2
votes

I want to see if the male species affects the behavior of a female in response to male courtship. I am using a logistic regression because the response is a proportion of successes (female responded to male courtship) and failures (female did not respond to courtship):

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)

I would like to test my hypothesis with a permutation test in addition to the likelihood ratio test as I have a small dataset (46 females) with a few outliers that seem to be unduly influencing the results.

As far as I can tell, prr.test from the now archived glmperm() package is the only available function to do permutation test for generalized linear models.

When I call the function with my model:

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)

I repeatedly get the error:

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

Why is glmperm archived? Is there some reason why people don’t do permutation tests for logistic regression? Is there a better R package?

Can anyone tell me where I went wrong? Does this function not work on proportion data?

1
the archive page <cran.r-project.org/web/packages/glmperm/index.html > says " Archived on 2014-12-07 as maintainer address <[email protected]> bounced. " - Ben Bolker

1 Answers

4
votes

Apparently the function as written only works for numeric covariates, because it is looking for the name of the variable specified in the model matrix: when you have a predictor that is a factor, the name in the model matrix no longer matches the name in the formula. You can work around this by (1) converting your (two-level) factor to a dummy variable, e.g. behavior$maleDummy <- as.numeric(behavior$male=="speciesB") or (2) using the derived name of the dummy variable in your function call:

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