Home > Blockchain >  glm() splitting first variable in different ones for each value?
glm() splitting first variable in different ones for each value?

Time:01-30

I'm trying to do a logistic regression between two variables, where I want to extract the p-value of the correlation between them. However, it seems that the function glm() splits the dependable variable into the unique values it contains, and I receive only a p-value for each of them and not one for the entire variable. Is there a way to instead get a p-value for the entire dependent variable? That's what I get if I do the test in SPSS, so it seems it's possible with logistic regression in general. But is it in R with this function?

Here is a minimal reproducible example:

attach(PlantGrowth)
weight.factor<- cut(weight, 2, labels=c('Light', 'Heavy')) # binarize weights
plot(table(group, weight.factor))
group
glm.1<- glm(weight.factor~group, family=binomial)
summary(glm.1)

Best regards

CodePudding user response:

I'd recommend using the data argument to glm instead of attach: help("attach") itself says that you should *usually not use attach() ...

pg <- transform(PlantGrowth,
   weight.factor = cut(weight, 2, labels=c('Light', 'Heavy')))
glm.1 <- glm(weight.factor~group, family=binomial, data = pg)

anova() will test each term in the model:

anova(glm.1, test="Chisq")
...
Terms added sequentially (first to last)
      Df Deviance Resid. Df Resid. Dev Pr(>Chi)   
NULL                     29     41.054            
group  2   11.084        27     29.970 0.003919 **

or car::Anova()

car::Anova(glm.1)
Analysis of Deviance Table (Type II tests)

Response: weight.factor
      LR Chisq Df Pr(>Chisq)   
group   11.084  2   0.003919 **

You have to be careful/think about the testing sequence when your models are more complicated (contain more than one term, and especially when they contain interaction terms). The defaults for car::Anova() come closer to what most people want, but if you have interactions in the model you should still read the "Details" section of help("Anova", package="car")

CodePudding user response:

Perhaps you are looking for this?

1-pchisq(glm.1$null.deviance-glm.1$deviance, df = glm.1$df.null - glm.1$df.residual)

Output:

0.003918751
  •  Tags:  
  • Related