-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
136 lines (83 loc) · 4.34 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# RefineMod
<!-- badges: start -->
```{r, echo = FALSE}
version <- as.vector(read.dcf('DESCRIPTION')[, 'Version'])
version <- gsub('-', '.', version)
```
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) [![packageversion](https://img.shields.io/badge/Package%20version-`r version`-blue.svg?style=flat-square)](commits/master)
<!-- badges: end -->
The goal of RefineMod is to provide functions to refine and optimize linear regression models. Models can be refined to only those predictors that are statistically significant in explaining the response variable. Linear regression models can also be compared on the basis of their performance like RMSE, R2 and MAE. Package website [RefineMod](https://asfarlathif.github.io/RefineMod/)
## Package Development
This package was developed as an assignment for **STAT545B** at UBC using `devtools` and `usethis` packages.
The codes and pipeline used to create this package is as follows
```{r,eval=FALSE}
usethis::create_package(path = "RefineMod") #To initiate the package project locally
usethis::use_git() #To create a git repository of the package locally
```
This local repo is then linked to an empty github repository created with the same name `RefineMod`
```
git remote add origin https://github.com/asfarlathif/RefineMod.git
git branch -M main
git push -u origin main
```
```{r, eval=FALSE}
usethis::use_r("function name") #To create script files of the functions in this package
#All the functions were documented using the roxygen skeleton
devtools::document() #To record the documentation files and update NAMESPACE
usethis::use_readme_rmd() #README file initiation
usethis::use_mit_license() #LICENSE file
usethis::use_code_of_conduct() #CODE OF CONDUCT file
usethis::use_testthat() #To Create tests to include test scripts for the functions
usethis::use_test("function name") #intialize Funstion specific test scripts
usethis::use_package("package name") #To include package dependencies in the DESCRIPTION file
usethis::use_vignette("vignette name") #Initialize vignette RMD file
usethis::use_news_md() #Adding Changelogs
#PACKAGE DIAGNOSIS
devtools::test() #Run all testthat files
devtools::check() #Head to Toe evaluation of the package
```
## Installation
The development version of RefineMod can be installed from [GitHub](https://github.com/) with:
``` r
devtools::install_github("asfarlathif/RefineMod")
```
## Example
### Refining a linear regression model with only its significant predictors
`cancer_sample` data set from `datateachr` package
`radius_mean` as response variable and all (except `diagnosis`) as input predictors
```{r}
library(RefineMod)
library(datateachr)
mod <- lm(radius_mean ~ ., cancer_sample[,-2]) #lm() call without any predictor selection
summary(mod)
```
Above is the model built using all the input predictors as the independent variables while building the model. Many of these variables don’t show any statistical significance (in terms of their p-value) to be included in the model.
```{r}
sig_mod <- lm_significant(cancer_sample[,-2], res = "radius_mean") #model with optimized predictors
summary(sig_mod)
```
`perimeter_mean`, `compactness_mean`, `radius_worst`, `area_worst`, `concavity_mean`, `perimeter_worst` and `compactness_worst` are the predictors that were found to be statistically significant while building a model for the response variable `radius_mean`.
### Comparing Model Performance between one or more lm models
```{r}
train <- mtcars[1:20,]
test <- mtcars[21:30,]
mod1 <- lm(mpg~wt, train)
mod2 <- lm(mpg~cyl, train)
mod3 <- lm(mpg~wt+cyl, train)
mod4 <- lm(mpg~carb, train)
comp_mods(mod1, mod2, mod3, mod4, newdata = test)
```
## Code of Conduct
Please note that the RefineMod project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.