Thanks for the response. I'm sorry I didn't provide the code or data
example earlier. I was using the polynomial fitting technique of this form;
test <- lm(x[,34] ~ I(x[,1]) + I(x[,1]^2) + I(x[,1]^3))
for the original fitting operation. I also tried to use;
lm(y ~ poly(x,3,raw=TRUE))
with the same results for the polynomial coefficients in both cases. If my
understanding is correct, both of the methods above produce the coefficients of
a polynomial based on the data in 'y' as that data varies over
'x'. Therefore, I would assume that the function of the polynomial
should always produce the same results as the predict() function in R produces.
However, here are the raw data for anyone that has the time to help me out.
y:
[1] 9097 9074 9043 8978 8912 8847 8814 8786 8752 8722 8686 8657 8610 8604 8554
[16] 8546 8496 8482 8479 8462 8460 8438 8428 8418 8384
x:
[1] 17.50 NA 20.59 21.43 17.78 21.89 NA 22.86 NA 6.10 NA 5.37
[13] 3.80 NA 6.80 NA NA NA 5.80 NA NA NA NA NA
[25] NA
I think that R lm() just ignores the NA values, but I've also tried this by
first eliminating NAs and the corresponding x values from the data before
fitting the poly and the result was the same coefficients. Thanks very much to
anyone who is willing to provide information.
Chris Carleton
> CC: r-help@r-project.org
> From: r.turner@auckland.ac.nz
> Subject: Re: [R] Polynomial Fitting
> Date: Tue, 29 Sep 2009 13:30:07 +1300
> To: w_chris_carleton@hotmail.com
>
>
> On 29/09/2009, at 10:52 AM, chris carleton wrote:
>
> >
> > Hello All,
> >
> > This might seem elementary to everyone, but please bear with me.
I've
> > just spent some time fitting poly functions to time series data in R
> > using lm() and predict(). I want to analyze the functions once
I've
> > fit them to the various data I'm studying. However, after pulling
the
> > first function into Octave (just by plotting the polynomial function
> > using fplot() over the same x interval as my original data) I was
> > surprised to see that the scale and y values were vastly different
> > than the ones I have in R. The basic shape of the polynomial over the
> > same interval looks similar in both Octave and R, but the y values
> > are
> > all different. When I compute the y values using the polynomial
> > function by hand, the y values from the Octave plot are returned and
> > not the y values predicted by predict() in R. Can someone explain to
> > me why the values for a function would be different in R? Thanks,
> > Chris Carleton
>
> Presumably because you were using poly() with the argument "raw"
left
> equal to its default, i.e. FALSE.
>
> cheers,
>
> Rolf Turner
>
> P. S. The posting guide asks for reproducible examples .....
>
> R. T.
>
> ######################################################################
> Attention:
> This e-mail message is privileged and confidential. If you are not the
> intended recipient please delete the message and notify the sender.
> Any views or opinions presented are solely those of the author.
>
> This e-mail has been scanned and cleared by MailMarshal
> www.marshalsoftware.com
> ######################################################################
_________________________________________________________________
[[alternative HTML version deleted]]