[英]Confidence Interval after linear regression model in R
I am trying to get the confidence interval after fitting the linear regression model.我试图在拟合线性回归 model 后获得置信区间。
My data contains:我的数据包含:
Growthrate Strains
<dbl> <fct>
where growthrate represents growthrate value and Strains represents strain names其中growthrate代表生长速率值,Strains代表菌株名称
my code:我的代码:
all.lm <- lm(Growthrate~Strains,all)
confint(all.lm, 'Strains',level=0.95)
Output: Output:
2.5 % 97.5 %
Strains NA NA
I don't understand why its printing NA.我不明白为什么它的印刷不适用。 Any help at this point is highly appreciated.在这一点上的任何帮助都非常感谢。
The problem is that Strains
is a categorical variable so there is no coefficient called Strains
.问题是Strains
是一个分类变量,因此没有称为Strains
的系数。 Here is an example using the iris
data set that is included with R:以下是使用 R 中包含的iris
数据集的示例:
data(iris)
iris.lm <- lm(Petal.Width~Species, iris)
confint(iris.lm, level=.95) # All coefficients
# 2.5 % 97.5 %
# (Intercept) 0.1888041 0.3031959
# Speciesversicolor 0.9991128 1.1608872
# Speciesvirginica 1.6991128 1.8608872
confint(iris.lm, "Species", level=.95) # Species is not a coefficient
# 2.5 % 97.5 %
# Species NA NA
You need to specify the coefficients by name or number:您需要按名称或编号指定系数:
confint(iris.lm, 2:3, level=.95)
# 2.5 % 97.5 %
# Speciesversicolor 0.9991128 1.160887
# Speciesvirginica 1.6991128 1.860887
cfnames <- names(coef(iris.lm))[2:3]
cfnames
# [1] "Speciesversicolor" "Speciesvirginica"
confint(iris.lm, cfnames, level=.95)
# 2.5 % 97.5 %
# Speciesversicolor 0.9991128 1.160887
# Speciesvirginica 1.6991128 1.860887
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.