Skip to content

Factor and Lm functions

2 messages · RORAM, PIKAL Petr

#
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.

Thanks
#
Hi


r-help-bounces at r-project.org napsal dne 04.02.2009 12:33:57:
to
the
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
http://www.nabble.com/Factor-and-Lm-functions-
http://www.R-project.org/posting-guide.html