## replace the below paths with your actual path to dropbox ## e.g., '/home/kaylea/Dropbox/Apps/Overleaf/WhateverICalledMyProject/figures/' figPath = '../InOverleaf/figures/' ## e.g., '/home/kaylea/Dropbox/Apps/Overleaf/WhateverICalledMyProject/knitr_rdata/' knitrPath = '../InOverleaf/knitr_rdata/' source('lib-00-utils.R') # enables the remember command set.seed(424242) # always! library('texreg') library('ggplot2') magicNumberOne <- rnorm(1, 0, 1) magicNumberOne magicNumberTwo <- rnorm(1, 0, 1) magicNumberTwo Importance <- data.frame(value=rbeta(100,3,6)+0.1, source='Importance') Quality <- data.frame(value=cumsum(rbeta(10,1,4)/10), source='Quality') sampleDF <- rbind(Importance, Quality) head(sampleDF) head(Quality) head(Importance) g <- ggplot(sampleDF, aes(value, color=source)) + geom_density(data=Importance, alpha=0.25, size=1) + stat_ecdf(data=Quality, aes(x=value), geom='step') + theme_classic() + xlab("Time") + ylab("Standard Deviation Units") + theme(axis.ticks.x=element_blank(), axis.text.x=element_blank(), axis.ticks.y=element_blank(), axis.text.y=element_blank(), axis.title.x=element_text(size=8), axis.title.y=element_text(size=8), legend.position="bottom", legend.title=element_blank(), legend.key.size= unit(.1, 'cm'), legend.key.height = unit(.1, 'cm'), legend.margin=margin(0,0,0,0), legend.key.width = unit(.1, 'cm'), legend.text = element_text(size=8)) + annotate("text", size=3, label="Risk", x=.32, y =1.4) + geom_segment(aes(x=.275, y=1.3, xend=.4, yend=1.3), color='black', size=0.13) + geom_segment(aes(x=.275, y=1.33, xend=.275, yend=1.27), color='black', size=0.14) + geom_segment(aes(x=.4, y=1.33, xend=.4, yend=1.27), color='black', size=0.14) g png(paste0(figPath, "simCurve.png"), units = "in", res = 300, width = 3, height = 3) g dev.off() m1 <- lm(Importance ~ Quality, data=sampleDF) summary(m1) m2 <- lm(Importance ~ poly(Quality, degree=2, raw=2), data=sampleDF) summary(m2) con <- textConnection("model.texreg", "w") #remembered sink(con, split=TRUE, type="output") texreg(list(m1,m2), omit.coef = 'factor', stars=NULL, digits=2, custom.model.names=c('M1 Description', 'M2 Description'), #custom.coef.names=c('(Intercept)', 'Quality', 'Quality Squared'), # run without specifying first, just to be sure these are right! use.packages=FALSE, table=FALSE, ci.force = TRUE) sink() close(con);rm(con) m1.coefs <- summary(m1)$coefficients ## for easy reference within the latex document m2.coefs <- summary(m1)$coefficients ## for easy reference within the latex document if (!nosave) { r <- list() remember(magicNumberOne) #put everything you want to have access to inside latex here remember(magicNumberTwo) #put everything you want to have access to inside latex here remember(model.texreg) remember(m1.coefs) remember(m2.coefs) save(r, file=paste0(knitrPath, "main.RData"), version=2) ## this creates the file, and we need to specify the version print("Remembrances complete") }