[R] trigonometric regression
William Simpson
william.a.simpson at gmail.com
Thu Jun 17 19:43:25 CEST 2010
Thanks, Bill!
Bill
On Thu, Jun 17, 2010 at 5:12 PM, William Dunlap <wdunlap at tibco.com> wrote:
>
> You can also define a function that keeps the cos
> and sin terms together so anova(fit) shows
> one entry for the (cos,sin) pair. E.g., define
> the following function
> cs <- function(x, freq)cbind(cos=cos(x*freq), sin=sin(x*freq))
> and use it as in
> > time<- sort(runif(30,0,20))
> >
> y<-sin(1.7*time+.1)+2*sin(1.1*time+.8)+rnorm(length(time),mean=2,sd=0.3)
> > fit <- lm(y~cs(time,1.7)+cs(time,1.1)+cs(time,1.3))
> > anova(fit)
> Analysis of Variance Table
>
> Response: y
> Df Sum Sq Mean Sq F value Pr(>F)
> cs(time, 1.7) 2 12.000 5.9998 50.7267 3.692e-09 ***
> cs(time, 1.1) 2 57.355 28.6776 242.4609 3.493e-16 ***
> cs(time, 1.3) 2 0.780 0.3902 3.2988 0.05501 .
> Residuals 23 2.720 0.1183
> ---
> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
More information about the R-help
mailing list