-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
90 lines (65 loc) · 2.96 KB
/
README.Rmd
File metadata and controls
90 lines (65 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
title: "statr"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
[](https://travis-ci.org/MGallow/statr)
[](https://cran.r-project.org/package=statr)
## Overview
`statr` is a personal R package that I have created for organizational/convenience purposes. This project is purely experimental! A (possibly incomplete) list of functions contained in the package can be found below:
* `tidy()` tidy's R package code and updates documentation
* `CVsplit()` splits data objects into training and testing sets
* `data_gen()` generates data for linear regression settings
* `dense()` generates dense matrices
* `denseQR()` generates dense matrices via spectral decomposition
* `tridiag()` generates tri-diagonal matrices
* `derivative()` approximates the derivative for a given function
* `diagnostic()` creates diagnostic plots using ggplot (residual and QQ)
* `dsearch()` is a dichotomous search algorithm for minimizing a univariate function
* `bsearch()` is a bi-section search algorithm for minimizing a univariate function
* `LASSO()` calculates lasso regression coefficient with optimal tuning
* `RIDGE()` calculates ridge regression coefficient with optimal tuning
* `scatter()` creates a scatterplot using ggplot
See [vignette](https://mgallow.github.io/statr/) or [manual](https://github.com/MGallow/statr/blob/master/statr.pdf).
## Installation
The easiest way to install is from the development version from Github:
```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("MGallow/statr")
```
If there are any issues/bugs, please let me know: [github](https://github.com/MGallow/statr/issues). You can also contact me via my [website](https://mgallow.github.io/). Contributions are welcome!
## Usage
```{r, message = FALSE}
library(statr)
library(magrittr)
# we will use the iris data set
X = dplyr::select(iris, -c(Species, Sepal.Length)) %>% as.matrix
y = dplyr::select(iris, Sepal.Length) %>% as.matrix
y_class = ifelse(dplyr::select(iris, Species) == "setosa", 1, 0)
# let us split the data for testing and training
CV = CVsplit(X, y)
# we can do some exploratory analysis
# plot Sepal.Length v Sepal.Width
iris %>% scatter(Sepal.Length, Sepal.Width)
# plot diagnostic plots
iris %>% diagnostic(Sepal.Length, Sepal.Width)
# use the training data to fit ridge regression
RIDGE(CV$X.train, CV$Y.train)
# or lasso regression
statr::LASSO(CV$X.train, CV$Y.train)
# we can also generate our own data
data = data_gen(p = 10, r = 5, n = 100)
CV = CVsplit(data$X, data$Y)
# and again fit a ridge regression
statr::RIDGE(CV$X.train, CV$Y.train)
# we can also generate random matrices with may be useful
# for other applications
# tridiagonal matrices
tridiag(p = 5)$Omega %>% round(5)
# dense matrices
dense(p = 5)$Omega %>% round(5)
# compound symmetric matrices
compound(p = 5)$Omega %>% round(5)
```