Dear R experts,
Excuse me if my question will be stupid...
I'd like to fit data with x^2 polynomial:
d <- read.table(file = "Oleg.dat", head = TRUE)
d
X T
3720.00 4.113
3715.00 4.123
3710.00 4.132
...
out <- lm(T ~ poly(X, 4), data = d)
out
Call:
lm(formula = T ~ poly(X, 2), data = d)
Coefficients:
(Intercept) poly(X, 2)1 poly(X, 2)2
9.803 -108.075 51.007
So, d$T best fitted with function
9.803 -108.075 * X + 51.007 * X^2,
yes?
T1 <- 9.803 -108.075 * d$X + 51.007 * d$X^2
T1
705453240
703557595
701664500
699773956
...
So, T1 obviosly gets non-sensible values.. :( Why?
Thanks a lot!
--
WBR,
Timur.
lm coefficients
6 messages · Sundar Dorai-Raj, Thomas Lumley, Spencer Graves +2 more
Look at ?poly. It's doing something your not expecting. What you want is lm(T ~ X + I(X^2), data = d) Regards, Sundar
Timur Elzhov wrote:
Dear R experts,
Excuse me if my question will be stupid...
I'd like to fit data with x^2 polynomial:
d <- read.table(file = "Oleg.dat", head = TRUE)
d
X T
3720.00 4.113
3715.00 4.123
3710.00 4.132
...
out <- lm(T ~ poly(X, 4), data = d)
out
Call:
lm(formula = T ~ poly(X, 2), data = d)
Coefficients:
(Intercept) poly(X, 2)1 poly(X, 2)2
9.803 -108.075 51.007
So, d$T best fitted with function
9.803 -108.075 * X + 51.007 * X^2,
yes?
T1 <- 9.803 -108.075 * d$X + 51.007 * d$X^2
T1
705453240
703557595
701664500
699773956
...
So, T1 obviosly gets non-sensible values.. :( Why?
Thanks a lot!
--
WBR,
Timur.
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Tue, 3 Feb 2004, Timur Elzhov wrote:
Dear R experts, Excuse me if my question will be stupid... I'd like to fit data with x^2 polynomial:
<snip>
out <- lm(T ~ poly(X, 4), data = d)
out
Call:
lm(formula = T ~ poly(X, 2), data = d)
Coefficients:
(Intercept) poly(X, 2)1 poly(X, 2)2
9.803 -108.075 51.007
So, d$T best fitted with function
9.803 -108.075 * X + 51.007 * X^2,
No. The predictors are not X and X^2, but two orthogonal polynomials. Look at the help page for poly(). -thomas
The function "poly" produces orthogonal polynomials, and those
depend on the exact combinations of levels of X in "d". Consider the
following:
> round(poly(1:3, 2), 2)
1 2
[1,] -0.71 0.41
[2,] 0.00 -0.82
[3,] 0.71 0.41
> round(poly(1:4, 2), 2)
1 2
[1,] -0.67 0.5
[2,] -0.22 -0.5
[3,] 0.22 -0.5
[4,] 0.67 0.5
Does this answer your question?
spencer graves
Timur Elzhov wrote:
Dear R experts,
Excuse me if my question will be stupid...
I'd like to fit data with x^2 polynomial:
d <- read.table(file = "Oleg.dat", head = TRUE)
d
X T
3720.00 4.113
3715.00 4.123
3710.00 4.132
...
out <- lm(T ~ poly(X, 4), data = d)
out
Call:
lm(formula = T ~ poly(X, 2), data = d)
Coefficients:
(Intercept) poly(X, 2)1 poly(X, 2)2
9.803 -108.075 51.007
So, d$T best fitted with function
9.803 -108.075 * X + 51.007 * X^2,
yes?
T1 <- 9.803 -108.075 * d$X + 51.007 * d$X^2
T1
705453240
703557595
701664500
699773956
...
So, T1 obviosly gets non-sensible values.. :( Why?
Thanks a lot!
--
WBR,
Timur.
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Do read ?poly: you have orthogonal polynomials.
On Tue, 3 Feb 2004, Timur Elzhov wrote:
Dear R experts, Excuse me if my question will be stupid... I'd like to fit data with x^2 polynomial: d <- read.table(file = "Oleg.dat", head = TRUE) d X T 3720.00 4.113 3715.00 4.123 3710.00 4.132 ... out <- lm(T ~ poly(X, 4), data = d)
You asked for 4 and got 2? Really?
out
Call:
lm(formula = T ~ poly(X, 2), data = d)
Coefficients:
(Intercept) poly(X, 2)1 poly(X, 2)2
9.803 -108.075 51.007
So, d$T best fitted with function
9.803 -108.075 * X + 51.007 * X^2,
yes?
No!
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Tue, Feb 03, 2004 at 05:27:40PM +0000, Prof Brian Ripley wrote:
out <- lm(T ~ poly(X, 4), data = d)
You asked for 4 and got 2? Really?
No, in fact I have a 4-power model, I just posted example with power of 2, for simplicity. I forgot to replace the poly argument :) Thanks too all who helped me! -- WBR, Timur.