Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 带因子的多元回归每次估计的置信区间_R_Linear Regression_Lm_Confidence Interval_Interaction - Fatal编程技术网

R 带因子的多元回归每次估计的置信区间

R 带因子的多元回归每次估计的置信区间,r,linear-regression,lm,confidence-interval,interaction,R,Linear Regression,Lm,Confidence Interval,Interaction,我想得到置信区间(p # Create data df1 <- cbind.data.frame (region = rep (c ("North", "South"), 6), height = c (30, 35, 28, 31, 29, 32, 25, 27, 23, 26, 28, 29), calories = c (300, 390, 2

我想得到置信区间(p
# Create data
df1 <- cbind.data.frame (region = rep (c  ("North", "South"), 6),
                         height = c (30, 35, 28, 31, 29, 32, 25, 27, 23, 26, 28, 29),
                         calories = c (300, 390, 282, 310, 215, 320, 252, 271, 440, 235, 235, 230))

> head (df1)
  region height calories
1  North     30      300
2  South     35      390
3  North     28      282
4  South     31      310
5  North     29      215
6  South     32      320

# Fit a model considering the interaction region*calories and get the confidence intervals

m1 <-lm (height ~ region * calories, data = df1 )
m1.coef <- cbind (estimate = summary(m1)$coef[,1], confint (m1))
> m1.coef
                         estimate        2.5 %      97.5 %
(Intercept)           33.35270923  26.08014451 40.62527394
regionSouth          -18.06358078 -30.24845497 -5.87870659
calories              -0.02152915  -0.04604315  0.00298485
regionSouth:calories   0.07179409   0.03082360  0.11276457
m2 <- lm (height ~ relevel (region, "South") * calories, data = df1 )
m2.coef <- cbind (estimate = summary(m2)$coef[,1], confint(m2))
> m2.coef
                                          estimate       2.5 %      97.5 %
(Intercept)                            15.28912845  5.51257684 25.06568006
relevel(region, "South")North          18.06358078  5.87870659 30.24845497
calories                                0.05026494  0.01743744  0.08309243
relevel(region, "South")North:calories -0.07179409 -0.11276457 -0.03082360

> confint (m2)["calories",]
     2.5 %     97.5 % 
0.01743744 0.08309243