Learn R Programming

tab (version 1.0)

tablog: Generate summary tables of logistic regression models for statistical reports.

Description

This function performs logistic regression using the glm function and summarizes the results in a clean table for a statistical report.

Usage

tablog(x, y, xlabels=NULL, int=TRUE, decimals=2, n=TRUE, events=TRUE, coef="n")

Arguments

x
For single predictor, vector of values; for multiple predictors, data frame or matrix with one column per predictor. Categorical variables should be of class "factor."
y
Vector of 0's and 1's where 1's indicate event.
xlabels
Optional character vector to label the x variables and their levels. If unspecified, the function uses generic labels.
int
If FALSE, the table returned will not include a row for the intercept (the model is still fit with an intercept).
decimals
Number of decimal places for the regression coefficients, standard errors, and confidence intervals.
n
If TRUE, the table returned will include a column for sample size.
events
If TRUE, the table returned will include a column for number of events observed.
coef
If set to "x", function will standardize all variables in x that are continuous, providing standardized regression coefficients. Then the interpretation of each odds ratio is the odds ratio associated with a one standard deviation increase in the predicto

Value

  • A character matrix with the results of the Cox PH regression. If you click on the matrix name under "Data" in the RStudio Workspace tab, you will see a clean table that you can copy and paste into a statistical report or manuscript.

Details

NA

References

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

See Also

tabfreq tabmeans tablin tabcox

Examples

Run this code
# Load in example dataset d
data(d)

# Create labels for race
races = c("White","Black","Mexican American","Other")

# Test whether race is associated with 1-year mortality
logtable1 = tablog(x=d$race,y=d$death_1yr,xlabels=c("Race",races))

# Test whether age, sex, race, and treatment group are associated with 1-year mortality
logtable2 = tablog(x=d[,c("age","sex","race","group")],y=d$death_1yr,
                   xlabels=c("Age","Male","Race",races,"Treatment"))

# Click on logtable1 and logtable2 in the Workspace tab of RStudio to see the 
# tables that could be copied and pasted into a report or manuscript.

Run the code above in your browser using DataLab