knitr::opts_chunk$set( collapse = TRUE, comment = NA )
You can install autoReg package on github.
#install.packages("devtools") devtools::install_github("cardiomoon/autoReg")
To load the package, use library() function.
library(autoReg)
You can make a table summarizing baseline characteristics easily.
library(moonBook) # For use of example data acs gaze(sex~.,data=acs)
You can make a publication-ready table easily using myft(). It makes a flextable object which can use in either HTML and PDF format.
library(dplyr) # for use of `%>%` ft=gaze(sex~.,data=acs) %>% myft() ft
You can also make a powerpoint file using rrtable::table2pptx() function.
library(rrtable) table2pptx(ft)
Exported table as Report.pptx
You can make a microsoft word file using rrtable::table2docx() function.
table2docx(ft)
Exported table as Report.docx
You can get a table summarizing baseline characteristics with two or more grouping variables.
gaze(sex+Dx~.,data=acs) %>% myft()
You can also use three or more grouping variables.The resultant table will be too long to review, but you can try.
gaze(sex+DM+HBP~age,data=acs) %>% myft()
You can make a table summarizing results of regression analysis. For example, let us perform a logistic regression with the colon cancer data.
library(survival) # For use of data colon data(cancer) fit=glm(status~rx+sex+age+obstruct+perfor+nodes,data=colon,family="binomial") summary(fit)
You can make table with above result.
autoReg(fit)
Or you can make a publication-ready table.
autoReg(fit) %>% myft()
If you want make a table with more explanation, you can make categorical variables with numeric variables. For example, the explanatory variables obstruct(obstruction of colon by tumor) and perfor(perforation of colon) is coded as 0 or 1, but it is "No" or "Yes" actually. Also the dependent variable status is coded as 0 or 1, it is "Alive" or "Died".
colon$status.factor=factor(colon$status,labels=c("Alive","Died")) colon$obstruct.factor=factor(colon$obstruct,labels=c("No","Yes")) colon$perfor.factor=factor(colon$perfor,labels=c("No","Yes")) colon$sex.factor=factor(colon$sex,labels=c("Female","Male")) fit=glm(status.factor~rx+sex.factor+age+obstruct.factor+perfor.factor+nodes,data=colon,family="binomial") result=autoReg(fit) result %>% myft()
You can add labels to the names of variables with setLabel() function.
colon$status.factor=setLabel(colon$status.factor,"Mortality") colon$rx=setLabel(colon$rx,"Treatment") colon$age=setLabel(colon$age,"Age(Years)") colon$sex.factor=setLabel(colon$sex.factor,"Sex") colon$obstruct.factor=setLabel(colon$obstruct.factor,"Obstruction") colon$perfor.factor=setLabel(colon$perfor.factor,"Perforation") colon$nodes=setLabel(colon$nodes,"Positive nodes") fit=glm(status.factor~rx+sex.factor+age+obstruct.factor+perfor.factor+nodes,data=colon,family="binomial") result=autoReg(fit) result %>% myft()
If you do not want to show the reference values in table, you can shorten the table.
shorten(result) %>% myft()
You can add the results of univariate analyses to the table. At this time, the autoReg() function automatically select explanatory variables below the threshold(default value 0.2) and perform multivariate analysis. In this table, the p values of explanatory variables sex.factor and age is above the default threshold(0.2), they are excluded in multivariate model.
autoReg(fit, uni=TRUE) %>% myft()
If you want to include all explanatory variables in the multivariate model, just set the threshold 1.
autoReg(fit, uni=TRUE,threshold=1) %>% myft()
You can perform stepwise backward elimination to select variables and make a final model. Just set final=TRUE.
autoReg(fit, uni=TRUE,threshold=1, final=TRUE) %>% myft()
When the argument imputed=TRUE, autoReg() function make a multiple imputed model using mice::mice() function. By default, 20 imputations performed. If you want, you can change the number of imputations with m argument.
autoReg(fit, imputed=TRUE) %>% myft()
You can draw the plot summarizing the model with modelPlot()
x=modelPlot(fit) x
You can make powerpoint file with this plot using rrtable::plot2pptx().
plot2pptx(print(x))
Exported plot as Report.pptx
You can summarize models in a plot. If you want to summarize univariate and multivariate model in a plot, just set the uni=TRUE and adjust the threshold. You can decide whether or not show the reference by show.ref argument.
modelPlot(fit,uni=TRUE,threshold=1,show.ref=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.