【问题标题】:permutation test for logistic regression?逻辑回归的排列检验?
【发布时间】:2018-06-14 14:35:49
【问题描述】:

我想看看雄性物种是否会影响雌性对雄性求爱的反应。我使用逻辑回归,因为响应是成功(女性对男性求爱有反应)和失败(女性对求爱没有反应)的比例:

behavior <- structure(
list(male = c("speciesB", "speciesB", 
  "speciesB", "speciesB","speciesB", "speciesB",
  "speciesB", "speciesA", "speciesA", "speciesA"), 
courtship = c(1, 1, 3, 6, 2, 2, 2, 23, 4, 1), 
female_response = c(0,0, 3, 4, 0, 1, 0, 23, 2, 1)), 
.Names = c("male", "courtship","female_response"), 
row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L,40L, 59L, 67L), 
class = "data.frame")

model <- glm(cbind(female_response,courtship-female_response)~male,
 family=binomial, data=behavior)

除了似然比检验之外,我还想用置换检验来检验我的假设,因为我有一个小数据集(46 位女性),其中有一些异常值似乎过度影响了结果。

据我所知,现在存档的 glmperm() 包中的 prr.test 是对广义线性模型进行置换测试的唯一可用函数。

当我用我的模型调用函数时:

packageurl <- "https://cran.r-project.org/src/contrib/Archive/glmperm//glmperm_1.0-5.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
library(glmperm)
prr.test(cbind(female_response,courtship-female_response) ~ male, var="male" , family=binomial, data=behavior)

我反复收到错误:

Error in prr.test(cbind(female_response, courtship - female_response) ~  :var not a covariate in the formular

为什么 glmperm 被归档?人们为什么不对逻辑回归进行排列测试有什么原因吗?有没有更好的 R 包?

谁能告诉我哪里出错了?这个函数对比例数据不起作用吗?

【问题讨论】:

  • 存档页面 cran.r-project.org/web/packages/glmperm/index.html > 显示“存档于 2014-12-07,维护者地址 已退回。”

标签: r permutation logistic-regression


【解决方案1】:

显然,所写的函数仅适用于 numeric 协变量,因为它正在寻找 模型矩阵 中指定的变量的名称:当您有一个预测器时是一个因素,模型矩阵中的名称不再与公式中的名称匹配。您可以通过(1)将您的(两级)因子转换为虚拟变量来解决此问题,例如behavior$maleDummy &lt;- as.numeric(behavior$male=="speciesB") 或 (2) 在函数调用中使用虚拟变量的派生名称:

res <- prr.test(cbind(female_response,courtship-female_response) ~ male, 
   var="malespeciesB" , family=binomial, data=behavior)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    相关资源
    最近更新 更多