Last data update: 2014.03.03

R: A simpler latex output of the latex.anova.rms
simpleRmsAnovaR Documentation

A simpler latex output of the latex.anova.rms

Description

The original problem is that the anova default function output is very detailed and cause a complaint in Sweave/knitr that hbox is overfull. It basically changes capitalized TOTAL, TOTAL INTERACTION and TOTAL NONLINEAR INTERACTION into lower case letters. It also deletes the (Factor + Higher Order Factors).

Usage

simpleRmsAnova(anova_output, subregexps, digits = 4, pval_lim.sig = 10^-4,
  rowlabel = "", ...)

## S3 method for class 'simpleRmsAnova'
print(x, html = TRUE, ...)

Arguments

anova_output

An object from the anova() function

subregexps

A 2 column matrix with sub() regular expressions to search for and their substitutions. The regular expression should be located in column 1 and the substitution in column 2.

digits

Number of digits in using the round

pval_lim.sig

The threshold before setting "<", default is < 0.0001

rowlabel

The label of the rows

...

Passed on to latex() or htmlTable

x

The output object from the SimpleRmsAnova function

html

If HTML output through the htmlTable should be used instead of traditional latex() function

Value

void See the latex() function

Examples

# ** Borrowed code from the lrm example **

#Fit a logistic model containing predictors age, blood.pressure, sex
#and cholesterol, with age fitted with a smooth 5-knot restricted cubic 
#spline function and a different shape of the age relationship for males 
#and females.  

library(rms)
n <- 1000    # define sample size
set.seed(17) # so can reproduce the results
age            <- rnorm(n, 50, 10)
blood.pressure <- rnorm(n, 120, 15)
cholesterol    <- rnorm(n, 200, 25)
sex            <- factor(sample(c('female','male'), n,TRUE))
label(age)            <- 'Age'      # label is in Hmisc
label(cholesterol)    <- 'Total Cholesterol'
label(blood.pressure) <- 'Systolic Blood Pressure'
label(sex)            <- 'Sex'
units(cholesterol)    <- 'mg/dl'   # uses units.default in Hmisc
units(blood.pressure) <- 'mmHg'

#To use prop. odds model, avoid using a huge number of intercepts by
#grouping cholesterol into 40-tiles

# Specify population model for log odds that Y=1
L <- .4*(sex=='male') + .045*(age-50) +
     (log(cholesterol - 10)-5.2)*(-2*(sex=='female') + 2*(sex=='male'))
# Simulate binary y to have Prob(y=1) = 1/[1+exp(-L)]
y <- ifelse(runif(n) < plogis(L), 1, 0)
cholesterol[1:3] <- NA   # 3 missings, at random

ddist <- datadist(age, blood.pressure, cholesterol, sex)
options(datadist='ddist')

fit_lrm <- lrm(y ~ blood.pressure + sex * (age + rcs(cholesterol,4)),
               x=TRUE, y=TRUE)
             
a_out <- anova(fit_lrm, 
               dec.F = 1,
               ss    = FALSE)
             
simpleRmsAnova(a_out, 
               subregexps = rbind(c("age", "Age"),
                                  c("cholesterol", "Cholesterol"),
                                  c("sex", "Sex")),
               caption="Anova output for a logistic regression model")

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Greg)
Loading required package: forestplot
Loading required package: grid
Loading required package: magrittr
Loading required package: Gmisc
Loading required package: Rcpp
Loading required package: htmlTable
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Greg/SimpleRmsAnova.Rd_%03d_medium.png", width=480, height=480)
> ### Name: simpleRmsAnova
> ### Title: A simpler latex output of the latex.anova.rms
> ### Aliases: print.simpleRmsAnova simpleRmsAnova
> ### Keywords: internal
> 
> ### ** Examples
> 
> # ** Borrowed code from the lrm example **
> 
> #Fit a logistic model containing predictors age, blood.pressure, sex
> #and cholesterol, with age fitted with a smooth 5-knot restricted cubic 
> #spline function and a different shape of the age relationship for males 
> #and females.  
> 
> library(rms)
Loading required package: Hmisc
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

    format.pval, round.POSIXt, trunc.POSIXt, units

Loading required package: SparseM

Attaching package: 'SparseM'

The following object is masked from 'package:base':

    backsolve

> n <- 1000    # define sample size
> set.seed(17) # so can reproduce the results
> age            <- rnorm(n, 50, 10)
> blood.pressure <- rnorm(n, 120, 15)
> cholesterol    <- rnorm(n, 200, 25)
> sex            <- factor(sample(c('female','male'), n,TRUE))
> label(age)            <- 'Age'      # label is in Hmisc
> label(cholesterol)    <- 'Total Cholesterol'
> label(blood.pressure) <- 'Systolic Blood Pressure'
> label(sex)            <- 'Sex'
> units(cholesterol)    <- 'mg/dl'   # uses units.default in Hmisc
> units(blood.pressure) <- 'mmHg'
> 
> #To use prop. odds model, avoid using a huge number of intercepts by
> #grouping cholesterol into 40-tiles
> 
> # Specify population model for log odds that Y=1
> L <- .4*(sex=='male') + .045*(age-50) +
+      (log(cholesterol - 10)-5.2)*(-2*(sex=='female') + 2*(sex=='male'))
> # Simulate binary y to have Prob(y=1) = 1/[1+exp(-L)]
> y <- ifelse(runif(n) < plogis(L), 1, 0)
> cholesterol[1:3] <- NA   # 3 missings, at random
> 
> ddist <- datadist(age, blood.pressure, cholesterol, sex)
> options(datadist='ddist')
> 
> fit_lrm <- lrm(y ~ blood.pressure + sex * (age + rcs(cholesterol,4)),
+                x=TRUE, y=TRUE)
>              
> a_out <- anova(fit_lrm, 
+                dec.F = 1,
+                ss    = FALSE)
>              
> simpleRmsAnova(a_out, 
+                subregexps = rbind(c("age", "Age"),
+                                   c("cholesterol", "Cholesterol"),
+                                   c("sex", "Sex")),
+                caption="Anova output for a logistic regression model")
<table class='gmisc_table' style='border-collapse: collapse; margin-top: 1em; margin-bottom: 1em;' >
<thead>
<tr><td colspan='4' style='text-align: left;'>
Anova output for a logistic regression model</td></tr>
<tr>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'></th>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Chi-Square</th>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>d.f.</th>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>pvals</th>
</tr>
</thead>
<tbody> 
<tr><td colspan='4' style='font-weight: 900;'>Variables</td></tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;blood.pressure</td>
<td style='text-align: center;'>0.23</td>
<td style='text-align: center;'>1</td>
<td style='text-align: center;'>0.63</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;Sex  </td>
<td style='text-align: center;'>38.17</td>
<td style='text-align: center;'>5</td>
<td style='text-align: center;'>&lt; 0.0001</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;&nbsp;&nbsp;All Interactions</td>
<td style='text-align: center;'>26.25</td>
<td style='text-align: center;'>4</td>
<td style='text-align: center;'>&lt; 0.0001</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;Age  </td>
<td style='text-align: center;'>30.48</td>
<td style='text-align: center;'>2</td>
<td style='text-align: center;'>&lt; 0.0001</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;&nbsp;&nbsp;All Interactions</td>
<td style='text-align: center;'>3.676</td>
<td style='text-align: center;'>1</td>
<td style='text-align: center;'>0.055</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;Cholesterol  </td>
<td style='text-align: center;'>24.15</td>
<td style='text-align: center;'>6</td>
<td style='text-align: center;'>0.0005</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;&nbsp;&nbsp;All Interactions</td>
<td style='text-align: center;'>22.74</td>
<td style='text-align: center;'>3</td>
<td style='text-align: center;'>&lt; 0.0001</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;&nbsp;&nbsp;Nonlinear </td>
<td style='text-align: center;'>5.113</td>
<td style='text-align: center;'>4</td>
<td style='text-align: center;'>0.28</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;Sex * Age  </td>
<td style='text-align: center;'>3.676</td>
<td style='text-align: center;'>1</td>
<td style='text-align: center;'>0.055</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;Sex * Cholesterol  </td>
<td style='text-align: center;'>22.74</td>
<td style='text-align: center;'>3</td>
<td style='text-align: center;'>&lt; 0.0001</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;&nbsp;&nbsp;Nonlinear</td>
<td style='text-align: center;'>4.544</td>
<td style='text-align: center;'>2</td>
<td style='text-align: center;'>0.10</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;&nbsp;&nbsp;Nonlinear Interaction : f(A,B) vs. AB</td>
<td style='text-align: center;'>4.544</td>
<td style='text-align: center;'>2</td>
<td style='text-align: center;'>0.10</td>
</tr> 
<tr><td colspan='4' style='font-weight: 900;'>Total</td></tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;Total nonlinear</td>
<td style='text-align: center;'>5.113</td>
<td style='text-align: center;'>4</td>
<td style='text-align: center;'>0.28</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;Total interaction</td>
<td style='text-align: center;'>26.25</td>
<td style='text-align: center;'>4</td>
<td style='text-align: center;'>&lt; 0.0001</td>
</tr>
<tr>
<td style='text-align: left;'>&nbsp;&nbsp;Total nonlinear + interaction</td>
<td style='text-align: center;'>26.98</td>
<td style='text-align: center;'>6</td>
<td style='text-align: center;'>0.0001</td>
</tr>
<tr>
<td style='border-bottom: 2px solid grey; text-align: left;'>&nbsp;&nbsp;Total</td>
<td style='border-bottom: 2px solid grey; text-align: center;'>62.1</td>
<td style='border-bottom: 2px solid grey; text-align: center;'>10</td>
<td style='border-bottom: 2px solid grey; text-align: center;'>&lt; 0.0001</td>
</tr>
</tbody>
</table>> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>