-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathsim.many.lo.R
64 lines (55 loc) · 2.42 KB
/
sim.many.lo.R
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
## Many methods: test out conformal intervals across a variety of
## low-dimensional settings
library(conformalInference)
# Set some overall simulation parameters
n = 200; p = 20 # Numbers of observations and features
s = 5 # Number of truly relevant features
n0 = 100 # Number of points at which to make predictions
nrep = 50 # Number of repetitions for a given setting
sigma = 1 # Marginal error standard deviation
bval = 8 # Magnitude of nonzero coefficients
# Define split conformal inference function for the lasso
my.lasso.funs = lasso.funs(nlambda=50)
my.split.lasso.fun = function(x, y, x0) {
conformal.pred.split(x,y,x0,alpha=0.1,verb="\t\t",
train.fun=my.lasso.funs$train,
predict.fun=my.lasso.funs$predict)
}
# Define split conformal inference function for the elastic net
my.elastic.funs = elastic.funs(gamma=0.8,nlambda=50)
my.split.elastic.fun = function(x, y, x0) {
conformal.pred.split(x,y,x0,alpha=0.1,verb="\t\t",
train.fun=my.elastic.funs$train,
predict.fun=my.elastic.funs$predict)
}
# Define split conformal inference function for sparse additive model
my.sam.funs = sam.funs(m=5,nlambda=50,lambda.min.ratio=0.01)
my.split.sam.fun = function(x, y, x0) {
conformal.pred.split(x,y,x0,alpha=0.1,verb="\t\t",
train.fun=my.sam.funs$train,
predict.fun=my.sam.funs$predict)
}
# Define split conformal inference function for random forest
my.rf.funs = rf.funs()
my.split.rf.fun = function(x, y, x0) {
conformal.pred.split(x,y,x0,alpha=0.1,verb="\t\t",
train.fun=my.rf.funs$train,
predict.fun=my.rf.funs$predict)
}
# Define split conformal inference function for forward stepwise
my.step.funs = lars.funs(max.steps=20)
my.split.step.fun = function(x, y, x0) {
conformal.pred.split(x,y,x0,alpha=0.1,verb="\t\t",
train.fun=my.step.funs$train,
predict.fun=my.step.funs$predict)
}
# Now put together a list with our three conformal inference functions
conformal.pred.funs = vector(mode="list",length=5)
conformal.pred.funs = list(my.split.lasso.fun, my.split.elastic.fun,
my.split.sam.fun, my.split.rf.fun, my.split.step.fun)
names(conformal.pred.funs) = c("Lasso","Elastic net","Spam",
"Random forest", "Stepwise")
path = "rds/many.lo."
source("sim.setting.a.R")
source("sim.setting.b.R")
source("sim.setting.c.R")