-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulationStudy.Rmd
More file actions
141 lines (98 loc) · 3.52 KB
/
SimulationStudy.Rmd
File metadata and controls
141 lines (98 loc) · 3.52 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
title: "Simulation Study for T-ridge"
author: "Shih-Ting Huang, Fang Xie, and Johannes Lederer"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
#### Description
This is an R markdown document provides the simulation study of the method described in
**Tuning-free ridge estimators for high-dimensional generalized linear models**
by Shih-Ting Huang, Fang Xie, and Johannes Lederer.
#### Settings
The settings include some simulation parameters described in the following :
1. num.runs : Number of runs of the test (for averaging).
2. num.obs : Number of observations (n).
3. num.par : Number of parameters (p).
4. k : Magnitude of mutual correlations.
5. Test.case : Test cases for generalized linear models ("gaussian", "poisson", or "binomial").
6. SNR : Signal-to-noise ratio for gaussian test case.
```{r}
num.runs <- 1
num.obs <- 100
num.par <- 300
k <- 0
Test.case <- "gaussian"
SNR <- 10
```
#### Required packages
The required packages for this simulation study contains :
1. glmnet : Applying cross validation for generalized linear models.
2. MASS : Creating samples from multivariate normal distribution.
3. htmlTable : Creating html tables for simulation result.
4. pander : Using specified text elements for output results.
```{r}
library(glmnet)
library(MASS)
library(htmlTable)
library(pander)
```
#### Loading additional functions
Some additional functions are loaded below and the description of each function
can be found in the folder named **Additional functions**.
```{r}
source("./Additional functions/qnorm.R")
source("./Additional functions/MeanFunction.R")
source("./Additional functions/bFunction.R")
source("./Additional functions/MeanPrime.R")
source("./Additional functions/ObjectiveFunction.R")
source("./Additional functions/Gradient.R")
source("./Additional functions/ObjectEdr.R")
source("./Additional functions/GradientEdr.R")
source("./Additional functions/ObjectRidge.R")
source("./Additional functions/GradientRidge.R")
source("./Additional functions/ObjectLs.R")
source("./Additional functions/GradientLs.R")
```
#### Simulation process
The simulation process is performed by two parts :
1. Initialization process.
2. Loop over the number of runs.
Initialization process :
This process initialize the absolute errors that are going to be computed later and basic setup.
```{r}
source("./SimulationProcess/Initialize.R")
```
Loop over the number of runs :
For each loop, we contain the following four steps in order :
1. Data generation.
2. 10-fold cross validation pipeline.
3. T-ridge pipeline.
4. Compute errors.
```{r}
for (run in 1:num.runs){
source("./SimulationProcess/DataGeneration.R")
source("./SimulationProcess/K-foldCV.R")
source("./SimulationProcess/TRidge.R")
source("./SimulationProcess/ComputeErrors.R")
}
```
#### Results and Output
The results are summarized by R dataframe and the output is formatted by HTML table.
Results :
```{r}
source("./SimulationProcess/ResultsOutput.R")
```
Output HTML Table :
```{r}
htmlTable(output,
header = H,
rnames = "Mean relative errors",
rgroup = paste0("Case : ", Test.case),
n.rgroup = c(1),
cgroup = c(pander("$\\frac{||X\\hat{\\beta}_{t-ridge} - X\\beta^{*}||_{2}}{||X\\beta^{*}||_{2}}$"), pander("$\\frac{||\\hat{\\beta}_{t-ridge} - \\beta^{*}||_{2}}{||\\beta^{*}||_{2}}$")),
n.cgroup = c(2,2),
caption=paste0("(n,p,k)=(", num.obs, ",", num.par, ",", k, ")"))
```