0

我收到错误消息

lsmDrugs=lsmeans(model1, -drug) -drug 中的错误:一元运算符的参数无效“

请问有什么帮助吗?

library(knitr)
library(lsmeans)

drug <- c(rep("A", 2),rep("B", 2),rep("C", 2))
drugDiff <- c(-14, -4, 5, -1, -2, 6)

data<-data.frame(Drug=as.factor(drug),Difference=drugDiff)
data

model1 <- aov(drugDiff ~ drug, data = data)

anova(model1)
kable(anova(model1), format = "markdown")

lsmDrugs = lsmeans(model1, -drug)

summary(contrast(lsmDrugs, method="pairwise", 
                 adjust = "tukey"), infer = c(T, T), level = 0.95, side = "twosided")
4

1 回答 1

0

您有错字,因为您应该使用波浪号 -~而不是-字符。波浪号用于 R 中的公式。请参见下面的代码:

library(knitr)
library(lsmeans)

drug <- c(
  rep("A", 2),
  rep("B", 2),
  rep("C", 2)
)

drugDiff <- c(-14, -4, 5, -1, -2, 6)

data <- data.frame(Drug = as.factor(drug), Difference = drugDiff)
data

model1 <- aov(drugDiff ~ drug, data = data)

anova(model1)
kable(anova(model1), format = "markdown")

lsmDrugs = lsmeans(model1, ~ drug) # tilde instead of minu, used for formula

summary(
  contrast(lsmDrugs, method = "pairwise",
           adjust = "tukey"),
  infer = c(T, T),
  level = 0.95,
  side = "twosided"
)

输出:

 contrast      estimate       SE df lower.CL upper.CL t.ratio p.value
 A - B    -1.100000e+01 5.773503  3 -35.1261  13.1261  -1.905  0.2817
 A - C    -1.100000e+01 5.773503  3 -35.1261  13.1261  -1.905  0.2817
 B - C    -1.776357e-15 5.773503  3 -24.1261  24.1261   0.000  1.0000

Confidence level used: 0.95 
Conf-level adjustment: tukey method for comparing a family of 3 estimates 
P value adjustment: tukey method for comparing a family of 3 estimates 
于 2018-09-21T20:02:11.387 回答