First a reproducible dataset in R code using data from your question lightly edited:
dat <- read.table(text="| X | Y | #you _should_ have offered output from dput(dat)
| 1 | 7 |
| 3 | 255 |
| 5 | 1895 |
| 8 | 12320 |", header=TRUE, sep="|")[2:3] # only the middle 2 columns are useful.
Then you need to know that the "^" operator in R is not exponentiation inside an R formula expression. You will need to a) use the I
function and also +0
to omit an estimated intercept.
n=4; lm( Y ~ I(X^n)+X+0, data=dat)
Call:
lm(formula = Y ~ I(X^n) + X + 0, data = dat)
Coefficients:
I(X^n) X
3 4
If you assign the result of the lm call to my.lm
, you can look at the fitted values with plot
> png()
> plot(dat$X, predict(my.lm))
> dev.off()
