Poisson family GLM with 1 categorical independent variable error missing value where TRUE/FALSE needed I want to test if a few test subjects show improvement over days in a test. I have 2 groups, 1 that did some training before the test and 1 that did not. My test lasted three days, with 10 trials a day, and now I wanted to see if my test subjects showed improvement over days. For this i thought i cannot use a regular Chi square test, since all individuals contribute 10 data points for ever day. The test has a binary outcome, pass or no pass.
I used the following R-script:
model= glm(Result ~ Day, family="poisson", data=MytestData)
Both Result (Fail/ Pass) and Day (1,2,3) are factor variables
I get the following error: Error in if (any(y < 0)) stop("negative values not allowed for the 'Poisson' family") :
missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(y, 0) : ‘<’ not meaningful for factors
Anyone can help me with this problem? Or am I using the wrong test here?
Edit/response:
Thank you for the useful answer. In the end I used a glmer with individual as random factor to correct for this, but I indeed seemed to be needing the binomial link function. Sorry maybe if it was too obvious but I am kinda new to data analysing still and still learning on my own. I cant comment on your response that it was useful, as I apparently need more reputation? But thanks for the assistance.
 A: Yes, you definitely need a different test.
First, the reason for the error message is that you are inputing a factor to the glm function, which was expecting to get numerical counts.
To illustrate this, I will simulate data like yours:
> set.seed(2)
> Result <- rbinom(30,p=0.5,size=1)
> Result <- factor(rbinom(30,p=0.5,size=1))
> levels(Result) <- c("Fail","Pass")
> Day <- gl(3,10,30)
> table(Result,Day)
      Day
Result 1 2 3
  Fail 4 4 3
  Pass 6 6 7

The Poisson distribution is a count distribution, so when family=Poisson
the glm function expects to get a numerical response vector containing non-negative counts. If I instead input the Result factor to glm as the reponse vector, then I get the same error message as you have:
> glm(Result ~ Day, family="poisson")
Error in if (any(y < 0)) stop("negative values not allowed for the 'Poisson' family") : 
  missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(y, 0) : ‘<’ not meaningful for factors

Admitedly the error message isn't very helpful, but the authors of the glm function didn't expect that anyone would try to input non-numeric data into the regression function and so don't check for it specifically.
The error arises because you can't do any numerical tests or computations on factors.
When they try to test whether the response vector contains any negative values (y < 0), the test returns NA instead of TRUE or FALSE (because the variable isn't numeric) and hence the error message.
You can however use a binomial glm with Result as the response variable, because binary regression doesn't need a numeric response, only a dichotomy between the two possible outcomes:
> fit <- glm(Result ~ Day, family="binomial")
> anova(fit, test="Chi")
Analysis of Deviance Table

Model: binomial, link: logit

Response: Result

Terms added sequentially (first to last)


     Df Deviance Resid. Df Resid. Dev Pr(>Chi)
NULL                    29     39.429         
Day   2  0.29171        27     39.138   0.8643

But there are other problems with your analysis.
You are not taking into account which result arose from which individual.
Test results from the same individual are correlated and this must be taken into account in the analysis.
You also need to take account of which group each individual belongs to.
You have not given complete information about your experiment so it is impossible to suggest a complete analysis for you with any confidence.
For example, does an individual who gets trained for one test always get trained before tests?
Can the same individual get trained for one test but not for another?
Anyway, you might be able to use a binomial model like this:
> fit <- glm(Result ~ Individual + Group:Day, family=binomial())

Here Individual is a factor identifying the individual and Group is a factor identifying the groups (training or no training).
