1
votes

I have been working with logistic regression and would like to run out that reports several models ("blocks") so I can compare them.

I found apa.reg.table which creates exactly the kind of output I would like to see, but, alas, when I run glm models, I get error messages. No such error messages when I run a regression. I am especially interested in comparing these block models by the percentage change, which runs fine in a regular regression.

Questions:

  1. Is there any way I can run apa.reg.table with a logistic regression?
  2. If not, does anyone know of any packages or techniques that can be used to help me reach my objectives?

...In researching the problem, I ran the iris database:

data(iris)

...and then ran a series of four successive logistic regressions:

#Logistic regression models
MODEL_A<-glm(species~sepal.len, data=iris,, family=binomial())
MODEL_B<-glm(species~sepal.len+sepal.wid, data=iris, family=binomial())
MODEL_C<-glm(species~sepal.len+sepal.wid+petal.len, data=iris, family=binomial())
MODEL_D<-glm(species~sepal.len+sepal.wid+petal.len+petal.wid, data=iris, family=binomial())

apa.reg.table(MODEL_A,MODEL_B,MODEL_C,MODEL_D)


...but I receive the following error messages:

#Error in if (F.value < 0) stop("Your 'F.value' is not correctly specified.") : 
# argument is of length zero
#In addition: Warning messages:
#1: Unknown or uninitialised column: 'r.squared'. 
#2: Unknown or uninitialised column: 'p.value'.

...it runs fine in a regular regression analysis:

#regression models:
MODEL_B2<-lm(sepal.len~sepal.wid, data=iris)
MODEL_C2<-lm(sepal.len~sepal.wid+petal.len, data=iris)
MODEL_D2<-lm(sepal.len~sepal.wid+petal.len+petal.wid, data=iris)

#create table with regression models--no error messages:
apa.reg.table(MODEL_B2,MODEL_C2,MODEL_D2)

Any help would be greatly appreciated.

1
not very clear in the vignette, but i guess it only takes in lm objects, not glm. rdocumentation.org/packages/apaTables/versions/2.0.5/topics/…StupidWolf

1 Answers

0
votes

You can try using broom:

library(broom)

colnames(iris) =c("sepal.len","sepal.wid","petal.len","petal.wid","species")

MODEL_A<-glm(species~sepal.len, data=iris,, family=binomial())
MODEL_B<-glm(species~sepal.len+sepal.wid, data=iris, family=binomial())
MODEL_C<-glm(species~sepal.len+sepal.wid+petal.len, data=iris, family=binomial())
MODEL_D<-glm(species~sepal.len+sepal.wid+petal.len+petal.wid, data=iris, family=binomial())

You can have them in a list:

lapply(list(MODEL_A,MODEL_B,MODEL_C,MODEL_D),tidy)

Or:

library(dplyr)
library(purrr)

res = tibble(name=c("MODEL_A","MODEL_B","MODEL_C","MODEL_D"),
models=list(MODEL_A,MODEL_BMODEL_C,MODEL_D)) %>% 
mutate(coef=map(models,tidy),stats=map(models,glance))

`

then:

res %>% unnest(coef)

res %>% unnest(stats)