Created
January 24, 2016 22:43
-
-
Save alexchinco/024d138648433c644fc9 to your computer and use it in GitHub Desktop.
Create plots for blog post on the characteristic scale of house-price variation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################### | |
########################################################################### | |
## @purpose: Estimate corrected lambda in simulated data. | |
## ------------------------------------------------------------------------ | |
## @author: Alex Chinco | |
## @date: 24-JAN-2016 | |
########################################################################### | |
########################################################################### | |
########################################################################### | |
########################################################################### | |
## @section: Prep workspace | |
########################################################################### | |
########################################################################### | |
options(width=120, digits=6, digits.secs=6) | |
rm(list=ls()) | |
library(foreign) | |
library(grid) | |
library(plyr) | |
library(ggplot2) | |
library(reshape) | |
library(R.matlab) | |
library(lubridate) | |
library(tikzDevice) | |
print(options('tikzLatexPackages')) | |
options(tikzLatexPackages = | |
c("\\usepackage{tikz}\n", | |
"\\usepackage[active,tightpage,psfixbb]{preview}\n", | |
"\\PreviewEnvironment{pgfpicture}\n", | |
"\\setlength\\PreviewBorder{0pt}\n", | |
"\\usepackage{amsmath}\n", | |
"\\usepackage{pxfonts}\n", | |
"\\usepackage{bm}\n", | |
"\\usepackage{xfrac}\n" | |
) | |
) | |
setTikzDefaults(overwrite = FALSE) | |
print(options('tikzLatexPackages')) | |
library(foreach) | |
library(doMC) | |
registerDoMC(2) | |
set.seed(123456) | |
scl.str.DAT_DIR <- "~/Dropbox/research/persistence_and_dispersion/data/" | |
scl.str.FIG_DIR <- "~/Dropbox/research/persistence_and_dispersion/figures/" | |
########################################################################### | |
########################################################################### | |
## @section: Define parameters | |
########################################################################### | |
########################################################################### | |
scl.int.H <- 2^8 | |
vec.int.N <- c(2^2, 2^4, 2^6) | |
scl.int.NUM_N <- length(vec.int.N) | |
vec.flt.SIG_N <- sqrt(seq(0.05, 0.95, by = 0.05)) | |
vec.flt.SIG_H <- sqrt(1 - vec.flt.SIG_N^2) | |
scl.int.NUM_BREAKS <- length(vec.flt.SIG_N) | |
scl.int.NUM_ITER <- 10^3 | |
########################################################################### | |
########################################################################### | |
## @section: Estimate corrected lambda | |
########################################################################### | |
########################################################################### | |
if (TRUE == FALSE) { | |
mat.flt.PLOT <- foreach(g=1:scl.int.NUM_N, .combine = "rbind") %do% { | |
## for (g in 1:scl.int.NUM_N) { | |
mat.flt.OUTTER <- foreach(b=1:scl.int.NUM_BREAKS, .combine = "rbind") %do% { | |
## for (b in 1:scl.int.NUM_BREAKS) { | |
print(paste("N = ", vec.int.N[g], ", ", round(b/scl.int.NUM_BREAKS*100,2), "%: ", round(Sys.time()), sep = "")) | |
mat.flt.INNER <- foreach(i=1:scl.int.NUM_ITER, .combine = "rbind") %dopar% { | |
## for (i in 1:scl.int.NUM_ITER) { | |
mat.df.TEMP <- data.frame(n = 1:vec.int.N[g], mu = rnorm(vec.int.N[g], 0, vec.flt.SIG_N[b])) | |
mat.df.TEMP <- foreach(l=1:(scl.int.H/vec.int.N[g]), .combine = "rbind") %do% { return(mat.df.TEMP) } | |
mat.df.TEMP <- mat.df.TEMP[order(mat.df.TEMP$n), ] | |
mat.df.TEMP$h <- 1:scl.int.H | |
mat.df.TEMP$tet <- rnorm(scl.int.H, 0, vec.flt.SIG_H[b]) | |
mat.df.TEMP$p <- mat.df.TEMP$mu + mat.df.TEMP$tet | |
mat.df.TEMP <- mat.df.TEMP[, c("h", "n", "mu", "tet", "p")] | |
mat.flt.RHS_N <- matrix(rep(0, (vec.int.N[g]/2) * scl.int.H), nrow = scl.int.H) | |
mat.flt.RHS_H <- matrix(rep(0, (scl.int.H/2) * scl.int.H), nrow = scl.int.H) | |
scl.int.L <- (scl.int.H/vec.int.N[g]) | |
for (n in 1:vec.int.N[g]) { | |
vec.int.TEMP <- 1:scl.int.L | |
for (l in 1:(scl.int.L/2)) { | |
vec.int.SAMPLE <- sample(vec.int.TEMP, 2) | |
vec.int.TEMP <- vec.int.TEMP[-which(vec.int.TEMP %in% vec.int.SAMPLE)] | |
mat.flt.RHS_H[(n-1)*scl.int.L + vec.int.SAMPLE[1], (n-1)*scl.int.L/2 + l] <- sqrt(scl.int.H-1)/sqrt(2*2) | |
mat.flt.RHS_H[(n-1)*scl.int.L + vec.int.SAMPLE[2], (n-1)*scl.int.L/2 + l] <- -sqrt(scl.int.H-1)/sqrt(2*2) | |
} | |
} | |
vec.int.TEMP <- 1:vec.int.N[g] | |
for (n in 1:(vec.int.N[g]/2)) { | |
vec.int.SAMPLE <- sample(vec.int.TEMP, 2) | |
vec.int.TEMP <- vec.int.TEMP[-which(vec.int.TEMP %in% vec.int.SAMPLE)] | |
mat.flt.RHS_N[(vec.int.SAMPLE[1]-1)*scl.int.L + 1:scl.int.L, n] <- sqrt(scl.int.H-1)/sqrt(2*2*scl.int.L) | |
mat.flt.RHS_N[(vec.int.SAMPLE[2]-1)*scl.int.L + 1:scl.int.L, n] <- -sqrt(scl.int.H-1)/sqrt(2*2*scl.int.L) | |
} | |
obj.lm.REG <- summary(lm(mat.df.TEMP$p ~ 1 + mat.flt.RHS_H + mat.flt.RHS_N)) | |
vec.flt.COEF <- obj.lm.REG$coef[-c(1),1] | |
scl.flt.VAR_H_TIL <- sum(head(vec.flt.COEF, scl.int.H/2)^2) | |
scl.flt.VAR_N_TIL <- sum(tail(vec.flt.COEF, vec.int.N[g]/2)^2) - scl.flt.VAR_H_TIL/(scl.int.H/vec.int.N[g]) | |
return(c(scl.flt.VAR_N_TIL, scl.flt.VAR_H_TIL)) | |
} | |
return(c(vec.int.N[g], vec.flt.SIG_N[b]^2, apply(mat.flt.INNER, 2, mean))) | |
} | |
return(mat.flt.OUTTER) | |
} | |
mat.df.PLOT <- data.frame(mat.flt.PLOT) | |
names(mat.df.PLOT) <- c("N", "varN", "varNtil", "varHtil") | |
mat.df.PLOT$ratStar <- mat.df.PLOT$varN | |
mat.df.PLOT$rat2Sample <- mat.df.PLOT$varNtil/(mat.df.PLOT$varNtil + mat.df.PLOT$varHtil) | |
save(mat.df.PLOT, file = paste(scl.str.DAT_DIR, "data--corrected-lambda-estimate--simulated-data--24jan2016.Rdata", sep = "")) | |
} | |
load(paste(scl.str.DAT_DIR, "data--corrected-lambda-estimate--simulated-data--24jan2016.Rdata", sep = "")) | |
########################################################################### | |
########################################################################### | |
## @section: Plot results | |
########################################################################### | |
########################################################################### | |
mat.df.PLOT1 <- mat.df.PLOT[, c("ratStar", "N", "rat2Sample")] | |
names(mat.df.PLOT1) <- c("ratStar", "variable", "value") | |
mat.df.PLOT1$variable <- paste("$N = ", mat.df.PLOT1$variable, "$", sep = "") | |
mat.df.PLOT1$variable <- factor(mat.df.PLOT1$variable, levels = c("$N = 4$", "$N = 16$", "$N = 64$")) | |
mat.df.PLOT2 <- mat.df.PLOT[, c("ratStar", "N", "rat2Sample")] | |
names(mat.df.PLOT2) <- c("ratStar", "variable", "value") | |
mat.df.PLOT2$value <- mat.df.PLOT2$value/mat.df.PLOT2$ratStar - 1 | |
mat.df.PLOT2$variable <- paste("$N = ", mat.df.PLOT2$variable, "$", sep = "") | |
mat.df.PLOT2$variable <- factor(mat.df.PLOT2$variable, levels = c("$N = 4$", "$N = 16$", "$N = 64$")) | |
obj.vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y) | |
theme_set(theme_bw()) | |
scl.str.RAW_FILE <- 'plot--corrected-lambda-estimate--simulated-data--24jan2016' | |
scl.str.TEX_FILE <- paste(scl.str.RAW_FILE,'.tex',sep='') | |
scl.str.PDF_FILE <- paste(scl.str.RAW_FILE,'.pdf',sep='') | |
scl.str.PNG_FILE <- paste(scl.str.RAW_FILE,'.png',sep='') | |
scl.str.AUX_FILE <- paste(scl.str.RAW_FILE,'.aux',sep='') | |
scl.str.LOG_FILE <- paste(scl.str.RAW_FILE,'.log',sep='') | |
tikz(file = scl.str.TEX_FILE, height = 2, width = 7, standAlone=TRUE) | |
## Left panel | |
obj.gg2.PLOT1 <- ggplot(data = mat.df.PLOT1) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + scale_colour_brewer(palette = "Set1") | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + annotate("segment", | |
x = 0.05, | |
xend = 0.95, | |
y = 0.05, | |
yend = 0.95, | |
colour = "black", | |
linetype = 4, | |
size = 1 | |
) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + geom_path(aes(x = ratStar, | |
y = value, | |
group = variable, | |
colour = variable | |
), | |
size = 2, | |
alpha = 0.75 | |
) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + coord_cartesian(xlim = c(0.00, 1.00), ylim = c(0.02, 0.98)) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + scale_x_continuous(breaks = c(0.05, 0.20, 0.50, 0.80, 0.95)) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + scale_y_continuous(breaks = c(0.05, 0.20, 0.50, 0.80, 0.95)) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + xlab("$\\lambda = \\sfrac{\\sigma_N^2}{(\\sigma_N^2 + \\sigma_H^2)}$") | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + ylab('$\\lambda^{\\scriptscriptstyle \\text{2-Sample}}$') | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + theme(plot.margin = unit(c(0,0.15,0.15,0.15), "lines"), | |
axis.text = element_text(size = 10), | |
axis.title = element_text(size = 10), | |
plot.title = element_blank(), | |
panel.grid.minor = element_blank(), | |
legend.position = "none" | |
) | |
## Right panel | |
obj.gg2.PLOT2 <- ggplot(data = mat.df.PLOT2) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + scale_colour_brewer(palette = "Set1") | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + annotate("segment", | |
x = 0.05, | |
xend = 0.95, | |
y = 0.00, | |
yend = 0.00, | |
colour = "black", | |
linetype = 4, | |
size = 1 | |
) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + geom_path(aes(x = ratStar, | |
y = value, | |
group = variable, | |
colour = variable | |
), | |
size = 2, | |
alpha = 0.75 | |
) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + xlab("$\\lambda = \\sfrac{\\sigma_N^2}{(\\sigma_N^2 + \\sigma_H^2)}$") | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + ylab('$(\\lambda^{\\scriptscriptstyle \\text{2-Sample}} - \\lambda)/\\lambda$') | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + labs(colour = "") | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + coord_cartesian(xlim = c(0.00, 1.00), ylim = c(-0.25,2.50)) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + scale_x_continuous(breaks = c(0.05, 0.20, 0.50, 0.80, 0.95)) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + scale_y_continuous(breaks = c(0, 0.75, 1.5, 2.25)) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + theme(plot.margin = unit(c(0,0.15,0.15,0.15), "lines"), | |
axis.text = element_text(size = 10), | |
axis.title = element_text(size = 10), | |
plot.title = element_blank(), | |
panel.grid.minor = element_blank(), | |
legend.position = c(0.75, 0.75), | |
legend.background = element_blank() | |
) | |
## Generate output | |
pushViewport(viewport(layout = grid.layout(5, 2))) | |
grid.text('Corrected Estimates of Neighborhood-Level Variance', vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2), vjust = 0.20, gp = gpar(fontsize=15)) | |
print(obj.gg2.PLOT1, vp = obj.vplayout(2:5,1)) | |
print(obj.gg2.PLOT2, vp = obj.vplayout(2:5,2)) | |
dev.off() | |
system(paste('lualatex', file.path(scl.str.TEX_FILE)), ignore.stdout = TRUE) | |
system(paste('rm ', scl.str.TEX_FILE, sep = '')) | |
system(paste('mv ', scl.str.PDF_FILE, ' ', scl.str.FIG_DIR, sep = '')) | |
system(paste('rm ', scl.str.AUX_FILE, sep = '')) | |
system(paste('rm ', scl.str.LOG_FILE, sep = '')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################### | |
########################################################################### | |
## @purpose: Estimate naive lambda in simulated data. | |
## ------------------------------------------------------------------------ | |
## @author: Alex Chinco | |
## @date: 22-JAN-2016 | |
########################################################################### | |
########################################################################### | |
########################################################################### | |
########################################################################### | |
## @section: Prep workspace | |
########################################################################### | |
########################################################################### | |
options(width=120, digits=6, digits.secs=6) | |
rm(list=ls()) | |
library(foreign) | |
library(grid) | |
library(plyr) | |
library(ggplot2) | |
library(reshape) | |
library(R.matlab) | |
library(lubridate) | |
library(tikzDevice) | |
print(options('tikzLatexPackages')) | |
options(tikzLatexPackages = | |
c("\\usepackage{tikz}\n", | |
"\\usepackage[active,tightpage,psfixbb]{preview}\n", | |
"\\PreviewEnvironment{pgfpicture}\n", | |
"\\setlength\\PreviewBorder{0pt}\n", | |
"\\usepackage{amsmath}\n", | |
"\\usepackage{pxfonts}\n", | |
"\\usepackage{bm}\n", | |
"\\usepackage{xfrac}\n" | |
) | |
) | |
setTikzDefaults(overwrite = FALSE) | |
print(options('tikzLatexPackages')) | |
library(foreach) | |
library(doMC) | |
registerDoMC(2) | |
set.seed(123456) | |
scl.str.DAT_DIR <- "~/Dropbox/research/persistence_and_dispersion/data/" | |
scl.str.FIG_DIR <- "~/Dropbox/research/persistence_and_dispersion/figures/" | |
########################################################################### | |
########################################################################### | |
## @section: Define parameters | |
########################################################################### | |
########################################################################### | |
scl.int.H <- 2^8 | |
vec.int.N <- c(2^2, 2^4, 2^6) | |
scl.int.NUM_N <- length(vec.int.N) | |
vec.flt.SIG_TET <- sqrt(seq(0.05, 0.95, by = 0.05)) | |
vec.flt.SIG_EP <- sqrt(1 - vec.flt.SIG_TET^2) | |
scl.int.NUM_BREAKS <- length(vec.flt.SIG_TET) | |
scl.int.NUM_ITER <- 10^3 | |
########################################################################### | |
########################################################################### | |
## @section: Estimate characteristic scale | |
########################################################################### | |
########################################################################### | |
if (TRUE == FALSE) { | |
mat.flt.PLOT <- foreach(g=1:scl.int.NUM_N, .combine = "rbind") %do% { | |
## for (g in 1:scl.int.NUM_N) { | |
mat.flt.OUTTER <- foreach(b=1:scl.int.NUM_BREAKS, .combine = "rbind") %do% { | |
## for (b in 1:scl.int.NUM_BREAKS) { | |
print(paste("N = ", vec.int.N[g], ", ", round(b/scl.int.NUM_BREAKS*100,2), "%: ", round(Sys.time()), sep = "")) | |
mat.flt.INNER <- foreach(i=1:scl.int.NUM_ITER, .combine = "rbind") %dopar% { | |
## for (i in 1:scl.int.NUM_ITER) { | |
mat.df.TEMP <- data.frame(n = 1:vec.int.N[g], tet = rnorm(vec.int.N[g], 0, vec.flt.SIG_TET[b])) | |
mat.df.TEMP <- foreach(l=1:(scl.int.H/vec.int.N[g]), .combine = "rbind") %do% { return(mat.df.TEMP) } | |
mat.df.TEMP <- mat.df.TEMP[order(mat.df.TEMP$n), ] | |
mat.df.TEMP$l <- rep(1:(scl.int.H/vec.int.N[g]), vec.int.N[g]) | |
mat.df.TEMP$ep <- rnorm(scl.int.H, 0, vec.flt.SIG_EP[b]) | |
mat.df.TEMP$p <- mat.df.TEMP$tet + mat.df.TEMP$ep | |
mat.df.TEMP <- mat.df.TEMP[, c("l", "n", "tet", "ep", "p")] | |
mat.df.NAIVE <- ddply(mat.df.TEMP, c("n"), function(X)mean(X$p)) | |
names(mat.df.NAIVE) <- c("n", "pBar") | |
scl.flt.VAR_TET <- (vec.int.N[g]/(vec.int.N[g] - 1)) * var(mat.df.NAIVE$pBar) | |
scl.flt.VAR_P <- (scl.int.H/(scl.int.H - 1)) * var(mat.df.TEMP$p) | |
return(c(scl.flt.VAR_TET, scl.flt.VAR_P)) | |
} | |
return(c(vec.int.N[g], vec.flt.SIG_TET[b]^2, apply(mat.flt.INNER, 2, mean))) | |
} | |
return(mat.flt.OUTTER) | |
} | |
mat.df.PLOT <- data.frame(mat.flt.PLOT) | |
names(mat.df.PLOT) <- c("N", "varTetStar", "varTet", "varP") | |
mat.df.PLOT$ratStar <- mat.df.PLOT$varTetStar | |
mat.df.PLOT$ratNaive <- mat.df.PLOT$varTet/mat.df.PLOT$varP | |
save(mat.df.PLOT, file = paste(scl.str.DAT_DIR, "data--naive-lambda-estimate--simulated-data--22jan2016.Rdata", sep = "")) | |
} | |
load(paste(scl.str.DAT_DIR, "data--naive-lambda-estimate--simulated-data--22jan2016.Rdata", sep = "")) | |
########################################################################### | |
########################################################################### | |
## @section: Plot results | |
########################################################################### | |
########################################################################### | |
mat.df.PLOT1 <- mat.df.PLOT[, c("ratStar", "N", "ratNaive")] | |
names(mat.df.PLOT1) <- c("ratStar", "variable", "value") | |
mat.df.PLOT1$variable <- paste("$N = ", mat.df.PLOT1$variable, "$", sep = "") | |
mat.df.PLOT1$variable <- factor(mat.df.PLOT1$variable, levels = c("$N = 4$", "$N = 16$", "$N = 64$")) | |
mat.df.PLOT2 <- mat.df.PLOT[, c("ratStar", "N", "ratNaive")] | |
names(mat.df.PLOT2) <- c("ratStar", "variable", "value") | |
mat.df.PLOT2$value <- mat.df.PLOT2$value/mat.df.PLOT2$ratStar - 1 | |
mat.df.PLOT2$variable <- paste("$N = ", mat.df.PLOT2$variable, "$", sep = "") | |
mat.df.PLOT2$variable <- factor(mat.df.PLOT2$variable, levels = c("$N = 4$", "$N = 16$", "$N = 64$")) | |
obj.vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y) | |
theme_set(theme_bw()) | |
scl.str.RAW_FILE <- 'plot--naive-lambda-estimate--simulated-data--22jan2016' | |
scl.str.TEX_FILE <- paste(scl.str.RAW_FILE,'.tex',sep='') | |
scl.str.PDF_FILE <- paste(scl.str.RAW_FILE,'.pdf',sep='') | |
scl.str.PNG_FILE <- paste(scl.str.RAW_FILE,'.png',sep='') | |
scl.str.AUX_FILE <- paste(scl.str.RAW_FILE,'.aux',sep='') | |
scl.str.LOG_FILE <- paste(scl.str.RAW_FILE,'.log',sep='') | |
tikz(file = scl.str.TEX_FILE, height = 2, width = 7, standAlone=TRUE) | |
## Left panel | |
obj.gg2.PLOT1 <- ggplot(data = mat.df.PLOT1) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + scale_colour_brewer(palette = "Set1") | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + annotate("segment", | |
x = 0.05, | |
xend = 0.95, | |
y = 0.05, | |
yend = 0.95, | |
colour = "black", | |
linetype = 4, | |
size = 1 | |
) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + geom_path(aes(x = ratStar, | |
y = value, | |
group = variable, | |
colour = variable | |
), | |
size = 2, | |
alpha = 0.75 | |
) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + coord_cartesian(xlim = c(0.00, 1.00), ylim = c(0.02, 0.98)) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + scale_x_continuous(breaks = c(0.05, 0.20, 0.50, 0.80, 0.95)) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + scale_y_continuous(breaks = c(0.05, 0.20, 0.50, 0.80, 0.95)) | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + xlab("$\\lambda = \\sfrac{\\sigma_N^2}{(\\sigma_N^2 + \\sigma_H^2)}$") | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + ylab('$\\lambda^{\\scriptscriptstyle \\text{Na\\"{i}ve}}$') | |
obj.gg2.PLOT1 <- obj.gg2.PLOT1 + theme(plot.margin = unit(c(0,0.15,0.15,0.15), "lines"), | |
axis.text = element_text(size = 10), | |
axis.title = element_text(size = 10), | |
plot.title = element_blank(), | |
panel.grid.minor = element_blank(), | |
legend.position = "none" | |
) | |
## Right panel | |
obj.gg2.PLOT2 <- ggplot(data = mat.df.PLOT2) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + scale_colour_brewer(palette = "Set1") | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + annotate("segment", | |
x = 0.05, | |
xend = 0.95, | |
y = 0.00, | |
yend = 0.00, | |
colour = "black", | |
linetype = 4, | |
size = 1 | |
) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + geom_path(aes(x = ratStar, | |
y = value, | |
group = variable, | |
colour = variable | |
), | |
size = 2, | |
alpha = 0.75 | |
) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + xlab("$\\lambda = \\sfrac{\\sigma_N^2}{(\\sigma_N^2 + \\sigma_H^2)}$") | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + ylab('$(\\lambda^{\\scriptscriptstyle \\text{Na\\"{i}ve}} - \\lambda)/\\lambda$') | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + labs(colour = "") | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + coord_cartesian(xlim = c(0.00, 1.00), ylim = c(-0.25,2.50)) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + scale_x_continuous(breaks = c(0.05, 0.20, 0.50, 0.80, 0.95)) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + scale_y_continuous(breaks = c(0, 0.75, 1.5, 2.25)) | |
obj.gg2.PLOT2 <- obj.gg2.PLOT2 + theme(plot.margin = unit(c(0,0.15,0.15,0.15), "lines"), | |
axis.text = element_text(size = 10), | |
axis.title = element_text(size = 10), | |
plot.title = element_blank(), | |
panel.grid.minor = element_blank(), | |
legend.position = c(0.75, 0.75), | |
legend.background = element_blank() | |
) | |
## Generate output | |
pushViewport(viewport(layout = grid.layout(5, 2))) | |
grid.text('Bias in $\\text{Na\\"{i}ve}$ Estimates of Neighborhood-Level Variance', vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2), vjust = 0.20, gp = gpar(fontsize=15)) | |
print(obj.gg2.PLOT1, vp = obj.vplayout(2:5,1)) | |
print(obj.gg2.PLOT2, vp = obj.vplayout(2:5,2)) | |
dev.off() | |
system(paste('lualatex', file.path(scl.str.TEX_FILE)), ignore.stdout = TRUE) | |
system(paste('rm ', scl.str.TEX_FILE, sep = '')) | |
system(paste('mv ', scl.str.PDF_FILE, ' ', scl.str.FIG_DIR, sep = '')) | |
system(paste('rm ', scl.str.AUX_FILE, sep = '')) | |
system(paste('rm ', scl.str.LOG_FILE, sep = '')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment