简体   繁体   English

比较 R 中回归的两个斜率

[英]Compare two slopes from regression in R

I used this code to get a plot with log formula我用这段代码得到了一个 plot 和对数公式

df %>%
  mutate(absVO2 = absVO2*1000) %>%
  ggplot(aes(x = VE, y = absVO2, color = group)) +
  geom_point(size = 0.5) +
  geom_smooth(aes(colour=group), method = "lm", formula = y ~ log(x)) +
  stat_regline_equation(label.x = 25, label.y = c(2400,2800), 
                        formula = y ~ log(x),
                        aes(color = group, label =  paste(..eq.label.., ..adj.rr.label.., sep = "~~~~")),) +
  xlab("VE (L/min)") + 
  ylab(expression(paste("V", O[2]," (mL/min)"))) +
  scale_x_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 25)) +
  theme_classic() +
  theme(
    panel.background = element_rect(fill ="white", colour = "white"),
    axis.line = element_line(colour = "black"),
    legend.title = element_text(face = "bold"),
    legend.position = "none",
    strip.text = element_blank()
  )

That gives me this output:这给了我这个 output: 在此处输入图像描述

I would like to statistically compare the two slopes, ie 910 and 970 which are the a in the VO2 = a * log(VE) + b formula.我想统计比较两个斜率,即910970 ,它们a VO2 = a * log(VE) + b公式中的 a。

Thank you!谢谢!

Here are the data:以下是数据:

structure(list(VE = c(22.75, 23.75, 26.75, 32.5, 39.5, 48.25, 
55.75, 24, 26.5, 29, 36.5, 44.75, 55.25, 63.75, 78, 19, 20.75, 
25, 29, 39.25, 51, 25, 25.5, 28.5, 34.25, 35.5, 40.25, 47, 52.5, 
59.5, 64.5, 83, 92.25, 18.25, 19.75, 20.75, 23.5, 26.25, 28, 
32.75, 37.25, 24.25, 26.75, 29.5, 31, 32, 39, 43.25, 46.25, 51.75, 
52.75, 64.5, 72.75, 15.75, 16.25, 20.25, 28, 34.75, 45.75, 64.75, 
18.25, 21.25, 22.25, 24.75, 29.5, 21.25, 20.75, 26, 30.75, 34, 
38.5, 46.75, 53.75, 70.5, 82.75, 98.25, 17.25, 22, 25.75, 29.75, 
33.75, 38.75, 44.5, 50.75, 56.25, 65, 71.75, 81, 99, 30, 29, 
29.75, 38.25, 40.75, 47.25, 52.75, 65.5, 22.75, 24.75, 28.75, 
34, 48, 53.75, 61.5, 73.75, 22, 21.75, 24.25, 28, 34.5, 40, 48.5
), absVO2 = c(0.739, 0.81975, 0.95125, 1.07525, 1.199, 1.34575, 
1.49775, 0.66125, 0.7485, 0.855, 0.9845, 1.1495, 1.3465, 1.451, 
1.5985, 0.61675, 0.717, 0.86275, 0.98575, 1.13, 1.262, 0.8835, 
0.94575, 1.08125, 1.244, 1.30475, 1.4735, 1.679, 1.79075, 1.96, 
2.0405, 2.34425, 2.4435, 0.5925, 0.661, 0.7435, 0.87875, 0.9435, 
0.99675, 1.11425, 1.20275, 0.9255, 1.02925, 1.11675, 1.19725, 
1.24775, 1.42625, 1.54225, 1.59425, 1.69675, 1.776, 1.94525, 
2.0395, 0.535, 0.5845, 0.76875, 0.982, 1.09975, 1.259, 1.3265, 
0.7205, 0.86825, 0.9235, 1.01075, 1.17275, 0.7435, 0.76575, 0.96075, 
1.0975, 1.21975, 1.34525, 1.50625, 1.6755, 1.86325, 2.0465, 2.1395, 
0.613, 0.85525, 0.98, 1.076, 1.287, 1.4615, 1.59325, 1.6965, 
1.884, 1.998, 2.1425, 2.31275, 2.474, 0.81075, 0.8035, 0.8645, 
1.076, 1.119, 1.255, 1.33825, 1.499, 0.8105, 0.8865, 1.03725, 
1.134, 1.26675, 1.36275, 1.4455, 1.52875, 0.64675, 0.6645, 0.742, 
0.81675, 0.983, 1.06875, 1.155), group = c("CAD", "CAD", "CAD", 
"CAD", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", 
"CAD", "CAD", "CAD", "Healthy", "Healthy", "Healthy", "Healthy", 
"Healthy", "Healthy", "Healthy", "Healthy", "Healthy", "Healthy", 
"Healthy", "Healthy", "Healthy", "Healthy", "Healthy", "Healthy", 
"Healthy", "Healthy", "Healthy", "Healthy", "Healthy", "Healthy", 
"Healthy", "Healthy", "Healthy", "Healthy", "CAD", "CAD", "CAD", 
"CAD", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", 
"Healthy", "Healthy", "Healthy", "Healthy", "Healthy", "Healthy", 
"Healthy", "Healthy", "Healthy", "Healthy", "Healthy", "Healthy", 
"CAD", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", 
"CAD", "CAD", "Healthy", "Healthy", "Healthy", "Healthy", "Healthy", 
"Healthy", "Healthy", "Healthy", "Healthy", "Healthy", "Healthy", 
"Healthy", "Healthy", "CAD", "CAD", "CAD", "CAD", "CAD", "CAD", 
"CAD", "CAD", "Healthy", "Healthy", "Healthy", "Healthy", "Healthy", 
"Healthy", "Healthy", "Healthy", "CAD", "CAD", "CAD", "CAD", 
"CAD", "CAD", "CAD")), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -112L))

Your hypothesis is that the slope of two groups are different.您的假设是两组的斜率不同。 To answer this you build a linear model with added group variable and an interaction between group and VE (without an interaction you are assuming the slope is the same between the groups, so you already have your answer in this case):为了回答这个问题,您构建了一个线性 model,其中添加了组变量以及组和 VE 之间的交互(没有交互,您假设组之间的斜率相同,因此在这种情况下您已经有了答案):

> summary(lm(absVO2*1000~group*log(VE),data=df))

Coefficients:
                     Estimate Std. Error t value Pr(>|t|)    
(Intercept)          -2120.98     210.38 -10.081   <2e-16 ***
groupHealthy           -96.46     263.82  -0.366    0.715    
log(VE)                914.32      57.40  15.928   <2e-16 ***
groupHealthy:log(VE)    60.52      72.64   0.833    0.407    

Intercept is the value of absVO2 when log(VE) is zero (not really meaningfull for your data) and group = CAD (which is the reference group, you can change this). Intercept是 absVO2 的值,当log(VE)为零(对您的数据没有真正意义)并且group = CAD (这是参考组,您可以更改它)。 log(VE) is the term you are interested in (the slope), which is approx. log(VE)是您感兴趣的项(斜率),大约是。 914 for group = CAD , for group = healthy you have to add approx. 914 为group = CAD ,为group = healthy你必须添加大约。 60 to it (which would result in a slope of approx. 974), but this coefficient is not significant (based on the PR(t) column - the dreaded p-value). 60 到它(这将导致大约 974 的斜率),但该系数并不显着(基于 PR(t) 列 - 可怕的 p 值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM