├── .Rbuildignore ├── .Rhistory ├── .gitignore ├── .travis.yml ├── CRAN-SUBMISSION ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── error.R ├── general.R ├── gg_boxcox.R ├── gg_cooksd.R ├── gg_diagnose.R ├── gg_qqplot.R ├── gg_resX.R ├── gg_resfitted.R ├── gg_reshist.R ├── gg_resleverage.R ├── gg_scalelocation.R └── plot_all.R ├── README.Rmd ├── README.md ├── cran-comments.md ├── figures ├── .DS_Store ├── README-unnamed-chunk-10-1.png ├── README-unnamed-chunk-11-1.png ├── README-unnamed-chunk-12-1.png ├── README-unnamed-chunk-13-1.png ├── README-unnamed-chunk-15-1.png ├── README-unnamed-chunk-16-1.png ├── README-unnamed-chunk-17-1.png ├── README-unnamed-chunk-18-1.png ├── README-unnamed-chunk-19-1.png ├── README-unnamed-chunk-21-1.png ├── README-unnamed-chunk-23-1.png ├── README-unnamed-chunk-24-1.png ├── README-unnamed-chunk-244-1.png ├── README-unnamed-chunk-246-1.png ├── README-unnamed-chunk-247-1.png ├── README-unnamed-chunk-248-1.png ├── README-unnamed-chunk-249-1.png ├── README-unnamed-chunk-25-1.png ├── README-unnamed-chunk-250-1.png ├── README-unnamed-chunk-251-1.png ├── README-unnamed-chunk-252-1.png ├── README-unnamed-chunk-253-1.png ├── README-unnamed-chunk-254-1.png ├── README-unnamed-chunk-255-1.png ├── README-unnamed-chunk-256-1.png ├── README-unnamed-chunk-257-1.png ├── README-unnamed-chunk-258-1.png ├── README-unnamed-chunk-259-1.png ├── README-unnamed-chunk-26-1.png ├── README-unnamed-chunk-27-1.png ├── README-unnamed-chunk-28-1.png ├── README-unnamed-chunk-29-1.png ├── README-unnamed-chunk-3-1.png ├── README-unnamed-chunk-30-1.png ├── README-unnamed-chunk-31-1.png ├── README-unnamed-chunk-32-1.png ├── README-unnamed-chunk-33-1.png ├── README-unnamed-chunk-34-1.png ├── README-unnamed-chunk-35-1.png ├── README-unnamed-chunk-36-1.png ├── README-unnamed-chunk-4-1.png ├── README-unnamed-chunk-5-1.png ├── README-unnamed-chunk-6-1.png ├── README-unnamed-chunk-7-1.png ├── README-unnamed-chunk-8-1.png ├── README-unnamed-chunk-9-1.png ├── lindia-main.png └── lindia-scale-location.png ├── lindia.Rproj └── man ├── gg_boxcox.Rd ├── gg_cooksd.Rd ├── gg_diagnose.Rd ├── gg_qqplot.Rd ├── gg_resX.Rd ├── gg_resfitted.Rd ├── gg_reshist.Rd ├── gg_resleverage.Rd ├── gg_scalelocation.Rd └── plot_all.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | ^CRAN-SUBMISSION$ 5 | ^cran-comments\.md$ 6 | -------------------------------------------------------------------------------- /.Rhistory: -------------------------------------------------------------------------------- 1 | install.packages("lindia") 2 | library("lindia") 3 | # create linear model 4 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 5 | install.packages("MASS") 6 | install.packages("MASS") 7 | data("Cars93") 8 | library("MASS") 9 | # create linear model 10 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 11 | # visualize diagnostic plots with a call to lindia 12 | gg_diagnose(cars_lm) 13 | library("lindia") 14 | # visualize diagnostic plots with a call to lindia 15 | gg_diagnose(cars_lm) 16 | detach("package:vegan", unload=TRUE) 17 | detach("package:lindia", unload=TRUE) 18 | install.packages("~/Desktop/personal/project/lindia/lindia", 19 | repos = NULL, 20 | type = "source") 21 | install.packages("~/Desktop/personal/project/lindia", 22 | repos = NULL, 23 | type = "source") 24 | install.packages("devtools") 25 | # To load package from local files 26 | library("devtools") 27 | load_all('~/Desktop/personal/projects/lindia/lindia') 28 | # create linear model 29 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 30 | # visualize diagnostic plots with a call to lindia 31 | gg_diagnose(cars_lm) 32 | load_all('~/Desktop/personal/projects/lindia/lindia') 33 | # visualize diagnostic plots with a call to lindia 34 | gg_diagnose(cars_lm) 35 | help(gg_diagnose) 36 | help(lm) 37 | help(ggplot) 38 | help(ggtitle) 39 | help(glm) 40 | load_all('~/Desktop/personal/projects/lindia/lindia') 41 | # visualize diagnostic plots with a call to lindia 42 | gg_diagnose(cars_lm) 43 | install.packages(mosaicData) 44 | install.packages("mosaicData") 45 | install.packages("moderndive") 46 | library(moderndive) 47 | data("SaratogaHouses") 48 | library(mosaicData) 49 | library(moderndive) 50 | data("SaratogaHouses") 51 | mod <- lm(price ~ livingArea, data = SaratogaHouses) 52 | gg_resX(mod) 53 | load_all('~/Desktop/personal/projects/lindia/lindia') 54 | load_all('~/Desktop/personal/projects/lindia/lindia') 55 | load_all('~/Desktop/personal/projects/lindia/lindia') 56 | mod <- lm(price ~ livingArea, data = SaratogaHouses) 57 | gg_resX(mod) 58 | formula(mod) 59 | var_names_list = strsplit(mod, ' ~ ') 60 | lm_formula <- formula(mod) 61 | var_names_list = strsplit(lm_formula, ' ~ ') 62 | lm_formula 63 | strsplit('price ~ livingArea', ' ~ ') 64 | lm_formula = as.character(formula(mod)) 65 | var_names_list = strsplit(lm_formula, ' ~ ') 66 | var_name_vec = strsplit_vec(lm_formula, ' ~ ') 67 | args_str = var_name_vec 68 | args = unlist(strsplit_vec(args_str, " \\+ ")) 69 | args 70 | # create linear model 71 | cars_lm <- lm(Price ~ Passengers, data = Cars93) 72 | # visualize diagnostic plots with a call to lindia 73 | gg_diagnose(cars_lm) 74 | strsplit_vec(args_str, " \\+ ") 75 | args_str 76 | load_all('~/Desktop/personal/projects/lindia/lindia') 77 | load_all('~/Desktop/personal/projects/lindia/lindia') 78 | # create linear model 79 | cars_lm <- lm(Price ~ Passengers, data = Cars93) 80 | # visualize diagnostic plots with a call to lindia 81 | gg_diagnose(cars_lm) 82 | mod <- lm(price ~ livingArea, data = SaratogaHouses) 83 | gg_resX(mod) 84 | # visualize diagnostic plots with a call to lindia 85 | gg_diagnose(cars_lm, mode="base_r") 86 | load_all('~/Desktop/personal/projects/lindia/lindia') 87 | # visualize diagnostic plots with a call to lindia 88 | gg_diagnose(cars_lm, mode="base_r") 89 | # create linear model 90 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 91 | # visualize diagnostic plots with a call to lindia 92 | gg_diagnose(cars_lm, mode="base_r") 93 | # create linear model 94 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 95 | # visualize diagnostic plots with a call to lindia 96 | gg_diagnose(cars_lm, mode="base_r") 97 | # visualize diagnostic plots with a call to lindia 98 | gg_diagnose(cars_lm) 99 | load_all('~/Desktop/personal/projects/lindia/lindia') 100 | # create linear model 101 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 102 | # visualize diagnostic plots with a call to lindia 103 | gg_diagnose(cars_lm) 104 | load_all('~/Desktop/personal/projects/lindia/lindia') 105 | # create linear model 106 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 107 | # visualize diagnostic plots with a call to lindia 108 | gg_diagnose(cars_lm) 109 | grepl("Passengers + Length + RPM", " \\+ ") 110 | grepl("Passengers + Length + RPM", "+") 111 | grepl(" \\+ ", "Passengers + Length + RPM") 112 | load_all('~/Desktop/personal/projects/lindia/lindia') 113 | # create linear model 114 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 115 | # visualize diagnostic plots with a call to lindia 116 | gg_diagnose(cars_lm) 117 | # create linear model 118 | cars_lm <- lm(Price ~ Passengers, data = Cars93) 119 | # visualize diagnostic plots with a call to lindia 120 | gg_diagnose(cars_lm) 121 | setwd('~/Desktop/personal/projects/lindia') 122 | devtools::release() 123 | devtools::check() 124 | setwd('~/Desktop/personal/projects/lindia/lindia') 125 | devtools::check() 126 | # create linear model 127 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 128 | # visualize diagnostic plots with a call to lindia 129 | gg_diagnose(cars_lm) 130 | devtools::check() 131 | # visualize diagnostic plots with a call to lindia 132 | gg_diagnose(cars_lm) 133 | # create linear model 134 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 135 | devtools::check() 136 | load_all('~/Desktop/personal/projects/lindia/lindia') 137 | # create linear model 138 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 139 | # visualize diagnostic plots with a call to lindia 140 | gg_diagnose(cars_lm) 141 | load_all('~/Desktop/personal/projects/lindia/lindia') 142 | # create linear model 143 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 144 | # visualize diagnostic plots with a call to lindia 145 | gg_diagnose(cars_lm) 146 | grepl(" + ", "Passengers + Length + RPM + Origin") 147 | grepl(" \\+ ", "Passengers + Length + RPM + Origin") 148 | load_all('~/Desktop/personal/projects/lindia/lindia') 149 | # create linear model 150 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 151 | # visualize diagnostic plots with a call to lindia 152 | gg_diagnose(cars_lm) 153 | devtools::check() 154 | devtools::document() 155 | devtools::check() 156 | grepl(" \\+ ", "Passengers + Length + RPM + Origin", fixed = TRUE) 157 | grepl(" \\+ ", "Prices", fixed = TRUE) 158 | # create linear model 159 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 160 | # visualize diagnostic plots with a call to lindia 161 | gg_diagnose(cars_lm) 162 | load_all('~/Desktop/personal/projects/lindia/lindia') 163 | # create linear model 164 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 165 | # visualize diagnostic plots with a call to lindia 166 | gg_diagnose(cars_lm) 167 | grepl(" \\+ ", "Passengers + Length + RPM + Origin", fixed = TRUE) 168 | grepl(" \\+ ", "Passengers + Length + RPM + Origin") 169 | strsplit_vec("Passengers + Length + RPM + Origin", " \\+ ") 170 | args_str <- "Passengers + Length + RPM + Origin" 171 | args = unlist(strsplit_vec(args_str, " \\+ ")) 172 | args 173 | # create linear model 174 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 175 | # visualize diagnostic plots with a call to lindia 176 | gg_diagnose(cars_lm) 177 | load_all('~/Desktop/personal/projects/lindia/lindia') 178 | # create linear model 179 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 180 | # visualize diagnostic plots with a call to lindia 181 | gg_diagnose(cars_lm) 182 | grepl(" \\+ ", args_str, fixed = TRUE) 183 | grepl(" \\+ ", args_str) 184 | grepl("\\+", args_str, fixed=TRUE) 185 | grepl("\+", args_str, fixed=TRUE) 186 | grepl("\\+", args_str, fixed=TRUE) 187 | args_str 188 | grepl(" \\+ ", args_str, fixed=TRUE) 189 | grepl(" \\+ ", args_str) 190 | load_all('~/Desktop/personal/projects/lindia/lindia') 191 | # create linear model 192 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 193 | # visualize diagnostic plots with a call to lindia 194 | gg_diagnose(cars_lm) 195 | devtools::check() 196 | ?grepl 197 | grepl(" + ", args_str, fixed=TRUE) 198 | load_all('~/Desktop/personal/projects/lindia/lindia') 199 | # create linear model 200 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 201 | # visualize diagnostic plots with a call to lindia 202 | gg_diagnose(cars_lm) 203 | devtools::check() 204 | devtools::check() 205 | devtools::check() 206 | # create linear model 207 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 208 | # visualize diagnostic plots with a call to lindia 209 | gg_diagnose(cars_lm) 210 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 211 | gg_diagnose(cars_lm) 212 | load_all('~/Desktop/personal/projects/lindia/lindia') 213 | # To load package from local files 214 | library("devtools") 215 | load_all('~/Desktop/personal/projects/lindia/lindia') 216 | # create linear model 217 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 218 | library("lindia") 219 | library("MASS") 220 | # create linear model 221 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 222 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 223 | gg_diagnose(cars_lm) 224 | load_all('~/Desktop/personal/projects/lindia/lindia') 225 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 226 | gg_diagnose(cars_lm) 227 | lm_object <- cars_lm 228 | lm_formula = as.character(formula(lm_object)) 229 | var_names_list = strsplit(lm_formula, ' ~ ') 230 | var_name_vec = strsplit_vec(lm_formula, ' ~ ') 231 | var_names_list 232 | var_name_vec 233 | # if there is more than one term 234 | args = unlist(strsplit_vec(args_str, " \\+ ")) 235 | # drop response variable 236 | args_str = var_name_vec 237 | # if there is more than one term 238 | args = unlist(strsplit_vec(args_str, " \\+ ")) 239 | args 240 | load_all('~/Desktop/personal/projects/lindia/lindia') 241 | # create linear model 242 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 243 | gg_diagnose(cars_lm) 244 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 245 | load_all('~/Desktop/personal/projects/lindia/lindia') 246 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 247 | gg_diagnose(cars_lm) 248 | classof(args_str) 249 | class(args_str) 250 | load_all('~/Desktop/personal/projects/lindia/lindia') 251 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 252 | gg_diagnose(cars_lm) 253 | load_all('~/Desktop/personal/projects/lindia/lindia') 254 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 255 | gg_diagnose(cars_lm) 256 | load_all('~/Desktop/personal/projects/lindia/lindia') 257 | # create linear model 258 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 259 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 260 | gg_diagnose(cars_lm) 261 | load_all('~/Desktop/personal/projects/lindia/lindia') 262 | gg_diagnose(cars_lm) 263 | load_all('~/Desktop/personal/projects/lindia/lindia') 264 | # create linear model 265 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 266 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 267 | gg_diagnose(cars_lm) 268 | load_all('~/Desktop/personal/projects/lindia/lindia') 269 | # create linear model 270 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 271 | gg_diagnose(cars_lm) 272 | load_all('~/Desktop/personal/projects/lindia/lindia') 273 | gg_diagnose(cars_lm) 274 | # 275 | library(lindia) 276 | library(mosaicData) 277 | library(moderndive) 278 | data("SaratogaHouses") 279 | mod <- lm(price ~ livingArea, data = SaratogaHouses) 280 | gg_resX(mod) 281 | load_all('~/Desktop/personal/projects/lindia/lindia') 282 | devtools::check() 283 | # To load package from local files 284 | library("devtools") 285 | cars_lm <- lm(Price ~ Passengers, data = Cars93) 286 | gg_diagnose(cars_lm) 287 | urlchecker::url_check() 288 | urlchecker::url_check() 289 | devtools::check() 290 | use_release_issue() 291 | urlchecker::url_check() 292 | devtools::check(remote = TRUE, manual = TRUE) 293 | devtools::check(remote = TRUE, manual = TRUE) 294 | devtools::check_win_devel() 295 | revdepcheck::revdep_check(num_workers = 4) 296 | install.packages('revdepcheck') 297 | revdepcheck::revdep_check(num_workers = 4) 298 | library(revdepcheck) 299 | install.packages('revdepcheck') 300 | devtools::install_github('r-lib/revdepcheck') 301 | revdepcheck::revdep_check(num_workers = 4) 302 | usethis::use_version('minor') 303 | devtools::submit_cran() 304 | use_cran_comments() 305 | devtools::check() 306 | devtools::check() 307 | use_cran_comments() 308 | devtools::submit_cran() 309 | devtools::revdep_check() 310 | devtools::build_readme() 311 | devtools::build_readme() 312 | devtools::check(remote = TRUE, manual = TRUE) 313 | devtools::submit_cran() 314 | ?devtools::check() 315 | ?devtools::check_built() 316 | devtools::check_built() 317 | setwd('~/Desktop/personal/projects/lindia/lindia') 318 | devtools::check_win_devel() 319 | devtools::build() 320 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | sudo: false 5 | cache: packages 6 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 0.10 2 | Date: 2023-07-29 20:48:55 UTC 3 | SHA: e24c70a31f617804e83916b23f3bc67af87e1799 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: lindia 2 | Type: Package 3 | Title: Automated Linear Regression Diagnostic 4 | Version: 0.10 5 | Authors@R: c(person("Yeuk Yu", "Lee", 6 | email = "lyeukyu@gmail.com", 7 | role = c("aut", "cre")), 8 | person("Samuel", "Ventura", 9 | email = "sventura@stat.cmu.edu", 10 | role = c("aut"))) 11 | Description: Provides a set of streamlined functions that allow 12 | easy generation of linear regression diagnostic plots necessarily 13 | for checking linear model assumptions. 14 | This package is meant for easy scheming of linear 15 | regression diagnostics, while preserving merits of 16 | "The Grammar of Graphics" as implemented in 'ggplot2'. 17 | See the 'ggplot2' website for more information regarding the 18 | specific capability of graphics. 19 | Depends: 20 | R (>= 3.2.2) 21 | License: MIT + file LICENSE 22 | Encoding: UTF-8 23 | RoxygenNote: 7.2.3 24 | Imports: 25 | MASS, 26 | ggplot2, 27 | gridExtra 28 | URL: https://github.com/yeukyul/lindia 29 | BugReports: https://github.com/yeukyul/lindia/issues 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2017 2 | COPYRIGHT HOLDER: Yeuk Yu Lee 3 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(gg_boxcox) 4 | export(gg_cooksd) 5 | export(gg_diagnose) 6 | export(gg_qqplot) 7 | export(gg_resX) 8 | export(gg_resfitted) 9 | export(gg_reshist) 10 | export(gg_resleverage) 11 | export(gg_scalelocation) 12 | export(plot_all) 13 | import(ggplot2) 14 | importFrom(MASS,boxcox) 15 | importFrom(gridExtra,grid.arrange) 16 | importFrom(stats,fitted) 17 | importFrom(stats,formula) 18 | importFrom(stats,hatvalues) 19 | importFrom(stats,qchisq) 20 | importFrom(stats,qnorm) 21 | importFrom(stats,quantile) 22 | importFrom(stats,residuals) 23 | importFrom(stats,rstandard) 24 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # lindia 0.10 2 | 3 | ## Breaking changes 4 | 5 | * `gg_boxcox()` now renders spline interpolation by default. If you want to turn it off, update settings for boxcox graph or use `packageVersion("lindia") = "0.9"`. 6 | 7 | ## New features 8 | 9 | * New `mode` param to `gg_diagnose()` to render predetermine set of graphs (`all` or `base_r`) (@Sid1204, #8) 10 | 11 | * Added spline interpolation to `gg_boxcox()` (@ColeConte, #5) 12 | 13 | 14 | ## Minor improvements and fixes 15 | 16 | * `gg_scalelocation` now has correct labels on x and y axis (previously flipped) (@Sid1204, #8) 17 | 18 | 19 | * Fixed error when `lm` object only has one predictor term (@yeukyul) 20 | 21 | -------------------------------------------------------------------------------- /R/error.R: -------------------------------------------------------------------------------- 1 | 2 | # This file contains exception checking and error handling functions 3 | 4 | # 5 | # exception handling function for malformed input in lindia 6 | # 7 | handle_exception <- function(input, function_name){ 8 | 9 | type = class(input) 10 | 11 | # exception handling : input not lm object 12 | if (type != "lm"){ 13 | stop(paste(function_name, "doesn't know how to handle non-lm object")) 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /R/general.R: -------------------------------------------------------------------------------- 1 | 2 | # This file contains general helper functions used in lindia 3 | 4 | # strsplit_vec - splits a string and returns a vector 5 | # 6 | # input: str - string to be splitted 7 | # split - character to be splitted by 8 | # output: a vector as a result of string splitting 9 | # 10 | strsplit_vec <- function(str, split) { 11 | return (unlist(strsplit(str, split))[-1]) 12 | } 13 | 14 | 15 | # 16 | # n_cat - returns the index of categorical varible in given regression 17 | # 18 | # input : varnames - vector of variable name strings 19 | # model_matrix - model_matrix of the fitted lm 20 | # output : index of categorical varible in given regression 21 | # 22 | n_cat <- function(varnames, model_matrix) { 23 | cat_inds = c() 24 | modelvars = colnames(model_matrix) 25 | for (i in 1:length(varnames)) { 26 | name = varnames[i] 27 | if (!(name %in% modelvars)) { 28 | cat_inds = c(cat_inds, i) 29 | } 30 | } 31 | return (cat_inds) 32 | } 33 | 34 | # 35 | # get_ncols - returns the appropriate number of columns to arrange number of plots 36 | # into a square display grid. ncol returned would at least be 1. 37 | # 38 | # input : n_plots - number of plots 39 | # output : a number represents number of column needed to organize the plots into a square grid 40 | # 41 | get_ncol <- function(n_plots) { 42 | return(max(floor(sqrt(n_plots)), 1)) 43 | } 44 | 45 | 46 | # 47 | # get_varnames - returns variable names in a lm. 48 | # 49 | # input : lm_object - fitted lm 50 | # output : list of two items 51 | # [[1]] : string variable names in fitted lm 52 | # [[2]] : vector of interaction terms 53 | # 54 | get_varnames <- function(lm_object) { 55 | 56 | lm_formula = as.character(formula(lm_object)) 57 | var_names_list = strsplit(lm_formula, ' ~ ') 58 | var_name_vec = strsplit_vec(lm_formula, ' ~ ') 59 | 60 | # drop response variable 61 | args_str = var_name_vec 62 | 63 | # check if there're more than one predictor terms 64 | if (grepl(" + ", lm_formula[3], fixed=TRUE)) { 65 | # if there is more than one term 66 | args = unlist(strsplit_vec(args_str, " \\+ ")) 67 | } else { 68 | args = c(args_str) 69 | } 70 | n_args = length(args) 71 | predictors = c() 72 | interaction = list() 73 | 74 | # count how many interaction terms there are 75 | # used for storing variables in return list 76 | n_inter = 1 77 | 78 | # find interaction terms 79 | for (i in 1:n_args) { 80 | term = args[i] 81 | 82 | # check if it is interaction term 83 | # !! caution: check if it works with multiple interaction 84 | if (grepl(' \\* ', term)) { 85 | inter_terms = unlist(strsplit(term, " \\* ")) 86 | predictors = c(predictors, inter_terms) 87 | interaction[[n_inter]] = inter_terms 88 | n_inter = n_inter + 1 89 | } 90 | else { 91 | predictors = c(predictors, term) 92 | } 93 | } 94 | 95 | # clean up duplicated predictors from extracting from interaction terms 96 | predictors = unique(predictors) 97 | 98 | return (list(predictors = predictors, interactions = interaction)) 99 | } 100 | -------------------------------------------------------------------------------- /R/gg_boxcox.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' Plot boxcox graph in ggplot with suggested lambda transformation 4 | #' 5 | #' @param fitted.lm a fitted linear model (i.e. lm, glm) that contains fitted regression 6 | #' @param showlambda logical; controls whether lambda value should be displayed on graph. Defaults to TRUE 7 | #' @param lambdaSF numeric; controls to how many significant figure is lambda rounded to. Defaults to 3. 8 | #' @param scale.factor numeric; scales the point size and linewidth to allow customized viewing. Defaults to 0.5. 9 | #' @return A ggplot object that contains boxcox graph 10 | #' @examples library(MASS) 11 | #' data(Cars93) 12 | #' cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 13 | #' gg_boxcox(cars_lm) 14 | #' 15 | #' @export 16 | #' @importFrom MASS boxcox 17 | gg_boxcox <- function(fitted.lm, showlambda = TRUE, lambdaSF = 3, scale.factor = 0.5){ 18 | 19 | handle_exception(fitted.lm, "gg_boxcox") 20 | 21 | # compute boxcox graph points 22 | boxcox_object <- boxcox(fitted.lm, plotit = FALSE,interp=TRUE) 23 | 24 | # create new dataframe to hold all x and y points 25 | x <- unlist(boxcox_object$x) 26 | y <- unlist(boxcox_object$y) 27 | 28 | # compute start and end of each line segment 29 | xstart <- x[-1] 30 | ystart <- y[-1] 31 | xend <- x[-(length(x))] 32 | yend <- y[-(length(y))] 33 | boxcox_unlist <- data.frame(xstart, ystart, xend, yend) 34 | 35 | # obtain best lamda 36 | best_lambda <- x[which.max(y)] 37 | rounded_lambda <- round(best_lambda, lambdaSF) 38 | min_y <- min(y) 39 | 40 | # compute accepted range of lambda transformation 41 | accept_inds <- which(y > max(y) - 1/2 * qchisq(.95,1)) 42 | accept_range <- x[accept_inds] 43 | conf_lo <- round(min(accept_range), lambdaSF) 44 | conf_hi <- round(max(accept_range), lambdaSF) 45 | 46 | plot <- ggplot(data = boxcox_unlist) + 47 | geom_segment(aes(x = xstart, y = ystart, xend = xend, yend = yend), size = scale.factor) + 48 | labs(x = "Lambda", y = "Log-likelihood") + 49 | ggtitle("Boxcox Plot") + 50 | geom_vline(xintercept = best_lambda, linetype = "dotted", size = scale.factor/2) + 51 | geom_vline(xintercept = conf_lo, linetype = "dotted", size = scale.factor/2) + 52 | geom_vline(xintercept = conf_hi, linetype = "dotted", size = scale.factor/2) + 53 | geom_hline(yintercept = y[min(accept_inds)], linetype = "dotted", size = scale.factor/2) 54 | 55 | # add label if show lambda range 56 | if (showlambda) { 57 | return(plot + 58 | geom_text(aes(x = best_lambda, label = as.character(rounded_lambda), y = min_y)) + 59 | geom_text(aes(x = conf_lo, label = as.character(conf_lo), y = min_y), color = "indianred3") + 60 | geom_text(aes(x = conf_hi, label = as.character(conf_hi), y = min_y), color = "indianred3")) 61 | } 62 | else { 63 | return (plot) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /R/gg_cooksd.R: -------------------------------------------------------------------------------- 1 | 2 | #' Plot cook's distance graph 3 | #' 4 | #' @param fitted.lm a fitted linear model (i.e. lm, glm) that contains fitted regression 5 | #' @param label logical; whether or not to label observation number larger than threshold. 6 | #' Default to TRUE. 7 | #' @param threshold string; determining the cut off label of cook's distance. Choices are 8 | #' "baseR" (0.5 and 1), "matlab" (mean(cooksd)*3), and "convention" (4/n and 1). Default to "convention". 9 | #' @param scale.factor numeric; scales the point size and linewidth to allow customized viewing. Defaults to 0.5. 10 | #' @param show.threshold logical; determine whether or not threshold line is to be shown. Default to TRUE. 11 | #' @return A ggplot object that contains a cook's distance plot 12 | #' @examples library(MASS) 13 | #' data(Cars93) 14 | #' cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 15 | #' gg_cooksd(cars_lm) 16 | #' 17 | #' @export 18 | gg_cooksd <- function(fitted.lm, label = TRUE, show.threshold = TRUE, threshold = "convention", scale.factor = 0.5) { 19 | 20 | handle_exception(fitted.lm, "gg_cooksd") 21 | 22 | # obtain linear model matrix 23 | lm_matrix <- fortify(fitted.lm) 24 | lm_matrix[, "rowname"] <- 1:nrow(lm_matrix) 25 | 26 | # threshold for outliar 27 | cooksd = lm_matrix[, ".cooksd"] 28 | n = nrow(lm_matrix) 29 | 30 | # compute the threshold value for cook's distance plot 31 | if (threshold == "matlab") { 32 | threshold = mean(cooksd) * 3 33 | } 34 | else if (threshold == "baseR") { 35 | threshold = c(0.5, 1) 36 | } 37 | else if (threshold == "convention") { 38 | threshold = c(4/n, 1) 39 | } 40 | else { 41 | stop("invalid threshold specified for gg_cooksd") 42 | } 43 | 44 | # window limit 45 | limit = max(cooksd, na.rm = T) 46 | margin_factor = 5 47 | margin = round(limit / margin_factor) 48 | max_cook = limit + margin 49 | 50 | .cooksd <- NULL 51 | 52 | base_plot <- (ggplot(fitted.lm, aes(1:nrow(lm_matrix), .cooksd, ymin = 0, ymax = cooksd)) + 53 | geom_point(size = scale.factor) + 54 | geom_linerange(size = scale.factor) + 55 | xlab("Observation Number") + 56 | ylab("Cook's distance") + 57 | ggtitle("Cook's Distance Plot") + 58 | ylim(0, max_cook)) 59 | 60 | # labelling of potential outliers 61 | if (label) { 62 | out_inds <- which(cooksd < min(threshold)) 63 | lm_matrix[out_inds, "rowname"] <- rep("", length(out_inds)) 64 | base_plot = base_plot + geom_text(label = lm_matrix[, "rowname"], nudge_x = 3, color = "indianred3") 65 | } 66 | 67 | # showing threshold for outliers 68 | if (show.threshold) { 69 | if (min(threshold) > max_cook) { 70 | message("Cut-off for outliers too big to be shown in Cook's Distance plot.") 71 | } 72 | else { 73 | for (i in 1:length(threshold)) { 74 | if (threshold[i] > max_cook) { 75 | next 76 | } 77 | base_plot = base_plot + geom_hline(yintercept = threshold[i], linetype = "dashed", color = "indianred3", size = scale.factor) 78 | } 79 | } 80 | } 81 | 82 | return(base_plot) 83 | } 84 | -------------------------------------------------------------------------------- /R/gg_diagnose.R: -------------------------------------------------------------------------------- 1 | 2 | #' Plot all diagnostic plots given fitted linear regression line. 3 | #' 4 | #' @param fitted.lm lm object that contains fitted regression 5 | #' @param theme ggplot graphing style using `ggplot::theme()`. A ggplot graphing style to apply to all plots. Default to null. 6 | #' @param ncol specify number of columns in resulting plot per page. Default to make a square matrix of the output. 7 | #' @param plot.all logical; determine whether plot will be returned as 8 | #' an arranged grid. When set to false, the function 9 | #' will return a list of diagnostic plots. Parameter defaults to TRUE. 10 | #' @param mode A string. Specifies which set of diagnostic plots to return: 11 | #' * `all` (the default) 12 | #' * `base_r`: only graphs included in the base R `plot(lm(...))` (i.e. residual vs fitted, QQ plot, scale location, residual vs leverage) 13 | #' @param scale.factor numeric; scales the point size, linewidth, labels in all diagnostic plots to allow optimal viewing. Defaults to 0.5. 14 | #' @param boxcox logical; detemine whether boxcox plot will be included. Parameter defaults to FALSE. 15 | #' @param max.per.page numeric; maximum number of plots allowed in one page. 16 | #' @return An arranged grid of linear model diagnostics plots in ggplot. 17 | #' If plot.all is set to FALSE, a list of ggplot objects will be returned instead. 18 | #' Name of the plots are set to respective variable names. 19 | #' @examples 20 | #' library(MASS) 21 | #' data(Cars93) 22 | #' # a regression with categorical variable 23 | #' cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 24 | #' gg_diagnose(cars_lm) 25 | #' # customize which diagnostic plot is included 26 | #' plots <- gg_diagnose(cars_lm, plot.all = FALSE) 27 | #' names(plots) # get name of the plots 28 | #' exclude_plots <- plots[-c(1, 3) ] #exclude certain diagnostics plots 29 | #' include_plots <- plots[c(1, 3)] # include certain diagnostics plots 30 | #' plot_all(exclude_plots) # make use of plot_all() in lindia 31 | #' plot_all(include_plots) 32 | #' @export 33 | #' @import ggplot2 34 | #' @importFrom gridExtra grid.arrange 35 | #' @importFrom stats fitted formula hatvalues qchisq qnorm quantile residuals rstandard 36 | gg_diagnose <- function(fitted.lm, theme = NULL, ncol = NA, plot.all = TRUE, mode = "all", 37 | scale.factor = 0.5, boxcox = FALSE, max.per.page = NA) 38 | { 39 | 40 | handle_exception(fitted.lm, "gg_diagnose") 41 | 42 | if(!(plot.all %in% c(TRUE, FALSE, "base_r"))) { 43 | plot.all = TRUE 44 | message("`plot.all` defaulting to TRUE: incorrect value supplied in function call.") 45 | } 46 | 47 | plots = list() 48 | # get all plots 49 | plots[["residual_hist"]] <- gg_reshist(fitted.lm) 50 | plots = append(plots, gg_resX(fitted.lm, plot.all = FALSE, scale.factor = scale.factor)) 51 | plots[["res_fitted"]] <- gg_resfitted(fitted.lm, scale.factor = scale.factor) 52 | plots[["qqplot"]] <- gg_qqplot(fitted.lm, scale.factor = scale.factor) 53 | plots[["scalelocation"]] <- gg_scalelocation(fitted.lm, scale.factor = scale.factor) 54 | plots[["resleverage"]] <- gg_resleverage(fitted.lm, scale.factor = scale.factor) 55 | plots[["cooksd"]] <- gg_cooksd(fitted.lm, scale.factor = scale.factor) 56 | if (boxcox) { 57 | plots[["boxcox"]] <- gg_boxcox(fitted.lm, scale.factor = scale.factor) 58 | } 59 | 60 | # apply style to all the plots 61 | if (!(is.null(theme))) { 62 | plots = lapply(plots, function(plot) { plot + theme }) 63 | } 64 | 65 | # handle malformed max.per.page request 66 | if (is.na(max.per.page)) { 67 | max.per.page = length(plots) 68 | } else if ((!inherits(max.per.page, "numeric")) || max.per.page < 1) { 69 | message("Maximum plots per page invalid; switch to default") 70 | max.per.page = length(plots) 71 | } 72 | 73 | if (mode == "base_r") { 74 | plots = plots[c("res_fitted","qqplot","scalelocation","resleverage")] 75 | } else if (mode != "all") { 76 | message("`mode` has invalid value, using 'all'") 77 | } 78 | 79 | # determine to plot the plots, or return a list of plots 80 | if (plot.all == TRUE) { 81 | return(arrange.plots(plots, max.per.page, ncol)) 82 | } else { 83 | return (plots) 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /R/gg_qqplot.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' Plot quantile-quantile plot (QQPlot) in ggplot with qqline shown. 4 | #' 5 | #' @param fitted.lm a fitted linear model (i.e. lm, glm) that contains fitted regression 6 | #' @param scale.factor numeric; scales the point size and linewidth to allow customized viewing. Defaults to 1. 7 | #' @return A qqplot with fitted qqline 8 | #' @examples library(MASS) 9 | #' data(Cars93) 10 | #' cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 11 | #' gg_qqplot(cars_lm) 12 | #' @export 13 | gg_qqplot <- function(fitted.lm, scale.factor = 1) { 14 | 15 | handle_exception(fitted.lm, "gg_qqplot") 16 | 17 | # extract residuals from lm object 18 | res = residuals(fitted.lm) 19 | 20 | # calculate slope and interncept for qqline 21 | slope = (quantile(res, .75) - quantile(res, .25)) / (qnorm(.75) - qnorm(.25)) 22 | intercept = quantile(res,.25) - slope*qnorm(.25) 23 | qq_line = data.frame(intercept = intercept, slope = slope) 24 | 25 | # generate ggplot for qqplot 26 | qq_plot <- ggplot(data = fitted.lm) + 27 | stat_qq(aes(sample = res), size = scale.factor) + 28 | labs(x = "Theoretical Quantile", y = "Standardized Residual") + 29 | geom_abline(data = qq_line ,aes(intercept = intercept ,slope = slope), color = "indianred3", size = scale.factor) + 30 | ggtitle("Normal-QQ Plot") 31 | qq_plot 32 | } 33 | -------------------------------------------------------------------------------- /R/gg_resX.R: -------------------------------------------------------------------------------- 1 | 2 | #' Generate residual plot of residuals against predictors 3 | #' 4 | #' @param fitted.lm a fitted linear model (i.e. lm, glm) that contains fitted regression 5 | #' @param plot.all boolean value to determine whether plot will be return as 6 | #' a plot arranged using `grid.arrange()`. When set to false, the function 7 | #' would return a list of residual plots. Parameter defaults to TRUE. 8 | #' @param ncol specify number of columns in resulting plot per page. Default to make a square matrix of the output. 9 | #' @param scale.factor numeric; scales the point size and linewidth to allow customized viewing. Defaults to 0.5. 10 | #' @param max.per.page numeric; maximum number of plots allowed in one page. Parameter defaults to fit all plots on one page. 11 | #' @return An arranged grid of residuals against predictor values plots in ggplot. 12 | #' If plotall is set to FALSE, a list of ggplot objects will be returned instead. 13 | #' Name of the plots are set to respective variable names. 14 | #' @examples 15 | #' library(MASS) 16 | #' data(Cars93) 17 | #' # a regression with categorical variable 18 | #' cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 19 | #' gg_resX(cars_lm) 20 | #' # customize which diagnostic plot is included by have gg_resX to return a list of plots 21 | #' plots <- gg_resX(cars_lm, plot.all = FALSE) 22 | #' names(plots) # get name of the plots 23 | #' exclude_plots <- plots[-1 ] #exclude certain residual plots 24 | #' include_plots <- plots[1] # include certain residual plots 25 | #' plot_all(exclude_plots) # make use of plot_all() in lindia 26 | #' plot_all(include_plots) 27 | #' @export 28 | gg_resX <- function(fitted.lm, plot.all = TRUE, scale.factor = 0.5, max.per.page = NA, ncol = NA){ 29 | 30 | handle_exception(fitted.lm, "gg_resX") 31 | 32 | # extract model matrix 33 | lm_matrix = fortify(fitted.lm) 34 | 35 | # extract relevant explanatory variables in model matrix 36 | var_names = get_varnames(fitted.lm)$predictor 37 | dim = length(var_names) 38 | 39 | # create a list to hold all residual plots 40 | plots = vector("list", dim) 41 | 42 | # number of plots so far 43 | n = 1 44 | 45 | for (i in 1:length(var_names)){ 46 | var = var_names[i] 47 | this_plot <- get_resplot(var, lm_matrix, fitted.lm, scale.factor) 48 | if (!is.null(this_plot)) { 49 | plots[[n]] <- this_plot 50 | n = n + 1 51 | } 52 | 53 | } 54 | 55 | # rename the plots 56 | names(plots) = var_names 57 | 58 | # handle malformed max.per.page request 59 | if (is.na(max.per.page)) { 60 | max.per.page = length(plots) 61 | } else if (!inherits(max.per.page, "numeric") || max.per.page < 1) { 62 | message("Maximum plots per page invalid; switch to default") 63 | max.per.page = length(plots) 64 | } 65 | 66 | # determine to plot the plots, or return a list of plots 67 | if (plot.all) { 68 | return(arrange.plots(plots, max.per.page, ncol)) 69 | } 70 | else { 71 | return (plots) 72 | } 73 | 74 | } 75 | 76 | # 77 | # arrange.plots arranges plot to pages according to max.per.page 78 | # 79 | arrange.plots <- function(plots, plots.per.page, ncol) { 80 | 81 | # get total number of plots 82 | len <- length(plots) 83 | if (plots.per.page >= len) { 84 | if (is.na(ncol)) { 85 | nCol = get_ncol(len) 86 | } else { 87 | nCol = ncol 88 | } 89 | return (do.call("grid.arrange", c(plots, ncol = nCol))) 90 | } 91 | 92 | # get pages needed 93 | pages <- ceiling(len/plots.per.page) 94 | 95 | for (i in 1:pages) { 96 | start = (i - 1) * (plots.per.page) + 1 97 | end = min(i * plots.per.page, len) 98 | if (is.na(ncol)) { 99 | nCol = get_ncol(end-start) 100 | } else { 101 | nCol = ncol 102 | } 103 | do.call("grid.arrange", c(plots[start:end], ncol = nCol)) 104 | } 105 | } 106 | 107 | # 108 | # get_resplot - returns a ggplot object of residuals in fitted.lm against var in lm_matrix 109 | # 110 | # input : var - variable name string the residual plot is about 111 | # lm_matrix - model matrix of the fitted lm 112 | # fitted.lm : fitted lm 113 | # data : original dataset (optional) 114 | # 115 | # output : a ggplot object of var vs. residual of fitted lm 116 | # 117 | get_resplot <- function(var, lm_matrix, fitted.lm, scale.factor){ 118 | 119 | # to center residual plot around y = 0 line 120 | res = residuals(fitted.lm) 121 | limit = max(abs(res)) 122 | margin_factor = 5 123 | margin = round(limit / margin_factor) 124 | 125 | n_var_threshold = 4 # if more number of variables than threshold, tilt label to 45 degrees 126 | 127 | # handle categorical and continuous variables 128 | x = lm_matrix[, var] 129 | 130 | # continuous variable: return scatterplot 131 | if (is.numeric(x)) { 132 | return (ggplot(data = fitted.lm, aes(x = lm_matrix[, var], y = fitted.lm$residuals)) + 133 | labs(x = var, y = "residuals") + 134 | ggtitle(paste("Residual vs.", var)) + 135 | geom_point(size = scale.factor) + 136 | geom_hline(yintercept = 0, linetype = "dashed", color = "indianred3", size = scale.factor) + 137 | ylim(-(limit + margin), limit + margin)) 138 | } 139 | # categorical variable: return boxplot 140 | else { 141 | base_plot = ggplot(data = data.frame(lm_matrix), aes(x = lm_matrix[, var], y = fitted.lm$residuals)) + 142 | labs(x = var, y = "Residuals") + 143 | ggtitle(paste("Residual vs.", var)) + 144 | geom_boxplot(size = scale.factor) 145 | if (nlevels(lm_matrix[, var]) > n_var_threshold) { 146 | return (base_plot + theme(axis.text.x = element_text(angle = 45, hjust = 1))) 147 | } 148 | else { 149 | return (base_plot) 150 | } 151 | return(base_plot) 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /R/gg_resfitted.R: -------------------------------------------------------------------------------- 1 | 2 | #' Generate residual plot of residuals against fitted value 3 | #' 4 | #' @param fitted.lm a fitted linear model (i.e. lm, glm) that contains fitted regression 5 | #' @param scale.factor numeric; scales the point size and linewidth to allow customized viewing. Defaults to 1. 6 | #' @return A ggplot object 7 | #' @examples library(MASS) 8 | #' data(Cars93) 9 | #' cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 10 | #' gg_resfitted(cars_lm) 11 | #' 12 | #' @export 13 | #' 14 | gg_resfitted <- function(fitted.lm, scale.factor = 1) { 15 | 16 | handle_exception(fitted.lm, "gg_resfitted") 17 | 18 | #obtain residual and fitted values from fitted.lm 19 | res = residuals(fitted.lm) 20 | fitted_values = fitted(fitted.lm) 21 | 22 | # to center residual plot around y = 0 line 23 | limit = max(abs(res)) 24 | margin_factor = 5 25 | margin = round(limit / margin_factor) 26 | 27 | df = data.frame(res, fitted_values) 28 | names(df) = c("residuals", "fitted_values") 29 | return (ggplot(data = df, aes(y = residuals, x = fitted_values)) + 30 | geom_point(size = scale.factor) + 31 | geom_hline(yintercept = 0, linetype = "dashed", color = "indianred3", size = scale.factor) + 32 | labs(y = "Residuals", x = "Fitted Values") + 33 | ylim(-(limit + margin), limit + margin) + 34 | ggtitle("Residual vs. Fitted Value")) 35 | } 36 | -------------------------------------------------------------------------------- /R/gg_reshist.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' Generate histogram of residuals in ggplot. 4 | #' 5 | #' @param fitted.lm a fitted linear model (i.e. lm, glm) that contains fitted regression 6 | #' @param bins bin size for histogram 7 | #' @return A ggplot object 8 | #' @examples 9 | #' library(MASS) 10 | #' data(Cars93) 11 | #' cars_lm <- lm(Price~ Passengers + Length + RPM, data = Cars93) 12 | #' gg_reshist(cars_lm) 13 | #' # specify number of bins 14 | #' gg_reshist(cars_lm, bins = 20) 15 | #' @export 16 | #' 17 | gg_reshist <- function(fitted.lm, bins = NULL) { 18 | 19 | handle_exception(fitted.lm, "gg_reshist") 20 | 21 | #obtain residual and fitted values from fitted.lm 22 | res = data.frame(residuals = residuals(fitted.lm)) 23 | 24 | if (is.null(bins)) { 25 | return (ggplot(data = res, aes(x = residuals)) + geom_histogram(color = "white") + 26 | ggtitle("Histogram of Residuals") + 27 | labs(x = "Residuals")) 28 | } 29 | else { 30 | return (ggplot(data = res, aes(x = residuals)) + geom_histogram(color = "white", bins = bins) + 31 | ggtitle("Histogram of Residuals") + 32 | labs(x = "Residuals", y = "Count")) 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /R/gg_resleverage.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' Plot residual versus leverage plot in ggplot. 4 | #' 5 | #' @param fitted.lm a fitted linear model (i.e. lm, glm) that contains fitted regression 6 | #' @param method smoothing method of fitted line on scale-location plot. 7 | #' eg. "lm", "glm", "gam", "loess", "rlm". See \url{https://ggplot2.tidyverse.org/reference/geom_smooth.html} 8 | #' for more details. 9 | #' @param se logical; determines whether se belt should be plotted on plot 10 | #' @param scale.factor numeric; scales the point size and linewidth to allow customized viewing. Defaults to 1. 11 | #' @return A ggplot object that contains residual vs. leverage graph 12 | #' @examples library(MASS) 13 | #' data(Cars93) 14 | #' cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 15 | #' gg_resleverage(cars_lm) 16 | #' @export 17 | #' 18 | gg_resleverage <- function(fitted.lm, method = "loess", se = FALSE, scale.factor = 1) { 19 | 20 | handle_exception(fitted.lm, "gg_resleverage") 21 | 22 | #obtain stardardized residual and fitted values from fitted.lm 23 | std_res = rstandard(fitted.lm) 24 | leverage = hatvalues(fitted.lm) 25 | 26 | df = data.frame(leverage, std_res) 27 | names(df) = c("leverage", "std_res") 28 | return (ggplot(data = df, aes(x = leverage, y = std_res)) + 29 | geom_point(size = scale.factor) + 30 | geom_smooth(method = method, se = se, color = "indianred3", size = scale.factor) + 31 | ggtitle("Residual vs. Leverage") + 32 | labs(y = "Standardized Residuals", x = "Leverage")) 33 | 34 | } 35 | -------------------------------------------------------------------------------- /R/gg_scalelocation.R: -------------------------------------------------------------------------------- 1 | 2 | #' Plot scale-location (also called spread-location plot) in ggplot. 3 | #' 4 | #' @param fitted.lm a fitted linear model (i.e. lm, glm) that contains fitted regression 5 | #' @param method smoothing method of fitted line on scale-location plot. 6 | #' eg. "lm", "glm", "gam", "loess", "rlm". See \url{https://ggplot2.tidyverse.org/reference/geom_smooth.html} 7 | #' for more details. 8 | #' @param se logical; determines whether se belt should be plotted on plot 9 | #' @param scale.factor numeric; scales the point size and linewidth to allow customized viewing. Defaults to 1. 10 | #' @return A ggplot object that contains scale-location graph 11 | #' @examples library(MASS) 12 | #' data(Cars93) 13 | #' cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 14 | #' gg_scalelocation(cars_lm) 15 | #' @export 16 | #' 17 | gg_scalelocation <- function(fitted.lm, method = 'loess', scale.factor = 1, se = FALSE) { 18 | 19 | handle_exception(fitted.lm, "gg_scalelocation") 20 | 21 | #obtain stardardized residual and fitted values from fitted.lm 22 | fitted_values = fitted(fitted.lm) 23 | std_res = rstandard(fitted.lm) 24 | 25 | df = data.frame(std_res, fitted_values) 26 | names(df) = c("sqrt(std_res)", "fitted_values") 27 | return (ggplot(data = df, aes(y = std_res, x = fitted_values)) + 28 | geom_point(size = scale.factor) + 29 | geom_smooth(method = method, se = se, size = scale.factor, color = "indianred3") + 30 | ggtitle("Scale-Location Plot") + 31 | labs(x="Fitted Values", y = "Sqrt (Standardized Residuals)")) 32 | } 33 | -------------------------------------------------------------------------------- /R/plot_all.R: -------------------------------------------------------------------------------- 1 | #' Plot all given plots in a square matrix form. 2 | #' 3 | #' @param plots a list of plots 4 | #' @param ncol numeric; the number of column that the arranged grid need to be. 5 | #' defaults to fitting all plots in square matrix 6 | #' @param max.per.page numeric; maximum number of plots allowed in one page. 7 | #' 8 | #' @return plots in a given list arrangeed using gridExtra 9 | #' @examples 10 | #' library(MASS) 11 | #' data(Cars93) 12 | #' # a regression with categorical variable 13 | #' cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 14 | #' plots <- gg_diagnose(cars_lm, plot.all = FALSE) 15 | #' names(plots) 16 | #' selected.plots <- plots[-c(2, 5)] 17 | #' plot_all(selected.plots) 18 | #' 19 | #' @export 20 | plot_all <- function(plots, ncol = NA, max.per.page = NA) { 21 | 22 | if (!inherits(plots, "list")) { 23 | stop("plot_all() doesn't know how to handle non-list input") 24 | } 25 | 26 | # handle malformed max.per.page request 27 | if (is.na(max.per.page)) { 28 | max.per.page = length(plots) 29 | } else if (!inherits(max.per.page, "numeric") || max.per.page < 1) { 30 | message("Maximum plots per page invalid; switch to default") 31 | max.per.page = length(plots) 32 | } 33 | 34 | return(arrange.plots(plots, max.per.page, ncol)) 35 | } -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | md_document: 4 | variant: markdown_github 5 | --- 6 | 7 | ```{r, echo = FALSE, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "# ", 11 | fig.path = "figures/README-" 12 | ) 13 | 14 | library(ggplot2) 15 | library(lindia) 16 | data(Cars93) 17 | 18 | ``` 19 | 20 | 21 | #lindia 22 | 23 | lindia is an extention to [**ggplot2**](http://ggplot2.org) to provide streamlined plotting features of linear model diagnostic plots. The following demonstrates basic plotting features of `lindia`. All functions in `lindia` takes in an lm object (including `lm()` and `glm()`) and returns linear diagnostic plots in forms of `ggplot` objects. The following code demonstrates how you can create a simple linear model from `Cars93` dataset, then use a call to `lindia::gg_diagnose()` to visualize overall features of the distribution. 24 | 25 | ```{r, warning = F, message = F, fig.width = 12, fig.height = 10} 26 | # create linear model 27 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 28 | 29 | # visualize diagnostic plots with a call to lindia 30 | gg_diagnose(cars_lm) 31 | ``` 32 | 33 | The functionality of lindia is an improvement of the features provided in base-R graphs. Using base-R, user can also create a series of diagnostic plots using the following line: 34 | 35 | ```{r, warning = F, message = F, fig.width = 12, fig.height = 10} 36 | par(mfrow = c(2,2)) 37 | plot(cars_lm) 38 | ``` 39 | 40 | However, the output from a call to `plot()` lacks flexibility and comprehensiveness. For example, residual vs. predictor plots are not shown, and that users cannot easily maipulate graph type and aesthetics. In that sense, `lindia` is an extension to features offered in base-R. 41 | 42 | #Installation 43 | 44 | + From Github: `devtools::install_github("yeukyul/lindia")` 45 | 46 | 47 | #Overview 48 | Followed are functions implemented in `lindia`: 49 | 50 | + [`gg_reshist()`](#gg_reshist): Histogram of residuals 51 | + [`gg_resfitted()`](#gg_resfitted): Residual plot of residuals by fitted value 52 | + [`gg_resX()`](#gg_resX): All residual plots of all predictors by fitted value, layed out in a grid 53 | + [`gg_qqplot()`](#gg_qqplot): Normaility quantile-quantile plot (QQPlot) with qqline overlayed on top 54 | + [`gg_boxcox()`](#gg_boxcox): Boxcox graph with optimal transformation labeled on graph 55 | + [`gg_scalelocation()`](#gg_scalelocation): Scale-location plot (also called spread-location plot) 56 | + [`gg_resleverage()`](#gg_resleverage): Residual by leverage plot 57 | + [`gg_cooksd()`](#gg_cooksd): Cook's distance plot with potential outliars labeled on top 58 | + [`gg_diagnose()`](#gg_diagnose): All diagnostic plots, layed out in a grid 59 | 60 | `gg_resX()` and `gg_diagnose()` would return multiple plots after a call to the function. By default, they would return one aggregate plot of all diagnostic plots as one arranged grid. If user needs more flexibility in determining graphical elements and inclusion/exclusion of certain plots, set `plot.all` parameter in the function call to `FALSE`. It will return a list of all plots, which user can manipulate. 61 | 62 | 63 | An example would as be followed: 64 | ```{r, warning = F, message = F} 65 | plots <- gg_diagnose(cars_lm, plot.all = FALSE) 66 | names(plots) 67 | exclude_plots <- plots[-c(1, 3)] # exclude certain diagnostics plots 68 | include_plots <- plots[c(1, 3)] # include certain diagnostics plots 69 | ``` 70 | 71 | 72 | In addition, `lindia` provides a `plot_all()` feature that allows user to pass in a list of plots and output as a formatted grid of plots using `gridExtra::grid.arrange()`. 73 | ```{r, warning = F, message = F, fig.width = 12, fig.height = 8} 74 | plot_all(exclude_plots) 75 | ``` 76 | 77 | All graphical styles returned by lindia graphing function can be overwritten by a call to `ggplot::theme()` (except `gg_resX()` and `gg_diagnose()`, which would return a list rather than a single ggplot object). 78 | ```{r, warning = F, message = F} 79 | gg_resfitted(cars_lm) + theme_bw() 80 | ``` 81 | 82 | #Functions in Lindia 83 | 84 | 85 | The following gives a brief demonstration of how to use the functions provided in `lindia`. 86 | 87 | #gg_reshist 88 | 89 | Plots distribution of residuals in histograms. Number of bins picked by default. 90 | ```{r, warning = F, message = F} 91 | gg_reshist(cars_lm) 92 | ``` 93 | 94 | Can also specify number of bins using `bins` argument: 95 | ```{r, warning = F, message = F} 96 | gg_reshist(cars_lm, bins = 20) 97 | ``` 98 | 99 | #gg_resX 100 | 101 | Plots residual plots of all predictors vs. residuals and return all plots as one plot that is arranged by package `gridExtra`. If a variable is continuous, it would be plotted as scatterplot. If a given variable is category is categorical, lindia would plot boxplot for that variable. 102 | ```{r, warning = F, message = F} 103 | cars_lm_2 <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 104 | gg_resX(cars_lm) 105 | ``` 106 | 107 | 108 | `lindia` can also handle linear models with interaction terms. 109 | 110 | ```{r, warning = F, message = F} 111 | cars_lm_inter <- lm(Price ~ Passengers * Length, data = Cars93) 112 | gg_resX(cars_lm_inter) 113 | ``` 114 | 115 | 116 | #gg_resfitted 117 | 118 | Plots residual against fitted value. 119 | ```{r, warning = F, message = F} 120 | gg_resfitted(cars_lm) 121 | ``` 122 | 123 | 124 | #gg_qqplot 125 | 126 | Plots quantile quantile plot of a linear model, with qqline overlayed on top. 127 | 128 | ```{r, warning = F, message = F} 129 | gg_qqplot(cars_lm) 130 | ``` 131 | 132 | #gg_boxcox 133 | 134 | Plots boxcox graph of given lm object, with labels showing optimal transforming power of response variable using box-cox transformation. Can hide labels on graph by setting `showlambda` to `FALSE`. 135 | ```{r, warning = F, message = F} 136 | gg_boxcox(cars_lm) 137 | ``` 138 | 139 | #gg_scalelocation 140 | 141 | Plots scale location graph of linear model. 142 | 143 | ```{r, warning = F, message = F} 144 | gg_scalelocation(cars_lm) 145 | ``` 146 | 147 | 148 | #gg_resleverage 149 | 150 | Plots residual vs. leverage of data points to detect outliers using cook's distance. 151 | 152 | ```{r, warning = F, message = F} 153 | gg_resleverage(cars_lm) 154 | ``` 155 | 156 | #gg_cooksd 157 | 158 | Plots cook's distance plot that helps identify outliers. Observation numbers are plotted next to data points that are considered anamolies. 159 | 160 | ```{r, warning = F, message = F} 161 | gg_cooksd(cars_lm) 162 | ``` 163 | 164 | 165 | #gg_diagnose 166 | 167 | An aggregate plot of all diagnostics plots, layed out on one panel as demonstrated in the beginning of this README document. User can set `theme` parameter to a specific theme type in order to apply to all plots in the panel. 168 | 169 | ```{r, warning = F, message = F, fig.width = 12, fig.height = 10} 170 | gg_diagnose(cars_lm_2, theme = theme_bw()) 171 | ``` 172 | 173 | If user set `plot.all` parameter to false, `gg_diagnose` would return a list of ggplot objects which user can manipulate. `lindia` also provides a handy trick that allows user to scale all point sizes and linewidth at once, using the parameter `scale.factor`. Followed is an extreme example by setting `scale.factor` to 0.3. 174 | 175 | ```{r, warning = F, message = F, fig.width = 12, fig.height = 10} 176 | gg_diagnose(cars_lm_2, theme = theme_bw(), scale.factor = 0.3) 177 | ``` 178 | 179 | 180 | #Package Dependency 181 | 182 | Lindia is built on top of the following few packages: 183 | 184 | + `ggplot2`: ver 2.1.0 185 | 186 | + `gridExtra`: ver 2.1.1 187 | 188 | 189 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | lindia 2 | ====== 3 | 4 | lindia is an extention to [**ggplot2**](http://ggplot2.org) to provide streamlined plotting features of linear model diagnostic plots. The following demonstrates basic plotting features of `lindia`. All functions in `lindia` takes in an lm object (including `lm()` and `glm()`) and returns linear diagnostic plots in forms of `ggplot` objects. The following code demonstrates how you can create a simple linear model from `Cars93` dataset, then use a call to `lindia::gg_diagnose()` to visualize overall features of the distribution. 5 | 6 | ``` r 7 | # create linear model 8 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 9 | 10 | # visualize diagnostic plots with a call to lindia 11 | gg_diagnose(cars_lm) 12 | ``` 13 | 14 | ![](figures/lindia-main.png) 15 | 16 | The functionality of lindia is an improvement of the features provided in base-R graphs. Using base-R, user can also create a series of diagnostic plots using the following line: 17 | 18 | ``` r 19 | par(mfrow = c(2,2)) 20 | plot(cars_lm) 21 | ``` 22 | 23 | ![](figures/README-unnamed-chunk-3-1.png) 24 | 25 | However, the output from a call to `plot()` lacks flexibility and comprehensiveness. For example, residual vs. predictor plots are not shown, and that users cannot easily maipulate graph type and aesthetics. In that sense, `lindia` is an extension to features offered in base-R. 26 | 27 | Installation 28 | ============ 29 | 30 | - From Github: `devtools::install_github("yeukyul/lindia")` 31 | 32 | Overview 33 | ======== 34 | 35 | Followed are functions implemented in `lindia`: 36 | 37 | - [`gg_reshist()`](#gg_reshist): Histogram of residuals 38 | - [`gg_resfitted()`](#gg_resfitted): Residual plot of residuals by fitted value 39 | - [`gg_resX()`](#gg_resX): All residual plots of all predictors by fitted value, layed out in a grid 40 | - [`gg_qqplot()`](#gg_qqplot): Normaility quantile-quantile plot (QQPlot) with qqline overlayed on top 41 | - [`gg_boxcox()`](#gg_boxcox): Boxcox graph with optimal transformation labeled on graph 42 | - [`gg_scalelocation()`](#gg_scalelocation): Scale-location plot (also called spread-location plot) 43 | - [`gg_resleverage()`](#gg_resleverage): Residual by leverage plot 44 | - [`gg_cooksd()`](#gg_cooksd): Cook's distance plot with potential outliars labeled on top 45 | - [`gg_diagnose()`](#gg_diagnose): All diagnostic plots, layed out in a grid 46 | 47 | `gg_resX()` and `gg_diagnose()` would return multiple plots after a call to the function. By default, they would return one aggregate plot of all diagnostic plots as one arranged grid. If user needs more flexibility in determining graphical elements and inclusion/exclusion of certain plots, set `plot.all` parameter in the function call to `FALSE`. It will return a list of all plots, which user can manipulate. 48 | 49 | An example would as be followed: 50 | 51 | ``` r 52 | plots <- gg_diagnose(cars_lm, plot.all = FALSE) 53 | names(plots) 54 | # [1] "residual_hist" "Passengers" "Length" "RPM" 55 | # [5] "res_fitted" "qqplot" "scalelocation" "resleverage" 56 | # [9] "cooksd" 57 | exclude_plots <- plots[-c(1, 3)] # exclude certain diagnostics plots 58 | include_plots <- plots[c(1, 3)] # include certain diagnostics plots 59 | ``` 60 | 61 | In addition, `lindia` provides a `plot_all()` feature that allows user to pass in a list of plots and output as a formatted grid of plots using `gridExtra::grid.arrange()`. 62 | 63 | ``` r 64 | plot_all(exclude_plots) 65 | ``` 66 | 67 | ![](figures/README-unnamed-chunk-5-1.png) 68 | 69 | All graphical styles returned by lindia graphing function can be overwritten by a call to `ggplot::theme()` (except `gg_resX()` and `gg_diagnose()`, which would return a list rather than a single ggplot object). 70 | 71 | ``` r 72 | gg_resfitted(cars_lm) + theme_bw() 73 | ``` 74 | 75 | ![](figures/README-unnamed-chunk-6-1.png) 76 | 77 | Functions in Lindia 78 | =================== 79 | 80 | The following gives a brief demonstration of how to use the functions provided in `lindia`. 81 | 82 | gg\_reshist 83 | =========== 84 | 85 | Plots distribution of residuals in histograms. Number of bins picked by default. 86 | 87 | ``` r 88 | gg_reshist(cars_lm) 89 | ``` 90 | 91 | ![](figures/README-unnamed-chunk-7-1.png) 92 | 93 | Can also specify number of bins using `bins` argument: 94 | 95 | ``` r 96 | gg_reshist(cars_lm, bins = 20) 97 | ``` 98 | 99 | ![](figures/README-unnamed-chunk-8-1.png) 100 | 101 | gg\_resX 102 | ======== 103 | 104 | Plots residual plots of all predictors vs. residuals and return all plots as one plot that is arranged by package `gridExtra`. If a variable is continuous, it would be plotted as scatterplot. If a given variable is category is categorical, lindia would plot boxplot for that variable. 105 | 106 | ``` r 107 | cars_lm_2 <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 108 | gg_resX(cars_lm) 109 | ``` 110 | 111 | ![](figures/README-unnamed-chunk-9-1.png) 112 | 113 | `lindia` can also handle linear models with interaction terms. 114 | 115 | ``` r 116 | cars_lm_inter <- lm(Price ~ Passengers * Length, data = Cars93) 117 | gg_resX(cars_lm_inter) 118 | ``` 119 | 120 | ![](figures/README-unnamed-chunk-10-1.png) 121 | 122 | gg\_resfitted 123 | ============= 124 | 125 | Plots residual against fitted value. 126 | 127 | ``` r 128 | gg_resfitted(cars_lm) 129 | ``` 130 | 131 | ![](figures/README-unnamed-chunk-11-1.png) 132 | 133 | gg\_qqplot 134 | ========== 135 | 136 | Plots quantile quantile plot of a linear model, with qqline overlayed on top. 137 | 138 | ``` r 139 | gg_qqplot(cars_lm) 140 | ``` 141 | 142 | ![](figures/README-unnamed-chunk-12-1.png) 143 | 144 | gg\_boxcox 145 | ========== 146 | 147 | Plots boxcox graph of given lm object, with labels showing optimal transforming power of response variable using box-cox transformation. Can hide labels on graph by setting `showlambda` to `FALSE`. 148 | 149 | ``` r 150 | gg_boxcox(cars_lm) 151 | ``` 152 | 153 | ![](figures/README-unnamed-chunk-13-1.png) 154 | 155 | gg\_scalelocation 156 | ================= 157 | 158 | Plots scale location graph of linear model. 159 | 160 | ``` r 161 | gg_scalelocation(cars_lm) 162 | ``` 163 | 164 | ![](figures/lindia-scale-location.png) 165 | 166 | gg\_resleverage 167 | =============== 168 | 169 | Plots residual vs. leverage of data points to detect outliers using cook's distance. 170 | 171 | ``` r 172 | gg_resleverage(cars_lm) 173 | ``` 174 | 175 | ![](figures/README-unnamed-chunk-15-1.png) 176 | 177 | gg\_cooksd 178 | ========== 179 | 180 | Plots cook's distance plot that helps identify outliers. Observation numbers are plotted next to data points that are considered anamolies. 181 | 182 | ``` r 183 | gg_cooksd(cars_lm) 184 | ``` 185 | 186 | ![](figures/README-unnamed-chunk-16-1.png) 187 | 188 | gg\_diagnose 189 | ============ 190 | 191 | An aggregate plot of all diagnostics plots, layed out on one panel as demonstrated in the beginning of this README document. User can set `theme` parameter to a specific theme type in order to apply to all plots in the panel. 192 | 193 | ``` r 194 | gg_diagnose(cars_lm_2, theme = theme_bw()) 195 | ``` 196 | 197 | ![](figures/README-unnamed-chunk-17-1.png) 198 | 199 | If user set `plot.all` parameter to false, `gg_diagnose` would return a list of ggplot objects which user can manipulate. `lindia` also provides a handy trick that allows user to scale all point sizes and linewidth at once, using the parameter `scale.factor`. Followed is an extreme example by setting `scale.factor` to 0.3. 200 | 201 | ``` r 202 | gg_diagnose(cars_lm_2, theme = theme_bw(), scale.factor = 0.3) 203 | ``` 204 | 205 | ![](figures/README-unnamed-chunk-18-1.png) 206 | 207 | Package Dependency 208 | ================== 209 | 210 | Lindia is built on top of the following few packages: 211 | 212 | - `ggplot2`: ver 2.1.0 213 | 214 | - `gridExtra`: ver 2.1.1 215 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors | 0 warnings | 0 notes 4 | 5 | Followed the CRAN checklist and have ran `urlchecker::url_check()`, `devtools::check(remote = TRUE, manual = TRUE)`, `devtools::check_win_devel()`, and `revdepcheck::revdep_check(num_workers = 4)` without any error, warning, or note. 6 | -------------------------------------------------------------------------------- /figures/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/.DS_Store -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-15-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-21-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-21-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-23-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-23-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-24-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-24-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-244-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-244-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-246-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-246-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-247-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-247-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-248-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-248-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-249-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-249-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-25-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-25-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-250-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-250-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-251-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-251-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-252-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-252-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-253-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-253-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-254-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-254-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-255-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-255-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-256-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-256-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-257-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-257-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-258-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-258-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-259-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-259-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-26-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-26-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-27-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-27-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-28-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-28-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-29-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-29-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-30-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-30-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-31-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-31-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-32-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-32-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-33-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-33-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-34-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-34-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-35-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-35-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-36-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-36-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /figures/README-unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/README-unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /figures/lindia-main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/lindia-main.png -------------------------------------------------------------------------------- /figures/lindia-scale-location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeukyul/lindia/f7da568891dee25a12046683bdf7f0c84dcbbe1f/figures/lindia-scale-location.png -------------------------------------------------------------------------------- /lindia.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 3 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /man/gg_boxcox.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_boxcox.R 3 | \name{gg_boxcox} 4 | \alias{gg_boxcox} 5 | \title{Plot boxcox graph in ggplot with suggested lambda transformation} 6 | \usage{ 7 | gg_boxcox(fitted.lm, showlambda = TRUE, lambdaSF = 3, scale.factor = 0.5) 8 | } 9 | \arguments{ 10 | \item{fitted.lm}{a fitted linear model (i.e. lm, glm) that contains fitted regression} 11 | 12 | \item{showlambda}{logical; controls whether lambda value should be displayed on graph. Defaults to TRUE} 13 | 14 | \item{lambdaSF}{numeric; controls to how many significant figure is lambda rounded to. Defaults to 3.} 15 | 16 | \item{scale.factor}{numeric; scales the point size and linewidth to allow customized viewing. Defaults to 0.5.} 17 | } 18 | \value{ 19 | A ggplot object that contains boxcox graph 20 | } 21 | \description{ 22 | Plot boxcox graph in ggplot with suggested lambda transformation 23 | } 24 | \examples{ 25 | library(MASS) 26 | data(Cars93) 27 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 28 | gg_boxcox(cars_lm) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /man/gg_cooksd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_cooksd.R 3 | \name{gg_cooksd} 4 | \alias{gg_cooksd} 5 | \title{Plot cook's distance graph} 6 | \usage{ 7 | gg_cooksd( 8 | fitted.lm, 9 | label = TRUE, 10 | show.threshold = TRUE, 11 | threshold = "convention", 12 | scale.factor = 0.5 13 | ) 14 | } 15 | \arguments{ 16 | \item{fitted.lm}{a fitted linear model (i.e. lm, glm) that contains fitted regression} 17 | 18 | \item{label}{logical; whether or not to label observation number larger than threshold. 19 | Default to TRUE.} 20 | 21 | \item{show.threshold}{logical; determine whether or not threshold line is to be shown. Default to TRUE.} 22 | 23 | \item{threshold}{string; determining the cut off label of cook's distance. Choices are 24 | "baseR" (0.5 and 1), "matlab" (mean(cooksd)*3), and "convention" (4/n and 1). Default to "convention".} 25 | 26 | \item{scale.factor}{numeric; scales the point size and linewidth to allow customized viewing. Defaults to 0.5.} 27 | } 28 | \value{ 29 | A ggplot object that contains a cook's distance plot 30 | } 31 | \description{ 32 | Plot cook's distance graph 33 | } 34 | \examples{ 35 | library(MASS) 36 | data(Cars93) 37 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 38 | gg_cooksd(cars_lm) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/gg_diagnose.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_diagnose.R 3 | \name{gg_diagnose} 4 | \alias{gg_diagnose} 5 | \title{Plot all diagnostic plots given fitted linear regression line.} 6 | \usage{ 7 | gg_diagnose( 8 | fitted.lm, 9 | theme = NULL, 10 | ncol = NA, 11 | plot.all = TRUE, 12 | mode = "all", 13 | scale.factor = 0.5, 14 | boxcox = FALSE, 15 | max.per.page = NA 16 | ) 17 | } 18 | \arguments{ 19 | \item{fitted.lm}{lm object that contains fitted regression} 20 | 21 | \item{theme}{ggplot graphing style using `ggplot::theme()`. A ggplot graphing style to apply to all plots. Default to null.} 22 | 23 | \item{ncol}{specify number of columns in resulting plot per page. Default to make a square matrix of the output.} 24 | 25 | \item{plot.all}{logical; determine whether plot will be returned as 26 | an arranged grid. When set to false, the function 27 | will return a list of diagnostic plots. Parameter defaults to TRUE.} 28 | 29 | \item{mode}{A string. Specifies which set of diagnostic plots to return: 30 | * `all` (the default) 31 | * `base_r`: only graphs included in the base R `plot(lm(...))` (i.e. residual vs fitted, QQ plot, scale location, residual vs leverage)} 32 | 33 | \item{scale.factor}{numeric; scales the point size, linewidth, labels in all diagnostic plots to allow optimal viewing. Defaults to 0.5.} 34 | 35 | \item{boxcox}{logical; detemine whether boxcox plot will be included. Parameter defaults to FALSE.} 36 | 37 | \item{max.per.page}{numeric; maximum number of plots allowed in one page.} 38 | } 39 | \value{ 40 | An arranged grid of linear model diagnostics plots in ggplot. 41 | If plot.all is set to FALSE, a list of ggplot objects will be returned instead. 42 | Name of the plots are set to respective variable names. 43 | } 44 | \description{ 45 | Plot all diagnostic plots given fitted linear regression line. 46 | } 47 | \examples{ 48 | library(MASS) 49 | data(Cars93) 50 | # a regression with categorical variable 51 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 52 | gg_diagnose(cars_lm) 53 | # customize which diagnostic plot is included 54 | plots <- gg_diagnose(cars_lm, plot.all = FALSE) 55 | names(plots) # get name of the plots 56 | exclude_plots <- plots[-c(1, 3) ] #exclude certain diagnostics plots 57 | include_plots <- plots[c(1, 3)] # include certain diagnostics plots 58 | plot_all(exclude_plots) # make use of plot_all() in lindia 59 | plot_all(include_plots) 60 | } 61 | -------------------------------------------------------------------------------- /man/gg_qqplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_qqplot.R 3 | \name{gg_qqplot} 4 | \alias{gg_qqplot} 5 | \title{Plot quantile-quantile plot (QQPlot) in ggplot with qqline shown.} 6 | \usage{ 7 | gg_qqplot(fitted.lm, scale.factor = 1) 8 | } 9 | \arguments{ 10 | \item{fitted.lm}{a fitted linear model (i.e. lm, glm) that contains fitted regression} 11 | 12 | \item{scale.factor}{numeric; scales the point size and linewidth to allow customized viewing. Defaults to 1.} 13 | } 14 | \value{ 15 | A qqplot with fitted qqline 16 | } 17 | \description{ 18 | Plot quantile-quantile plot (QQPlot) in ggplot with qqline shown. 19 | } 20 | \examples{ 21 | library(MASS) 22 | data(Cars93) 23 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 24 | gg_qqplot(cars_lm) 25 | } 26 | -------------------------------------------------------------------------------- /man/gg_resX.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_resX.R 3 | \name{gg_resX} 4 | \alias{gg_resX} 5 | \title{Generate residual plot of residuals against predictors} 6 | \usage{ 7 | gg_resX( 8 | fitted.lm, 9 | plot.all = TRUE, 10 | scale.factor = 0.5, 11 | max.per.page = NA, 12 | ncol = NA 13 | ) 14 | } 15 | \arguments{ 16 | \item{fitted.lm}{a fitted linear model (i.e. lm, glm) that contains fitted regression} 17 | 18 | \item{plot.all}{boolean value to determine whether plot will be return as 19 | a plot arranged using `grid.arrange()`. When set to false, the function 20 | would return a list of residual plots. Parameter defaults to TRUE.} 21 | 22 | \item{scale.factor}{numeric; scales the point size and linewidth to allow customized viewing. Defaults to 0.5.} 23 | 24 | \item{max.per.page}{numeric; maximum number of plots allowed in one page. Parameter defaults to fit all plots on one page.} 25 | 26 | \item{ncol}{specify number of columns in resulting plot per page. Default to make a square matrix of the output.} 27 | } 28 | \value{ 29 | An arranged grid of residuals against predictor values plots in ggplot. 30 | If plotall is set to FALSE, a list of ggplot objects will be returned instead. 31 | Name of the plots are set to respective variable names. 32 | } 33 | \description{ 34 | Generate residual plot of residuals against predictors 35 | } 36 | \examples{ 37 | library(MASS) 38 | data(Cars93) 39 | # a regression with categorical variable 40 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 41 | gg_resX(cars_lm) 42 | # customize which diagnostic plot is included by have gg_resX to return a list of plots 43 | plots <- gg_resX(cars_lm, plot.all = FALSE) 44 | names(plots) # get name of the plots 45 | exclude_plots <- plots[-1 ] #exclude certain residual plots 46 | include_plots <- plots[1] # include certain residual plots 47 | plot_all(exclude_plots) # make use of plot_all() in lindia 48 | plot_all(include_plots) 49 | } 50 | -------------------------------------------------------------------------------- /man/gg_resfitted.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_resfitted.R 3 | \name{gg_resfitted} 4 | \alias{gg_resfitted} 5 | \title{Generate residual plot of residuals against fitted value} 6 | \usage{ 7 | gg_resfitted(fitted.lm, scale.factor = 1) 8 | } 9 | \arguments{ 10 | \item{fitted.lm}{a fitted linear model (i.e. lm, glm) that contains fitted regression} 11 | 12 | \item{scale.factor}{numeric; scales the point size and linewidth to allow customized viewing. Defaults to 1.} 13 | } 14 | \value{ 15 | A ggplot object 16 | } 17 | \description{ 18 | Generate residual plot of residuals against fitted value 19 | } 20 | \examples{ 21 | library(MASS) 22 | data(Cars93) 23 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 24 | gg_resfitted(cars_lm) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/gg_reshist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_reshist.R 3 | \name{gg_reshist} 4 | \alias{gg_reshist} 5 | \title{Generate histogram of residuals in ggplot.} 6 | \usage{ 7 | gg_reshist(fitted.lm, bins = NULL) 8 | } 9 | \arguments{ 10 | \item{fitted.lm}{a fitted linear model (i.e. lm, glm) that contains fitted regression} 11 | 12 | \item{bins}{bin size for histogram} 13 | } 14 | \value{ 15 | A ggplot object 16 | } 17 | \description{ 18 | Generate histogram of residuals in ggplot. 19 | } 20 | \examples{ 21 | library(MASS) 22 | data(Cars93) 23 | cars_lm <- lm(Price~ Passengers + Length + RPM, data = Cars93) 24 | gg_reshist(cars_lm) 25 | # specify number of bins 26 | gg_reshist(cars_lm, bins = 20) 27 | } 28 | -------------------------------------------------------------------------------- /man/gg_resleverage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_resleverage.R 3 | \name{gg_resleverage} 4 | \alias{gg_resleverage} 5 | \title{Plot residual versus leverage plot in ggplot.} 6 | \usage{ 7 | gg_resleverage(fitted.lm, method = "loess", se = FALSE, scale.factor = 1) 8 | } 9 | \arguments{ 10 | \item{fitted.lm}{a fitted linear model (i.e. lm, glm) that contains fitted regression} 11 | 12 | \item{method}{smoothing method of fitted line on scale-location plot. 13 | eg. "lm", "glm", "gam", "loess", "rlm". See \url{https://ggplot2.tidyverse.org/reference/geom_smooth.html} 14 | for more details.} 15 | 16 | \item{se}{logical; determines whether se belt should be plotted on plot} 17 | 18 | \item{scale.factor}{numeric; scales the point size and linewidth to allow customized viewing. Defaults to 1.} 19 | } 20 | \value{ 21 | A ggplot object that contains residual vs. leverage graph 22 | } 23 | \description{ 24 | Plot residual versus leverage plot in ggplot. 25 | } 26 | \examples{ 27 | library(MASS) 28 | data(Cars93) 29 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 30 | gg_resleverage(cars_lm) 31 | } 32 | -------------------------------------------------------------------------------- /man/gg_scalelocation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gg_scalelocation.R 3 | \name{gg_scalelocation} 4 | \alias{gg_scalelocation} 5 | \title{Plot scale-location (also called spread-location plot) in ggplot.} 6 | \usage{ 7 | gg_scalelocation(fitted.lm, method = "loess", scale.factor = 1, se = FALSE) 8 | } 9 | \arguments{ 10 | \item{fitted.lm}{a fitted linear model (i.e. lm, glm) that contains fitted regression} 11 | 12 | \item{method}{smoothing method of fitted line on scale-location plot. 13 | eg. "lm", "glm", "gam", "loess", "rlm". See \url{https://ggplot2.tidyverse.org/reference/geom_smooth.html} 14 | for more details.} 15 | 16 | \item{scale.factor}{numeric; scales the point size and linewidth to allow customized viewing. Defaults to 1.} 17 | 18 | \item{se}{logical; determines whether se belt should be plotted on plot} 19 | } 20 | \value{ 21 | A ggplot object that contains scale-location graph 22 | } 23 | \description{ 24 | Plot scale-location (also called spread-location plot) in ggplot. 25 | } 26 | \examples{ 27 | library(MASS) 28 | data(Cars93) 29 | cars_lm <- lm(Price ~ Passengers + Length + RPM, data = Cars93) 30 | gg_scalelocation(cars_lm) 31 | } 32 | -------------------------------------------------------------------------------- /man/plot_all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_all.R 3 | \name{plot_all} 4 | \alias{plot_all} 5 | \title{Plot all given plots in a square matrix form.} 6 | \usage{ 7 | plot_all(plots, ncol = NA, max.per.page = NA) 8 | } 9 | \arguments{ 10 | \item{plots}{a list of plots} 11 | 12 | \item{ncol}{numeric; the number of column that the arranged grid need to be. 13 | defaults to fitting all plots in square matrix} 14 | 15 | \item{max.per.page}{numeric; maximum number of plots allowed in one page.} 16 | } 17 | \value{ 18 | plots in a given list arrangeed using gridExtra 19 | } 20 | \description{ 21 | Plot all given plots in a square matrix form. 22 | } 23 | \examples{ 24 | library(MASS) 25 | data(Cars93) 26 | # a regression with categorical variable 27 | cars_lm <- lm(Price ~ Passengers + Length + RPM + Origin, data = Cars93) 28 | plots <- gg_diagnose(cars_lm, plot.all = FALSE) 29 | names(plots) 30 | selected.plots <- plots[-c(2, 5)] 31 | plot_all(selected.plots) 32 | 33 | } 34 | --------------------------------------------------------------------------------