Trouble getting summary and plots of lmer object into word document within a for loop

17 views Asked by At

I am trying to create a for loop to test mixed effects models and I'm having trouble generating a word document with the summ() results for the model and a pdf document. I got help from someone who gave me code for a glm that works, but when I try it with a lmer it doesn't work. This is the code that works properly when I run it.

for (dat in datalist){ 
  bird <- read.csv(dat)
  bird$datebanded <-as.Date(bird$datebanded, format = "%m/%d/%Y")
  trap.twi.mod<-glm(bird$bc~log(bird$trap_count150+0.1)+scale(bird$meantwi_150m))
summary_text<- summ(trap.twi.mod)
  outputname<-sub(indir,outdir,dat)
  outputname<-sub("csv", "docx", outputname)
 export_summs(summary_text, scale = F, digits = 4, 
                        to.file = "docx", file.name =outputname)
  plotname<-sub(indir,outdir,dat)
  plotname<-sub("csv", "%03d.pdf", plotname)
  pdf(file=plotname)
  for (i in 1:4)
  plot(null_mod, which = i)
  dev.off()
}

But when I run it replaced with this mixed effects model:

null_mod <- lmer(bc ~ (1 | bandnum) + ( 1 | juliandate_noyr), data = bird) 

It doesn't work. I get an error code when it runs the "export_summs" line that says: Error in the_cis[, 1] : incorrect number of dimensions

This is my first time posting here so forgive me if I am missing anything important for context. any help would be greatly appreciated.

I've tried a bunch of stuff and read into the packages and I think that the "export_summs" function is not compatible with lmer objects. I tried using some functions from the "broom" and "sjPlot" packages and the code was able to run without an error message except both the pdf for the plots and word document for the summary statistics that's generated comes out empty and I can't figure out how to fix it.

0

There are 0 answers