Hi
r-help-bounces at r-project.org napsal dne 04.02.2009 12:33:57:
>
> Hei,
> I have a formula for a model as follows
> lm(TS~log(BodyWt)+log(BodyWt):factor(D). I do not use R for programming
> hence I dont understand what is the second covariate in the model
> "log(BodyWt):factor(D)".
> Where BodyWt = body weight and D = danger index (either 1 or 2). I want
to> run the same model in other program. Can anyone explain me what is doing
the> : operator and the factor() function.
Factor changes D from numeric (1,2) to factor with levels 1 and 2. As a
result from lm with such specified model you shall get one intercept and 2
slopes one for level 1 and second for level 2 of D
see
x<-1:20
A<-sample(1:2, 20, replace=T)
y<-10+x*5*(A==1)+x*12*(A==2)+rnorm(20)
fit<-lm(y~x+x:factor(A))
plot(x,y)
summary(fit)
lines(x, 9.38+x*5.07268)
lines(x, 9.38+x*5.07268+x*6.98)
Regards
Petr
>
> Thanks
> --
> View this message in context:
http://www.nabble.com/Factor-and-Lm-functions-> tp21828771p21828771.html
> Sent from the R help mailing list archive at Nabble.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.