knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
version <- as.vector(read.dcf('DESCRIPTION')[, 'Version']) version <- gsub('-', '.', version)
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
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
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
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
The development version of RefineMod can be installed from GitHub with:
devtools::install_github("asfarlathif/RefineMod")
cancer_sample
data set from datateachr
package
radius_mean
as response variable and all (except diagnosis
) as input predictors
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.
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
.
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)
Please note that the RefineMod project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.