[R] Odp: fit data with y = x^-1
Petr PIKAL
petr.pikal at precheza.cz
Mon Jun 7 14:41:21 CEST 2010
Hi
r-help-bounces at r-project.org napsal dne 07.06.2010 14:28:58:
> Dear list,
>
> I am getting weired with fitting data with a 1/x-polynomial. Suggest I
have
> the following data:
>
> x <- c(1,2,3,4,5,6,7)
> y <- c(100,20,4,2,1,.3,.1)
>
> I may fit this with a linear model
>
> fit1 = lm(y ~ I(x))
fit1 = lm(y ~ x)
is enough
>
> Getting plot out of this model I applied
> library(polynom)
> pol1 = polynomial(fit1$coefficients)
> f1 = as.function(pol1)
>
> plot(x,y)
> lines(x, f1(x), col = 2)
why not
plot(x,y)
lines(x, fitted(fit))
>
> Clearly, this model appears insufficient. Therefore I intended to aplly
> fit2 = lm(y ~ I(1/x))
> pol2 = polynomial(fit2$coefficients)
> f2 = as.function(pol2)
> lines(x, f2(x), col = 3)
The same applies here
fit3 = lm(y ~ I(1/x^3))
lines(x, fitted(fit3))
seems to give quite reasonable output.
Regards
Petr
>
> as this would be much more pleasant. However, the second model does not
work
> at all.
>
>
> Does anyone know about how to correctly fit an x^-1-polynomial to my
data
> cloud?
>
>
> Many thanks in advance,
>
>
> behelfsadresse
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list