lsmeans 模型中的参数无效?
Posted
技术标签:
【中文标题】lsmeans 模型中的参数无效?【英文标题】:Invalid argument in the lsmeans model? 【发布时间】:2019-02-24 05:46:06 【问题描述】:我收到错误提示
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")
【问题讨论】:
应该是波浪号 (~drug ),而不是减号 (-drug);波浪线用于表示 R 中的公式 【参考方案1】:您有一个错字,因为您应该使用波浪号 - ~
而不是 -
字符。波浪号用于 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
【讨论】:
以上是关于lsmeans 模型中的参数无效?的主要内容,如果未能解决你的问题,请参考以下文章
ValueError:使用 GridSearch 参数时估计器 CountVectorizer 的参数模型无效
模型衍生 API 发布作业 - 400 错误请求“无效的‘设计’参数”