Reputation: 153
Hello I would like to know what is the command to do the following problem:
Determine a 95% confidence interval for the average number of winning games. swim, limited 2 000 in Rstudio
viex<-c(2205,2096, 1847, 1903, 1457, 1848, 1564, 1821, 2577, 2476, 1984, 1917, 1761, 1709, 1901, 2288, 2072, 2861, 2411, 2289, 2203 ,2592, 2053 ,1979, 2048, 1786, 2876, 2560)
clasy<-c(10, 11, 11, 13, 10, 11, 10 ,11, 4 , 2, 7, 10, 9, 9, 6, 5, 5, 5, 6, 4 , 3 , 3 , 4, 10, 6 , 8, 2 , 0)
modelo = lm(clasy~ viex)
modelo
that's what i've done
Upvotes: 1
Views: 51
Reputation: 76663
This comes directly from the definition of confidence interval.
ci_regression <- function(x, conf = 0.95){
est <- coef(summary(x))[, 1]
se <- coef(summary(x))[, 2]
qq <- qt(1 - (1 - conf)/2, df = x$df.residual)
cbind(lower = est - qq*se, upper = est + qq*se)
}
ci_regression(modelo)
# lower upper
#(Intercept) 16.246064040 27.330437725
#viex -0.009614347 -0.004435854
In the case of linear regression, there is a confint.lm
method for objects of class "lm"
.
Simply run
confint(modelo)
# 2.5 % 97.5 %
#(Intercept) 16.246064040 27.330437725
#viex -0.009614347 -0.004435854
Upvotes: 1