逻辑回归的置换检验?

permutation test for logistic regression?

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

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

为什么要存档 glperm?人们不对逻辑回归进行排列检验有什么原因吗?有没有更好的R包?

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

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

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