我正在运行一个线性模型,并希望将斜率上的一组点与 0 处的估计值进行比较。我的代码遵循此处的响应布局。输出似乎有一个单一的、相同的 p 值。我希望接近 0 的值具有高 p 值,而远离 0 的值具有小的 p 值。我绝对没想到在比较中会有相同的 p 值。有什么建议么?
玩具数据集:
library(ggplot2)
library(tidyr)
library(emmeans)
df <- structure(list(Distance = c(0, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5),
Mean = c(139, 119.8, 121, 130.4, 115.9, 134.7, 134.7, 122.2, 118.8, 116.9, 114.4,
109.6, 103.9, 113.2, 103.5, 113.3, 122.1, 105.9, 115.2)), row.names = c(NA, -19L),
class = c("tbl_df", "tbl", "data.frame"))
m <- lm(Mean ~ Distance, data = df)
df$Pred <- predict(m)
# data and predictions look ok
ggplot(df) +
geom_point(aes(x = Distance, y = Mean)) +
geom_line(aes(x = Distance, y = Pred))
# create a fake grid for emmeans
fake.df <- data.frame(Distance = 0:10)
# run a treatment vs control, where control is value at 0 and "treatment" are values
# stepping away from 0
emm <- emmeans(m, trt.vs.ctrl1 ~ Distance, data = fake.df,
cov.reduce = FALSE, covnest = TRUE)
emm