Skip to content
Prev 308139 / 398513 Next

se's and CI's for fitted lines in multivariate regression analysis

Hello,

If you want confidence intervals for the beta coefficients of the model, 
try the following.

ci_lm <- function(object, level = 0.95){
     sfit <- summary(object)
     beta <- sfit$coefficients[, 1]
     se <- sfit$coefficients[, 2]
     df <- sfit$df[1]
     alpha <- 1 - level
     lower <- beta + qt(alpha/2, df = df)*se
     upper <- beta + qt(1 - alpha/2, df = df)*se
     data.frame(beta, lower, upper)
}

data(OrchardSprays)
model <- lm(decrease ~ rowpos + colpos * treatment, data = OrchardSprays)
ci_lm(model)


On the other hand, if you want to run regressions on each factor level 
separately, use the argument 'subset' of lm().

model2 <- lm(decrease ~ colpos , subset = treatment == 'A', data = 
OrchardSprays)
model2

I believe that you might be looking for this last one.

Rui Barradas
Em 16-10-2012 19:58, Sigrid escreveu: