Skip to content

Commit 7040ad4

Browse files
copy of CRAN version 1.2.3 in selectiveInference-currentCRAN
1 parent a0034d7 commit 7040ad4

36 files changed

+5471
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Package: selectiveInference
2+
Type: Package
3+
Title: Tools for Post-Selection Inference
4+
Version: 1.2.3
5+
Date: 2017-09-18
6+
Author: Ryan Tibshirani, Rob Tibshirani, Jonathan Taylor,
7+
Joshua Loftus, Stephen Reid
8+
Maintainer: Rob Tibshirani <[email protected]>
9+
Depends: glmnet, intervals, survival
10+
Suggests: Rmpfr
11+
Description: New tools for post-selection inference, for use
12+
with forward stepwise regression, least angle regression, the
13+
lasso, and the many means problem. The lasso function implements Gaussian, logistic and Cox survival models.
14+
License: GPL-2
15+
NeedsCompilation: yes
16+
Packaged: 2017-09-19 23:49:11 UTC; tibs
17+
Repository: CRAN
18+
Date/Publication: 2017-09-20 03:14:10 UTC

selectiveInference-currentCRAN/MD5

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
89792835188231f03f117ab143c2fe46 *DESCRIPTION
2+
5b8e448cf043849e190d2b71898eaad9 *NAMESPACE
3+
9c5c032cb17908e6dea15a0b89d649a9 *R/funs.common.R
4+
cf1d1199cf6cacb1d54fce08388d20cc *R/funs.fixed.R
5+
faf5eed09c13d3e80270d82305f0b348 *R/funs.fixedCox.R
6+
25e9f2957b4cbac8b11a283c69533f64 *R/funs.fixedLogit.R
7+
c7af51c32236ef56a6ed0a525f52dce4 *R/funs.fs.R
8+
fc41d0af77330bde0395f438c117c7d8 *R/funs.groupfs.R
9+
632c61c8fc3da59cde6b337f7d4341a4 *R/funs.inf.R
10+
dba7bfb08c9184569d97c14a0575c5a1 *R/funs.lar.R
11+
ed45e9aa5e6383ff9888b35af9b30e9e *R/funs.manymeans.R
12+
bd535e32d32e9cd0e723a5f9f00d9eef *R/funs.max.R
13+
6daca48218e58720c1570784706c199a *R/funs.quadratic.R
14+
d1db3866e82ad6e33baef9da4d994833 *man/estimateSigma.Rd
15+
1747e0899ef985469ae560fb828755cb *man/factorDesign.Rd
16+
1028942deac2fd45aaf2e49d94aa6dac *man/fixedLassoInf.Rd
17+
60e2065f446f1d6dc11c77a5534580bc *man/forwardStop.Rd
18+
2e6f87cd38e1f4b4cb60bfc8299dc1f4 *man/fs.Rd
19+
1483067f07f71b2d996138877e4f48ef *man/fsInf.Rd
20+
7d5ca8ce0ff81cf5f0e87cadffa29229 *man/groupfs.Rd
21+
5ccec019c69b4832438b79830649e730 *man/groupfsInf.Rd
22+
61bdaa3e5ac7bbe02d55f42530edf956 *man/lar.Rd
23+
b25bc2d93c0b266dbec45d82a5d05004 *man/larInf.Rd
24+
4da84515659e7a70fb7375dc2c791b4b *man/manyMeans.Rd
25+
c7c96850986be5e1203cca414a410a32 *man/plot.fs.Rd
26+
3dc4100747d7e72276a75c8e6beba37c *man/plot.lar.Rd
27+
192e0031a10ace23df79a314cf90c648 *man/predict.fs.Rd
28+
588230513bd05fd139c75d45f94a7cd6 *man/predict.groupfs.Rd
29+
0b477548ac30e902eca27163a947e2ca *man/predict.lar.Rd
30+
b275e61a2976d14595dc9dfea646675e *man/scaleGroups.Rd
31+
0c21e5414145f4841c3897c995dad4c2 *man/selectiveInference-internal.Rd
32+
b0bbe4ffe6e958215a85bb15fc43ab01 *man/selectiveInference.Rd
33+
4313aa781953d7f1f6e75383e938e1c7 *src/matrixcomps.c
34+
d7f4c478a9de5716b2da338ae6da2ea5 *src/selinf_init.c
35+
11b2e6c34bc1ed181b407fc658a3b0af *src/truncnorm.c
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export(lar,fs,
2+
larInf,fsInf,
3+
coef.lar,coef.fs,
4+
predict.lar,predict.fs,
5+
print.lar,print.fs,
6+
print.larInf,print.fsInf,
7+
plot.lar,plot.fs,
8+
fixedLassoInf,print.fixedLassoInf,
9+
# fixedLogitLassoInf,print.fixedLogitLassoInf,
10+
# fixedCoxLassoInf,print.fixedCoxLassoInf,
11+
forwardStop,
12+
estimateSigma,
13+
manyMeans,print.manyMeans,
14+
groupfs,groupfsInf,
15+
scaleGroups,factorDesign
16+
)
17+
18+
S3method("coef", "lar")
19+
S3method("predict", "lar")
20+
S3method("print", "lar")
21+
S3method("plot", "lar")
22+
S3method("print", "larInf")
23+
S3method("coef", "fs")
24+
S3method("predict", "fs")
25+
S3method("print", "fs")
26+
S3method("plot", "fs")
27+
S3method("print", "fsInf")
28+
S3method("print", "fixedLassoInf")
29+
S3method("print", "fixedLogitLassoInf")
30+
S3method("print", "fixedCoxLassoInf")
31+
S3method("print", "manyMeans")
32+
S3method("print", "groupfs")
33+
S3method("print", "groupfsInf")
34+
35+
useDynLib("selectiveInference",.registration=TRUE)
36+
import(glmnet)
37+
import(intervals)
38+
import(survival)
39+
importFrom("graphics", abline, axis, matplot)
40+
importFrom("stats", dnorm, lsfit, pexp, pnorm, predict,
41+
qnorm, rnorm, sd, uniroot, dchisq, model.matrix, pchisq)
42+
importFrom("stats", "coef", "df", "lm", "pf")
43+
importFrom("stats", "glm", "residuals", "vcov")
44+
45+
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# Special linear time order function, works only when x
2+
# is a scrambled vector of integers.
3+
4+
Order <- function(x) {
5+
n = length(x)
6+
o = numeric(n)
7+
o[x] = Seq(1,n)
8+
return(o)
9+
}
10+
11+
# Returns a sequence of integers from a to b if a <= b,
12+
# otherwise nothing. You have no idea how important this
13+
# function is...
14+
15+
Seq <- function(a, b, ...) {
16+
if (a<=b) return(seq(a,b,...))
17+
else return(numeric(0))
18+
}
19+
20+
# Returns the sign of x, with Sign(0)=1.
21+
22+
Sign <- function(x) {
23+
return(-1+2*(x>=0))
24+
}
25+
26+
##############################
27+
28+
# Centering and scaling convenience function
29+
30+
standardize <- function(x, y, intercept, normalize) {
31+
x = as.matrix(x)
32+
y = as.numeric(y)
33+
n = nrow(x)
34+
p = ncol(x)
35+
36+
if (intercept) {
37+
bx = colMeans(x)
38+
by = mean(y)
39+
x = scale(x,bx,FALSE)
40+
y = y-mean(y)
41+
} else {
42+
bx = rep(0,p)
43+
by = 0
44+
}
45+
if (normalize) {
46+
sx = sqrt(colSums(x^2))
47+
x = scale(x,FALSE,sx)
48+
} else {
49+
sx = rep(1,p)
50+
}
51+
52+
return(list(x=x,y=y,bx=bx,by=by,sx=sx))
53+
}
54+
55+
##############################
56+
57+
# Interpolation function to get coefficients
58+
59+
coef.interpolate <- function(betas, s, knots, dec=TRUE) {
60+
# Sort the s values
61+
o = order(s,dec=dec)
62+
s = s[o]
63+
64+
k = length(s)
65+
mat = matrix(rep(knots,each=k),nrow=k)
66+
if (dec) b = s >= mat
67+
else b = s <= mat
68+
blo = max.col(b,ties.method="first")
69+
bhi = pmax(blo-1,1)
70+
71+
i = bhi==blo
72+
p = numeric(k)
73+
p[i] = 0
74+
p[!i] = ((s-knots[blo])/(knots[bhi]-knots[blo]))[!i]
75+
76+
beta = t((1-p)*t(betas[,blo,drop=FALSE]) + p*t(betas[,bhi,drop=FALSE]))
77+
colnames(beta) = as.character(round(s,3))
78+
rownames(beta) = NULL
79+
80+
# Return in original order
81+
o = order(o)
82+
return(beta[,o,drop=FALSE])
83+
}
84+
85+
##############################
86+
87+
checkargs.xy <- function(x, y) {
88+
if (missing(x)) stop("x is missing")
89+
if (is.null(x) || !is.matrix(x)) stop("x must be a matrix")
90+
if (missing(y)) stop("y is missing")
91+
if (is.null(y) || !is.numeric(y)) stop("y must be numeric")
92+
if (ncol(x) == 0) stop("There must be at least one predictor [must have ncol(x) > 0]")
93+
if (checkcols(x)) stop("x cannot have duplicate columns")
94+
if (length(y) == 0) stop("There must be at least one data point [must have length(y) > 0]")
95+
if (length(y)!=nrow(x)) stop("Dimensions don't match [length(y) != nrow(x)]")
96+
}
97+
98+
checkargs.misc <- function(sigma=NULL, alpha=NULL, k=NULL,
99+
gridrange=NULL, gridpts=NULL, griddepth=NULL,
100+
mult=NULL, ntimes=NULL,
101+
beta=NULL, lambda=NULL, tol.beta=NULL, tol.kkt=NULL,
102+
bh.q=NULL) {
103+
104+
if (!is.null(sigma) && sigma <= 0) stop("sigma must be > 0")
105+
if (!is.null(lambda) && lambda < 0) stop("lambda must be >= 0")
106+
if (!is.null(alpha) && (alpha <= 0 || alpha >= 1)) stop("alpha must be between 0 and 1")
107+
if (!is.null(k) && length(k) != 1) stop("k must be a single number")
108+
if (!is.null(k) && (k < 1 || k != floor(k))) stop("k must be an integer >= 1")
109+
if (!is.null(gridrange) && (length(gridrange) != 2 || gridrange[1] > gridrange[2]))
110+
stop("gridrange must be an interval of the form c(a,b) with a <= b")
111+
if (!is.null(gridpts) && (gridpts < 20 || gridpts != round(gridpts)))
112+
stop("gridpts must be an integer >= 20")
113+
if (!is.null(griddepth) && (griddepth > 10 || griddepth != round(griddepth)))
114+
stop("griddepth must be an integer <= 10")
115+
if (!is.null(mult) && mult < 0) stop("mult must be >= 0")
116+
if (!is.null(ntimes) && (ntimes <= 0 || ntimes != round(ntimes)))
117+
stop("ntimes must be an integer > 0")
118+
if (!is.null(beta) && sum(beta!=0)==0) stop("Value of lambda too large, beta is zero")
119+
if (!is.null(lambda) && length(lambda) != 1) stop("lambda must be a single number")
120+
if (!is.null(lambda) && lambda < 0) stop("lambda must be >=0")
121+
if (!is.null(tol.beta) && tol.beta <= 0) stop("tol.beta must be > 0")
122+
if (!is.null(tol.kkt) && tol.kkt <= 0) stop("tol.kkt must be > 0")
123+
}
124+
125+
# Make sure that no two columms of A are the same
126+
# (this works with probability one).
127+
128+
checkcols <- function(A) {
129+
b = rnorm(nrow(A))
130+
a = sort(t(A)%*%b)
131+
if (any(diff(a)==0)) return(TRUE)
132+
return(FALSE)
133+
}
134+
135+
estimateSigma <- function(x, y, intercept=TRUE, standardize=TRUE) {
136+
checkargs.xy(x,rep(0,nrow(x)))
137+
if(nrow(x)<10) stop("Number of observations must be at least 10 to run estimateSigma")
138+
cvfit=cv.glmnet(x,y,intercept=intercept,standardize=standardize)
139+
lamhat=cvfit$lambda.min
140+
fit=glmnet(x,y,standardize=standardize)
141+
yhat=predict(fit,x,s=lamhat)
142+
nz=sum(predict(fit,s=lamhat, type="coef")!=0)
143+
sigma=sqrt(sum((y-yhat)^2)/(length(y)-nz-1))
144+
return(list(sigmahat=sigma, df=nz))
145+
}
146+
147+
# Update the QR factorization, after a column has been
148+
# added. Here Q1 is m x n, Q2 is m x k, and R is n x n.
149+
150+
updateQR <- function(Q1,Q2,R,col) {
151+
m = nrow(Q1)
152+
n = ncol(Q1)
153+
k = ncol(Q2)
154+
155+
a = .C("update1",
156+
Q2=as.double(Q2),
157+
w=as.double(t(Q2)%*%col),
158+
m=as.integer(m),
159+
k=as.integer(k),
160+
dup=FALSE,
161+
package="selectiveInference")
162+
163+
Q2 = matrix(a$Q2,nrow=m)
164+
w = c(t(Q1)%*%col,a$w)
165+
166+
# Re-structure: delete a column from Q2, add one to
167+
# Q1, and expand R
168+
Q1 = cbind(Q1,Q2[,1])
169+
Q2 = Q2[,-1,drop=FALSE]
170+
R = rbind(R,rep(0,n))
171+
R = cbind(R,w[Seq(1,n+1)])
172+
173+
return(list(Q1=Q1,Q2=Q2,R=R))
174+
}
175+
176+
# Moore-Penrose pseudo inverse for symmetric matrices
177+
178+
pinv <- function(A, tol=.Machine$double.eps) {
179+
e = eigen(A)
180+
v = Re(e$vec)
181+
d = Re(e$val)
182+
d[d > tol] = 1/d[d > tol]
183+
d[d < tol] = 0
184+
if (length(d)==1) return(v*d*v)
185+
else return(v %*% diag(d) %*% t(v))
186+
}

0 commit comments

Comments
 (0)