# Re: [R] trigonometric regression

From: William Simpson <william.a.simpson_at_gmail.com>
Date: Thu, 17 Jun 2010 18:43:25 +0100

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

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. Received on Thu 17 Jun 2010 - 17:45:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Jun 2010 - 17:50:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.