# glm for categorical data [duplicate]

I am currently running some GLM's looking at different carnivore species and environmental variables. One of my variables is habitat which I have coded from 1-6. I ran the models with Poisson, but I think I need to use a different model as it may be assuming my habitat data is continuous like my other variables. Can anybody please tell me what type of model I should be using that can account for both numerical and categorical data sets combined (if that makes sense).

    glm1<-glm(Jaguar_RAI~Habitat+Dist_river+Human_RAI+Fox_RAI+
Pu‌​ma_RAI + Tayra_RAI+Ocelot_RAI,family = poisson())
summary(glm1)
plot(glm1)
#now test the sig relationship with spearmans because it's non parametric
cor.test(Jaguar_RAI,Habitat,method = "spearman")

• Is the variable stored as a factor? Also it would be good to add a small example similar to your code. – Elin Sep 9 '17 at 15:48
• No I just checked, its not a factor – sarah_finnegan Sep 9 '17 at 15:52
• Well that is the problem. In your formula wrap it with as.factor(). – Elin Sep 9 '17 at 15:54
• glm1<-glm(Jaguar_RAI~Habitat+Dist_river+Human_RAI+Fox_RAI+Puma_RAI +Tayra_RAI+Ocelot_RAI,family = poisson()) summary(glm1) plot(glm1) #now test the sig relationship with spearmans because its non parametric cor.test(Jaguar_RAI,Habitat,method = "spearman") This is one part of the code, I am looking at 5 species independently.. all other varibles are numbers, but habitat numbers relates to a category – sarah_finnegan Sep 9 '17 at 15:54
• In R categorical variables are factors. So as.factor(Habitat) . – Elin Sep 9 '17 at 15:59