Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>if <code>a</code> is the anova table object, then <code>attr(a,"heading")</code> does contain the information you are looking for, but I couldn't figure out a nice way of extracting it. So I looked up the code of <code>anova.glm</code>, which directed me to the code of <code>anova.lmlist</code> to figure out how they put that information into the heading. This inspired to following solution:</p> <pre><code># fake data x &lt;- 1:10 y &lt;- x+ rnorm(10) # two models m1 &lt;- glm(y~x) m2 &lt;- glm(y~x+I(x^2)) a &lt;- anova(m1, m2) # anova object to be printed # get model formulas flas &lt;- sapply(list(m1,m2), function(x)paste(deparse(x$formula))) rownames(a) &lt;- flas # add formulas as rownames # convert to latex xtable(a) </code></pre> <p><strong>Edit to cater for long formulas:</strong><br> If you have long formulas, two changes are needed: first we have to make sure that <code>deparse</code> does not break it into lines, and then we need to make latex to wrap the formula in the table. The first can be achieved by using the <code>cutoff.width</code> argument of deparse, and the second by using a <code>p{width}</code> column type in latex. For example:</p> <pre><code># add long formula m2$formula &lt;- freq ~ sex + attend + birth + politics + sex:attend + sex:birth + sex:politics + attend:birth + attend:politics + birth:politics + sex:attend:birth + sex:attend:politics + sex:birth:politics + attend:birth:politics a &lt;- anova(m1, m2) # use a large width flas &lt;- sapply(list(m1,m2), function(x)paste(deparse(x$formula, cutoff.width=500))) rownames(a) &lt;- flas # add formulas as rownames # convert to latex with first column wrapped in a 5cm wide parbox xtable(a, align="p{5cm}rrrr") </code></pre> <p>The result is not overly pretty, but your formula is not pretty either. In this particular case I would use <code>(sex + attend + birth + politics)^3</code> - gets the point across and is much shorter. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload