Giter Club home page Giter Club logo

quickreg's Introduction

A manual to show the R package quickReg.

Introduction

The quickReg package provide a set of functions to display and pry a dataset. More precisely, the package can display statistical descriptions for a dataset, build regression models for lm, glm, and cox regressions based on specified independent variables. The package also provides functions to visualize the regression results. Some examples are shown below:

Getting started

The example data is a toy dataset extracting from package PredictABEL only to be used to demonstrate the main idea of the package.

# download it from cran or github

install.packages("quickReg")

devtools::install_github("XikunHan/quickReg", build_vignettes = TRUE)

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

# Load the dataset

data(diabetes)

# Show the first 6 rows of the data

head(diabetes)

Functions display_table or display_table_group can be used to show statistical descriptions of the dataset.

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

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

# 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 survival 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

# adjusting for 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


# 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

# 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

Plot these regression models

plot(reg_1)

# if the OR value is very large, we can set a limit
plot(reg_1,limits=c(NA,3))


# Sort the variables alphabetically

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

# Similarly, we can plot several dependent variables result

plot(reg_4)


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



# modify the plot 
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)))

quickreg's People

Contributors

xikunhan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.