Skip to content

Commit 4f03c01

Browse files
committed
Removing stub code for ch6; see comment for code path
1 parent 8facbe7 commit 4f03c01

File tree

6 files changed

+21
-80
lines changed

6 files changed

+21
-80
lines changed

.project.url

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/users/pbreheny/projects/4

R/bc-tcga.R

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#' attachData(bcTCGA)
1010
#' cvfit <- cv.glmnet(X, y)
1111
#' Fig2.10(cvfit)
12-
#'
1312
#' @export
1413

1514
Fig2.10 <- function(cvfit, parlist=list(mfrow=c(1,2), mar=c(5,5,5,0.5))) {

R/mfdr-corr.R

+7-25
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,24 @@
1-
#' Reproduce Example 6.2 and Figure 6.3
1+
#' Reproduce Example 6.3 and Figure 6.5
22
#'
3-
#' Reproduces Example 6.2 and Figure 6.3 from the book. If you specify any options, your results may look different.
3+
#' Reproduces Example 6.3 and Figure 6.5 from the book. If you specify any options, your results may look different.
44
#'
55
#' @examples
66
#' \dontrun{
7-
#' out <- Ex6.2()
8-
#' Fig6.3(out)
7+
#' out <- Ex6.3()
8+
#' Fig6.5(out)
99
#' }
1010
#' @export
1111

1212
Ex6.3 <- function() {
13+
# ~/res/lassoFDR/corr/*
1314
stop('Ex6.3 not implemented yet')
14-
15-
# NEED TO ADD
1615
}
1716

1817
#' @rdname Ex6.3
19-
#'
2018
#' @param out Output of `Ex6.3()`
21-
#'
2219
#' @export
2320

2421
Fig6.5 <- function(out) {
25-
26-
## Read in data
27-
df <- array2df(apply(out[,,-1], 2:3, sum), vars=c("lambda", "Type", "Avg"))
28-
S <- apply(out[,,1], 2, sum)
29-
df$mFDR <- df$Avg/S
30-
df$Avg <- df$Avg/dim(out)[1]
31-
df$lam <- factor2num(df$lambda)
32-
df$ll <- log(df$lam)
33-
34-
xlim <- rev(range(df$ll))
35-
p1 <- qplot(ll, Avg, data=df, color=Type, geom="line", xlab=expression(log(lambda)), ylab="False inclusions", xlim=xlim) +
36-
geom_line(size=2) + scale_color_manual(values=pal(2, alpha=0.5)) + theme(legend.position="top")
37-
p2 <- qplot(ll, mFDR, data=df, color=Type, geom="line", xlab=expression(log(lambda)), ylab="False inclusions", xlim=xlim) +
38-
geom_line(size=2) + scale_color_manual(values=pal(2, alpha=0.5)) + theme(legend.position="top")
39-
40-
#subset(df, ll == ll[14])
41-
gridExtra::grid.arrange(p1, p2, widths=c(1,1))
22+
if (missing(out)) stop("You need to run the code in Ex6.3() first and pass it to Fig6.5()")
23+
# /man/Breheny2019/fig/sim-corr.R
4224
}

R/mfdr-ind.R

+2-19
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,15 @@
1010
#' @export
1111

1212
Ex6.2 <- function() {
13+
# ~/res/lassoFDR/uncorr/sim1.R
1314
stop('Ex6.2 not implemented yet')
14-
#subset(df, loglambda == loglambda[20])
1515
}
1616

1717
#' @rdname Ex6.2
18-
#'
1918
#' @param out Output of `Ex6.2()`
20-
#'
2119
#' @export
2220

2321
Fig6.3 <- function(out) {
2422
if (missing(out)) stop("You need to run the code in Ex6.2() first and pass it to Fig6.3()")
25-
26-
out[,,1,4] <- out[,,1,4]*42/60
27-
out[,,2,4] <- out[,,2,4]*540/600
28-
dimnames(out)[[4]][3:4] <- c("Actual", "Estimated")
29-
df <- data.frame(array2df(apply(out[,,,3:4],2:4,mean), vars=c("lambda","p","Type", "Avg")))
30-
df$lambda <- factor2num(df$lambda)
31-
df$loglambda <- log(df$lambda)
32-
df$S <- as.numeric(apply(apply(out[,,,1:3], 1:3, sum), 2:3, mean))
33-
df$FDR <- df$Avg/df$S
34-
35-
p1 <- qplot(loglambda, Avg, data=df, color=Type, geom="line", xlab=expression(log(lambda)), ylab="False inclusions", xlim=c(0.4, -4.2)) +
36-
geom_line(size=2) + scale_color_manual(values=pal(2, alpha=0.5)) + facet_grid(~p, labeller=label_both) + theme(legend.position="top") + theme(panel.background=element_rect(fill = "gray90"))
37-
p2 <- qplot(loglambda, FDR, data=df, color=Type, geom="line", xlab=expression(log(lambda)), ylab="FIR", xlim=c(0.4, -4.2)) +
38-
geom_line(size=2) + scale_color_manual(values=pal(2, alpha=0.5)) + facet_grid(~p, labeller=label_both) + theme(legend.position="none") + theme(panel.background=element_rect(fill = "gray90"))
39-
40-
gridExtra::grid.arrange(p1, p2, heights=c(1.2, 1))
23+
# /man/Breheny2019/fig/sim-ind.R
4124
}

R/mfdr-power.R

+11-29
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
1+
#' Reproduce Figure 6.4
2+
#'
3+
#' Reproduces Example Figure 6.4 from the book. If you specify any options, your results may look different.
4+
#'
5+
#' @examples
6+
#' \dontrun{
7+
#' out <- Ex6.2()
8+
#' Fig6.4(out)
9+
#' }
110
#' @export
211

312
Fig6.4 <- function(out) {
4-
dimnames(out)[[3]][1:2] <- c("Univariate", "LassoFIR")
5-
dimnames(out)[[4]] <- c("Causative (A)", "Correlated (B)", "Noise (C)")
6-
df <- array2df(apply(out, 2:4, mean, na.rm=TRUE), vars=c("p","Method", "Group", "Avg"))
7-
8-
# Subsets / reordering factors
9-
ggdf1 <- subset(df, p==60 & Method != "LassoBIC")
10-
#ggdf2 <- subset(df, p==600 & !(Method %in% c("LassoBIC", "LassoCV")))
11-
ggdf2 <- subset(df, p==600 & Method != "LassoBIC")
12-
ggdf1$Method <- revlevel(relevel(droplevels(ggdf1$Method), 'LassoFIR'))
13-
ggdf2$Method <- revlevel(relevel(droplevels(ggdf2$Method), 'LassoFIR'))
14-
15-
# Plot
16-
p1 <- ggplot(data=ggdf1) + aes(Method, Avg, fill=Group) + geom_bar(stat='identity') +
17-
scale_fill_grey(start=0,end=1) + coord_flip() + theme(panel.background=element_rect(fill = "gray90")) +
18-
facet_grid(p~., labeller=label_both) + theme(legend.position="top", legend.background=element_rect(fill = "gray90"))
19-
p2 <- ggplot(data=ggdf2) + aes(Method, Avg, fill=Group) + geom_bar(stat='identity') +
20-
scale_fill_grey(start=0,end=1) + coord_flip() + theme(panel.background=element_rect(fill = "gray90")) +
21-
facet_grid(p~., labeller=label_both) + theme(legend.position="none")
22-
23-
gridExtra::grid.arrange(p1, p2, heights=c(1.3, 1))
24-
25-
# Summaries
26-
# T1 <- apply(out[,1,,],2:3,mean)
27-
# T1[,3]/apply(T1,1,sum)
28-
# (T1[,2]+T1[,3])/apply(T1,1,sum)
29-
# T2 <- apply(out[,2,,],2:3,mean)
30-
# T2[,3]/apply(T2,1,sum)
31-
# (T2[,2]+T2[,3])/apply(T2,1,sum)
32-
13+
if (missing(out)) stop("You need to run the code in Ex6.2() first and pass it to Fig6.4()")
14+
# /man/Breheny2019/fig/sim-power.R
3315
}

R/utils.R

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
array2df <- function(X,vars=paste("V",1:ncol(df),sep="")) {
2-
df <- cbind(do.call("expand.grid",dimnames(X)),as.numeric(X))
3-
names(df) <- vars
4-
df
5-
}
6-
71
#' Make a log-scale axis
82
#'
93
#' @param side 1=bottom, 2=left, 3=top, 4=right

0 commit comments

Comments
 (0)