0

Is it possible to run a GLM with a poisson distribution with a variable that has combined columns in R?

I am looking at the effects of different species, the cage density and the day that eggs are laid on how many eggs were laid and how many hatched, so I have linked the hatched and unhatched columns. My data are count data. The code works ok with family = binomial but I want to test if poisson is a better model.

My code is as follows:

attach(EggV)
density <- as.factor(Density)
day <- as.factor(Day)
Y <- cbind (Hatched, Unhatched)
model.pois <- glm(Y ~ Species + density + day, data = EggV, family = poisson)

But once I run the code it give me an error:

Error in x[good, , drop = FALSE] : (subscript) logical subscript too long

If I run the same code with only the variables "Hatched" or "Unhatched" it works but this is not sufficient for my data analysis.

Psidom
  • 209,562
  • 33
  • 339
  • 356
NJP
  • 1
  • 2
  • Your example is not reproducible: please see here http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – renato vitolo Aug 20 '16 at 15:46
  • 4
    Using a two column matrix is OK for binomial models but not for Poisson models. If you want to control for varying sample sizes in batches then you will need to use an offset. (and if you want tested code then do produce a dataset,,,,, and as always, friends don't let friends use `attach`.) – IRTFM Aug 20 '16 at 16:02

0 Answers0