0

I am trying to export the output of an 'Analysis of deviance table' in HTML format, so that it can be inserted into a word document.

I created a GLM model as follows:

newmod <- glm(cbind(Recaptured, predated) ~ Morph * Plant * Site, data = 
survival, family = binomial)

Running the following code gives me the output that I would like to export to HTML:

anova(newmod,test="Chisq")

I have tried the following code to create a HTML table using stargazer, however it doesn't seem to be working:

anova_mod<-anova(newmod,test="Chisq")
stargazer(newmod, type="html", out = "anova_output.htm")

Is there a simple way of doing this in r? I have managed to successfully export the summary statistics, but what I really need is the Analysis of deviance table.

Ferdi
  • 540
  • 3
  • 12
  • 23
  • I have found a solution to this issue now, I turned the model output (the analysis of deviance table) into a matrix using as.matrix(), I was then able to use stargazer on that object. – Debbie Walsh Dec 28 '17 at 17:09

1 Answers1

1

I believe you are looking for:

print(xtable(anova_mod), type = "html")

as indicated by this answer: Exporting R tables to HTML

Here is my full code for reproducing something similar to your question:

plant.df = PlantGrowth
plant.df$group = factor(plant.df$group,labels = c("Control", "Treatment 1", "Treatment 2"))
newmod = lm(weight ~ group, data = plant.df)
anova_mod=anova(newmod)
anova_mod

install.packages("xtable")
require(xtable)
print(xtable(anova_mod), type = "html")

You can then paste the output to an html vizualizer such as: https://htmledit.squarefree.com/ to see the resulting table.

Instead of printing it, you can write it to a file. I have not personally tested this part, but the second answer in this question should work for you: Save html result to a txt or html file

Note: You can also reference all parts of the anova_mod separately by adding a $ after it like anova_mod$Df.

Borislav Aymaliev
  • 803
  • 2
  • 9
  • 20
  • Hi, I don't think this works either :( because although I can't save the data to a file (I didn't figure that part out yet), the data that is printed is not from the 'analysis of deviance' table, it is just the summary statistics... – Debbie Walsh Dec 28 '17 at 15:33
  • @DebbieWalsh I did not read your question correctly the first time. Your `newmod` variable should be your model. Since you want the analysis of deviance, then you should export the information from the `anova_mod` variable. My answer gets an update to reflect that. – Borislav Aymaliev Dec 29 '17 at 08:10