quickReg

A manual to show the R package quickReg.

Introduction

The quickReg package concentrates on a set of functions to display and pry a dataset. More precisely, the package can display statistical description for a dataset, build regression models for lm, glm and cox regression based on specified variables. More importantly, the package provides several seamless functions to display these regressions. Several examples are used to explain the idea.

Getting started

The example data is a hypothetical dataset extracting a subset from package PredictABEL. It has no practical implications and only be used to demostrate the main idea of the package.

# Change the width of html file
options(width = 150,tibble.print_max=50)
# If you haven't install the package, you can download it from cran

# install.packages("quickReg")

library(quickReg)
library(ggplot2)
library(rlang)
library(dplyr)

# Load the dataset

data(diabetes)

# Show the first 6 rows of the data

head(diabetes)

We can use the function display_table or display_table_group to show statistical descriptions of the data.

display_1<-display_table(data=diabetes,variables=c("age","smoking","education"),group="CFHrs2230199")
display_1

# You could do a sub-group analysis by sex
display_2<-display_table_group(data=diabetes,variables=c("age","smoking"),group="CFHrs2230199",super_group = "sex")
display_2

# You could do a sub-group analysis by two variables
display_3<-display_table_group(data=diabetes,variables=c("age","smoking"),group="CFHrs2230199",super_group = c("sex","education"))
display_3


# Sub-group analysis can be a combination
display_4<-display_table_group(data=diabetes,variables=c("age","smoking"),group="CFHrs2230199",super_group = c("sex","education"),group_combine = TRUE)
display_4

Build regression models

# Apply univariate regression models

reg_1<-reg_x(data = diabetes, y = 5, factors = c(1, 3, 4), model = 'glm')
reg_1

# Or a survial analysis

reg_2<-reg_x(data = diabetes, x = c(3:4, 6), y ="diabetes",time=2,factors = c(1, 3, 4), model = 'coxph')
reg_2

# adjust some covariates

reg_3<-reg_x(data = diabetes, x = c("sex","age"), y ="diabetes" ,cov=c("CFBrs641153","CFHrs2230199"), factors ="sex", model = 'glm',cov_show = TRUE)
reg_3


# How about regression on several dependent variables
reg_4<-reg_y(data = diabetes, x = c("sex","age","CFHrs1061170"), y =c("systolic","diastolic","BMI") ,cov=c("CFBrs641153","CFHrs2230199"), factors ="sex", model = 'lm')
reg_4

# Cool, but I want to do a subgroup analysis

reg_5<-reg(data = diabetes, x = c("age","CFHrs1061170"), y =c("systolic","diastolic") ,cov=c("CFBrs641153","CFHrs2230199"), model = 'lm',group="sex")
reg_5


# or two subgroup analysis
reg_6<-reg(data = diabetes, x = c("age","CFHrs1061170"), y =c("systolic","diastolic") ,cov=c("CFBrs641153","CFHrs2230199"), model = 'lm',group=c("sex","smoking"))
reg_6


# or subgroup combination analysis
reg_7<-reg(data = diabetes, x = c("age","CFHrs1061170"), y =c("systolic","diastolic") ,cov=c("CFBrs641153","CFHrs2230199"), model = 'lm',group=c("sex","smoking"),group_combine = TRUE)
reg_7

How about plot these regression models

# good idea

plot(reg_1)

# One OR value is larger than others, we can set the limits
plot(reg_1,limits=c(NA,3))


# Sort the variables according to alphabetical

plot(reg_1,limits=c(NA,3), sort ="alphabetical")

# Similarly, we can plot for several dependent variables result

plot(reg_4)


# Subgroup and several dependent variables result
plot(reg_5)+facet_grid(sex~y)



# Actually, you can modify the plot like ggplot2 
library(ggplot2);library(ggthemes)

plot(reg_1,limits=c(0.5,2))+
  labs(list(title = "Regression Model", x = "variables"))+
  theme_classic() %+replace% 
  theme(legend.position ="none",axis.text.x=element_text(angle=45,size=rel(1.5)))

Perspective

The quickReg package provides a flexible and convenient way to dispaly data and the association between variables. This vignette offers a glimpse of its use and features. The source code and help files are more helpful. The package is ongoing. If you have any comments, questions or bug reports, please contact me.



Try the quickReg package in your browser

Any scripts or data that you put into this service are public.

quickReg documentation built on May 2, 2019, 12:35 p.m.