2013-10-15 66 views
0

我有一個示例數據。R glm多變量語法較短

DF<- data.frame(x=c(1,1,2,2,3,3,3), y1=c(1,2,3,4,8,8,4), y2=c(12,11,5,7,4,7,8), y3=c(2,3,4,5,3,2,1))

DF1 <- glm(DF$y1 ~ -1 + factor(DF$x)) 
DF2 <- glm(DF$y2 ~ -1 + factor(DF$x)) 
DF3 <- glm(DF$y3 ~ -1 + factor(DF$x)) 
result <- cbind(DF1$res, DF2$res, DF3$res) 

你能幫我怎麼能GLM模型語法採取短?

回答

1

由於具有family = gaussian一個GLM只是普通線性迴歸:

fit <- lm(cbind(y1,y2,y3) ~ -1 + factor(x), data=DF) 
result <- fit$res