Skip to content

Instantly share code, notes, and snippets.

@alexchinco
Last active January 21, 2017 14:56
Show Gist options
  • Save alexchinco/eea45a87e7e09a64a55723430e70e22c to your computer and use it in GitHub Desktop.
Save alexchinco/eea45a87e7e09a64a55723430e70e22c to your computer and use it in GitHub Desktop.
Probability that the maximum in-sample correlation is less than a given cutoff value.
## ##########################################################################################################################
## ##########################################################################################################################
## @section: Prep workspace
## ##########################################################################################################################
## ##########################################################################################################################
options(width=200, digits=6, digits.secs=6)
rm(list=ls())
library(plyr)
library(ggplot2)
library(grid)
library(scales)
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{xfrac}\n"
)
)
setTikzDefaults(overwrite = FALSE)
print(options('tikzLatexPackages'))
## ##########################################################################################################################
## ##########################################################################################################################
## @section: simulate data
## ##########################################################################################################################
## ##########################################################################################################################
scl.flt.C <- 0.414
scl.int.S <- 50
scl.int.V <- 50
mat.df.PLOT <- data.frame(S = scl.int.S,
V = 2:scl.int.V,
value = NA
)
for (v in 2:scl.int.V) {
mat.df.PLOT[mat.df.PLOT$V == v, ]$value <- (1 - 2 * pnorm(-scl.flt.C, 0, 1/sqrt(scl.int.S)))^(choose(v, 2))
}
## ##########################################################################################################################
## ##########################################################################################################################
## @section: Plot results
## ##########################################################################################################################
## ##########################################################################################################################
theme_set(theme_bw())
scl.str.RAW_FILE <- 'figure'
scl.str.TEX_FILE <- paste(scl.str.RAW_FILE,'.tex',sep='')
scl.str.PDF_FILE <- paste(scl.str.RAW_FILE,'.pdf',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 = 3, standAlone=TRUE)
obj.gg2.PLOT <- ggplot()
obj.gg2.PLOT <- obj.gg2.PLOT + scale_colour_brewer(palette="Set1")
obj.gg2.PLOT <- obj.gg2.PLOT + geom_path(data = mat.df.PLOT,
aes(x = V,
y = value
),
size = 3.50,
alpha = 0.75
)
obj.gg2.PLOT <- obj.gg2.PLOT + annotate("text",
x = 35.5,
y = 0.90,
size = 5,
label = "Probability that"
)
obj.gg2.PLOT <- obj.gg2.PLOT + annotate("text",
x = 35.3,
y = 0.75,
size = 5,
label = "$\\max |\\hat{\\rho}_{v,v'}| \\leq 0.41$"
)
obj.gg2.PLOT <- obj.gg2.PLOT + annotate("text",
x = 38.00,
y = 0.60,
size = 5,
label = "when $S = 50$."
)
obj.gg2.PLOT <- obj.gg2.PLOT + coord_cartesian(xlim = c(2, 50), ylim = c(0, 1))
obj.gg2.PLOT <- obj.gg2.PLOT + scale_x_continuous(breaks = c(2, 8, 20, 37, 50), labels = c("$V = 2\\phantom{=V}$", "$8$", "$20$", "$37$", "$50$"))
obj.gg2.PLOT <- obj.gg2.PLOT + scale_y_continuous(breaks = c(0, 0.10, 0.50, 0.90, 1.00), labels = c("$0.0$", "$0.1$", "$0.5$", "$0.9$", "$1.0$"))
obj.gg2.PLOT <- obj.gg2.PLOT + theme(plot.margin = unit(c(0.15,0.15,0.15,0.15), "lines"),
axis.title = element_blank(),
axis.text = element_text(size = 14),
plot.title = element_blank(),
panel.grid.minor = element_blank()
)
print(obj.gg2.PLOT)
dev.off()
system(paste('lualatex', file.path(scl.str.TEX_FILE)), ignore.stdout = TRUE)
system(paste('rm ', scl.str.TEX_FILE, 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