[英]How to work with linear regression and confidence intervals in R?
I would like to know the used commands in R to work with linear regression problems and confidence intervals, and why these ones are incorrect. 我想知道R中使用的命令来处理线性回归问题和置信区间,以及为什么这些不正确。
For example let's say we have the following data: 例如,假设我们有以下数据:
A <- c(12,11,12,15,13,16,13,18,11,14) # this is the width
B <- c(50,51,62,45,63,76,53,68,51,74) # this is the height
We did a linear regression that describes the variable B (height) by the variable A (width). 我们做了一个线性回归,用变量A(宽度)描述变量B(高度)。 The question is find the 90% confidence interval with mean of the height (B) that has 14 of width (A).
问题是找到90%置信区间,其中高度(B)的平均值为14(宽度(A))。
I know how to do the linear regression in R, lm(B~A)
and I get an equation like this B = a+A*c , where B and A are my variables a is the intercept.. 我知道如何在R,
lm(B~A)
进行线性回归,我得到一个像这样的方程式B = a + A * c ,其中B和A是我的变量a是截距..
What I tried was: 我试过的是:
B= a + (14)*c
= MU (for example) B= a + (14)*c
= MU(例如) t.test(B, mu = MU, conf.level=0.9)
, but unfortunately it's incorrect.. t.test(B, mu = MU, conf.level=0.9)
,但不幸的是它不正确.. Try this: 试试这个:
> m <- lm(B~A)
> predict(m, newdata=data.frame(A=14), interval='confidence', level=0.9)
fit lwr upr
1 60.58495 54.72854 66.44135
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.