[R-sig-Epi] Cosinor Model (Halberg, Bingham) - Multiple components - Linear, Quadratic and Cubic trends
BXC (Bendix Carstensen)
bxc at steno.dk
Sun Mar 18 11:48:06 CET 2012
Dear Iva,
First it is normal politeness to identify yourself with name an affiliation at the end of your email to a list like this, many people will not answer anonymous e-mails.
It is a little unclear to me what you mean.
If you are alluding to quadratic or cubic terms in some variable
you just include then in the model al
lm( y ~ I(z^2) + I(z^3), data=...)
But if you are referring to harmonic functions of higher order you can put hem in as separate sines and cosinse:
lm( y ~ I(cos(2*pi*t/T)) + I(sin(2*pi*t/T)) + I(cos(4*pi*t/T)) + I(sin(4*pi*t/T)) )
Here is a small function and a demo that shows what it does, maybe this is what you are looking for:
harm <-
function( mm, n )
{
# Function to devise a n'th order harmonic from a
# numerical vector, scaled to be in the range 0 to 1
MM <- cbind(
outer( mm * 2 * pi, 1:n, function(x,y) cos( x*y ) ),
outer( mm * 2 * pi, 1:n, function(x,y) sin( x*y ) )
)[,rep(1:n,each=2)+rep(0:1,n)*n]
colnames( MM ) <- outer( c("cos","sin"), 1:n, paste, sep="" )
MM
}
x <- seq(0,1,,100)
head( harm(x,3) )
matplot( x, harm(x,3), type="l", lty=1, lwd=2 )
Best regards
Bendix Carstensen
Epi package maintainer
______________________________________________
Bendix Carstensen
Senior Statistician
Epidemiology
Steno Diabetes Center A/S
Niels Steensens Vej 2-4
DK-2820 Gentofte
Denmark
+45 44 43 87 38 (direct)
+45 30 75 87 38 (mobile)
bxc at steno.dk http://BendixCarstensen.com
www.steno.dk
> -----Original Message-----
> From: r-sig-epi-bounces at r-project.org
> [mailto:r-sig-epi-bounces at r-project.org] On Behalf Of Iva P
> Sent: 18. marts 2012 21:21
> To: R-sig-epi at r-project.org
> Subject: [R-sig-Epi] Cosinor Model (Halberg, Bingham) -
> Multiple components - Linear, Quadratic and Cubic trends
>
>
>
> Hello!
>
> I have a doubt in relation with the use of the cosinor model
> with R when I have not only multiple components, but also
> linear, quadratic and cubic trends.
>
> I explain the details:
>
> In simple cosinor:
>
>
> Y = M + A * cos(2
> * π* t / T + φ) + error
>
> T knowed: y = M + β* X1 + ϒ* X2 + error,
>
> Where X1 = cos (2 * π* t / T) and X2 = sin(2
> * π* t / T)
>
> In this
> case, I use lm(y ~ X1 + X2) .
>
> For the
> multiple components case:
>
> y = M + ∑Aj * cos(2 * π * t /Tj + φj) + error
>
> In this
> case I use: lm(y ~ X1tot + X2tot)
>
> However, in
> the generalized model case (linear, quadratic and cubic
> trends), I don’t know how to analyze with R.
>
> I include
> the situacion formula:
>
> y = M + α1 * t + α2 * t2 + α3 * t3+ ∑Aj *
> cos(2 *π* t /Tj + φ2) + error
>
> What
> function in R can I use, as I used lm for the simple cosinor
> model and the multiple components model?.
>
> How can I
> obtain global information and separated information?. I refer
> to obtain information for each contribution (linear tren,
> quadratic trend, … and so on).
>
> Thank you
> very much for your help.
> [[alternative HTML version deleted]]
>
>
More information about the R-sig-Epi
mailing list