Learn R Programming

tab (version 1.0)

tablin: Generate summary tables of linear regression models for statistical reports.

Description

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

Usage

tablin(x, y, xlabels=NULL, int=TRUE, decimals=2, n=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 values for the response variable.
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.
coef
If set to "x", function will standardize all variables in x that are continuous, providing standardized regression coefficients. Then the interpretation of each beta is the expected change in y for one standard deviation increase in the predictor. If

Value

  • A character matrix with the results of the linear 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 tablog 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 BMI
lintable1 = tablin(x=d$race,y=d$bmi,xlabels=c("Race",races))

# Test whether age, sex, race, and treatment group are associated with BMI
lintable2 = tablin(x=d[,c("age","sex","race","group")],y=d$bmi,
                   xlabels=c("Age","Male","Race",races,"Treatment"))

# Same as previous, but request fully standardized regression coefficients
lintable3 = tablin(x=d[,c("age","sex","race","group")],y=d$bmi,
                   xlabels=c("Age","Male","Race",races,"Treatment"),coef="xy")

# Click on lintable1, lintable2, and lintable3 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