diff --git a/.RData b/.RData new file mode 100644 index 0000000..452a61d Binary files /dev/null and b/.RData differ diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 0000000..0ad4449 --- /dev/null +++ b/.Rhistory @@ -0,0 +1,292 @@ +df = data.frame("x" = c(1), "y" =c(2)) +df +linearmodel = lm(y ~ x, data = df) +linearmodel +dunif(x, min = 0, max = 1, log = FALSE) +matrix(0, 1, 1000) +matrix(0, 1, 1000) +dunif(x, min = 0, max = 1, log = FALSE) +1000) +dunif(x, min = 0, max = 1, log = FALSE) +dunif(x, min = 0, max = 1, log = FALSE) +x=matrix(0, 1, 1000) +dunif(x, min = 0, max = 1, log = FALSE) +x=dunif(x, min = 0, max = 1, log = FALSE) +x +x=punif(q, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE) +x=punif(x, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE) +x +u <- runif(1000) +u +u <- runif(x) +u +u <-runif(x, min = 0, max = 1) +u +clear +u <- runif(1000) +u +attributes(u) +summarize(u) +describe.u +describe(u) +x=matrix(0,1000) +x +describe(u) +describe.vector(u) +describe.matrix(u) +str(u) +typeof(u) +typeof(u) +u +typeof(u) +bidders1 <- u[1:500] +bidders1 = u[1:500] +u <- runif(x) +x=matrix(0,1000) +u <- runif(x) +bidders1 <- u[1:500] +bidders1 +x=matrix(0,1000) +u <- runif(x) +bidders1 <- u[1:500] +dim(bidders1) <- c(125,4) +bidders1` +x=matrix(0,1000) +u <- runif(x) +bidders1 <- u[1:500] +dim(bidders1) <- c(125,4) +bidders1 +dim(bids) <- c(125,4) +dim(bids1) <- c(125,4) +bidders <- runif(matrix(0,1000)) +bids1 <- (3/4)*u[1:500] +dim(bids1) <- c(125,4) +bids1 +bidders <- runif(matrix(0,1000)) +bids1 <- (3/4)*u[1:500] +dim(bids1) <- c(125,4) +bids2 <- (4/5)*u[501:1000] +dim(bids2) <- c(100,5) +bids2 +# library(TTR) +# djia = getYahooData("^DJI", start=20060420, end=20160420, freq="daily") +library(xts) +djiar = diff(log(djia$Close))[-1] # approximate returns +plot(djiar, main="DJIA Returns", type="n") +lines(djiar) +library(TTR) +djia = getYahooData("^DJI", start=20060420, end=20160420, freq="daily") +library(xts) +djiar = diff(log(djia$Close))[-1] # approximate returns +plot(djiar, main="DJIA Returns", type="n") +lines(djiar) +library(TTR) +djiar = getYahooData("^DJI", start=20060420, end=20160420, freq="daily") +library(xts) +djiar = diff(log(djia$Close))[-1] # approximate returns +plot(djiar, main="DJIA Returns", type="n") +lines(djiar) +install.packages("astsa") +library(astsa) +.First <- function(){library(astsa)} +1:5 +seq(1, 10, by=2) +x=c(1:20); y=c(1:5); x*y +ls() +ls(pattern=2) +ls(pattern=bid) +ls(pattern="bid") +ls(pattern=.4020) +ls(pattern=.402) +ls() +ls(pattern=u) +ls(pattern="u") +help(read.table) +x = 1:3; y = 4:6 +(u = c(x, y)) # an R vector +(u1 = cbind(x, y)) +(u1 = cbind(t(x), t(y)) +(u1 = cbind(t(x), t(y)) +library(TTR) +djiar = getYahooData("^DJI", start=20060420, end=20160420, freq="daily") +library(xts) +djiar = diff(log(djia$Close))[-1] # approximate returns +plot(djiar, main="DJIA Returns", type="n") +lines(djiar) +library(tidyverse) +library(readr) +library(cubature) +setwd("C:/Users/Joe/github/empirical-methods") +dt <- read.delim("ProblemSets/pset1/bids1.csv") +dt <- rbind(2.9679,dt) # first observation was read as a column name, so put it back as an observation +names(dt)<- "bids" +mean(dt$bids) +X <- dt$bids +I <- 1:300 # index vector +H <- seq(from=.01, to=.3, by=.001) # bandwidth vector +# you need full sample density estimate to do CV +epan <- density(dt$bids, kernel= "epanechnikov", bw = "SJ", adjust = 1) +# test on X[i] +y_j <- function(j) density(dt$bids, kernel= "epanechnikov", bw = "SJ", adjust = 1) +yhatj <- function(i,j) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw="SJ")$y +MSEi <- function(i) (y_j(j)- yhatj(i,j))^2 +MSEhat <- sum(sapply(I, MSEi)) +y_j <- function(j) density(dt$bids, kernel= "epanechnikov", bw = "SJ", adjust = 1) +yhatj <- function(i,j) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw="SJ")$y +MSEi <- function(i) (y_j(j)- yhatj(i,j))^2 +MSEhat <- sum(sapply(I, MSEi)) +J <- I # another index vector +MSEhat <- sum(mapply(I,J, FUN=MSEi)) +y_j <- function(j) density(dt$bids, kernel= "epanechnikov", bw = "SJ", adjust = 1) +yhatj <- function(i,j) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw="SJ")$y +MSEi <- function(i,j) (y_j(j)- yhatj(i,j))^2 +MSEhat <- sum(mapply(I,J, FUN=MSEi)) +y_j <- function(j) density(dt$bids, kernel= "epanechnikov", bw = "SJ", adjust = 1)$y +yhatj <- function(i,j) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw="SJ")$y +MSEi <- function(i,j) (y_j(j)- yhatj(i,j))^2 +MSEhat <- sum(mapply(I,J, FUN=MSEi)) +MSEi(1) +MSEi(i=1,j=1) +y_j(1) +?density +y_j(0) +# test on X[i] +y_j <- function(j) density(dt$bids, n=1, kernel= "epanechnikov", bw = "SJ", adjust = 1)$y +yhatj <- function(i,j) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw="SJ")$y +MSEi <- function(i,j) (y_j(j)- yhatj(i,j))^2 +MSEhat <- sum(mapply(I,J, FUN=MSEi)) +y_j(1) +y_j(2) +y_j(0) +y_j(-1) +y_j <- function(j) density(dt$bids,from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw = "SJ", adjust = 1)$y +yhatj <- function(i,j) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw="SJ")$y +MSEi <- function(i,j) (y_j(j)- yhatj(i,j))^2 +MSEhat <- sum(mapply(I,J, FUN=MSEi)) +y_j(1) +y_j(10) +y_j(100) +epan <- density(dt$bids, kernel= "epanechnikov", bw = "SJ", adjust = 1) +epan(1) +epan(1)$y +y_j <- function(j) density(X,from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw = "SJ", adjust = 1)$y +yhatj <- function(i,j) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw="SJ")$y +MSEi_summand <- function(i,j) (y_j(j)- yhatj(i,j))^2 +MSEi_summand(1) +MSEi_summand(i=1,j=1) +MSEi_summand(i=1,j=2) +MSEi_summand(i=1,j=3) +MSEi_summand(i=1,j=4) +MSEi_summand(i=1,j=5) +?Vectorize +MSEi <- sum(Vectorize(MSEi_summand)) +MSEi <- sum(Vectorize(FUN=MSEi_summand)) +MSEi <- Vectorize(FUN=MSEi_summand) +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi_vec(i,J) +?rep +i_vec <- rep(1, time=300) +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi_vec(i_vec,J) +y_j <- function(j) density(X,from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw = "SJ", adjust = 1)$y +yhatj <- function(i,j,h) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw=h)$y +MSEi_summand <- function(i,j,h) (y_j(j)- yhatj(i,j,h))^2 +h_vec <- rep(.1, time=300) +i_vec <- rep(1, time=300) +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi <- sum(MSEi_vec) +MSEhat <- sum(mapply(I,J, FUN=MSEi)) +y_j <- function(j) density(X,from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw = "SJ", adjust = 1)$y +yhatj <- function(i,j,h) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw=h)$y +MSEi_summand <- function(i,j,h) (y_j(j)- yhatj(i,j,h))^2 +h_vec <- rep(.1, time=300) +i_vec <- rep(1, time=300) +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi <- sum(MSEi_vec) +epan <- density(dt$bids, kernel= "epanechnikov", bw = "SJ", adjust = 1) +# test on X[i] +y_j <- function(j) density(X,from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw = "SJ", adjust = 1)$y +yhatj <- function(i,j,h) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw=h)$y +MSEi_summand <- function(i,j,h) (y_j(j)- yhatj(i,j,h))^2 +h_vec <- rep(.1, time=300) +i_vec <- rep(1, time=300) +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi_vec(i_vec,J,h_vec) +MSEi <- sum(MSEi_vec) +MSEi <- sum(MSEi_vec(i_vec,h_vec,J)) +MSEi <- sum(MSEi_vec(i_vec,J,h_vec)) +MSEi +h_vec <- rep(.2, time=300) +i_vec <- rep(1, time=300) +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi <- sum(MSEi_vec(i_vec,J,h_vec)) +MSEi +h_vec <- rep(.01, time=300) +i_vec <- rep(1, time=300) +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi <- sum(MSEi_vec(i_vec,J,h_vec)) +MSEi +h_vec <- rep(.5, time=300) +i_vec <- rep(1, time=300) +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi <- sum(MSEi_vec(i_vec,J,h_vec)) +MSEi +MSEhat <- function(h){ +h_vector <- rep.int(h, 300) +i_vector <- rep.int(i, 300) +return(sum(mapply(i_vector, J, h_vector, FUN=MSEi))) +} +MSEhat <- function(h){ +h_vector <- rep.int(h, 300) +i_vector <- rep.int(i, 300) +return(MSEi(i_vector, J, h_vector, FUN=MSEi)) +} +MSEhat(.1) +# you need full sample density estimate to do CV +epan <- density(dt$bids, kernel= "epanechnikov", bw = "SJ", adjust = 1) +# test on X[i] +y_j <- function(j) density(X,from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw = "SJ", adjust = 1)$y +yhatj <- function(i,j,h) density(X[-i],from=X[j],to=X[j],n=1, kernel= "epanechnikov", bw=h)$y +MSEi_summand <- function(i,j,h) (y_j(j)- yhatj(i,j,h))^2 +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi <- function(i,h){ +i_vec <- rep(1, time=300) +h_vec <- rep(.5, time=300) +MSEi_vec(i_vec, J, h_vec, FUN=MSEi_vec) +} +MSEi(1,1,) +MSEi(1,1) +MSEi_vec <- Vectorize(FUN=MSEi_summand) +MSEi <- function(i,h){ +i_vec <- rep(1, time=300) +h_vec <- rep(.5, time=300) +return(MSEi_vec(i_vec, J, h_vec)) +} +MSEi(1,1) +MSEhat_i <- function(I) { +h_vec <- rep(.5, time=300) +return(sapply(I,h_vec,FUN=MSEi)) +} +MSEhat_i <- function(h) { +h_vec <- rep(.5, time=300) +return(sapply(I,h_vec,FUN=MSEi)) +} +MSEhat_i(.1) +MSEhat_i(.1) +MSEhat_i(.1) +MSEi(1,.1) +MSEhat_i <- function(h) { +h_vec <- rep(h, time=300) +return(sapply(I,h_vec,FUN=MSEi)) +} +MSEhat_i(.1) +MSEi <- function(i,h){ +i_vec <- rep(i, time=300) +h_vec <- rep(h, time=300) +return(MSEi_vec(i_vec, J, h_vec)) +} +MSEhat_i <- function(h) { +h_vec <- rep(h, time=300) +return(sapply(I,h_vec,FUN=MSEi)) +} +MSEhat_i(.1) diff --git a/Part 2 - Model_Selection/model-selection.log b/Part 2 - Model_Selection/model-selection.log index cffc983..e511f04 100644 --- a/Part 2 - Model_Selection/model-selection.log +++ b/Part 2 - Model_Selection/model-selection.log @@ -1,3 +1,36 @@ +<<<<<<< HEAD +This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6500 64-bit) (preloaded format=pdflatex 2018.2.6) 5 FEB 2020 21:55 +entering extended mode +**./model-selection.tex +(model-selection.tex +LaTeX2e <2017-04-15> +Babel <3.15> and hyphenation patterns for 75 language(s) loaded. +(../slideHeader.tex + +! LaTeX Error: File `beamer.cls' not found. + +Type X to quit or to proceed, +or enter new name. (Default extension: cls) + +Enter file name: +! Emergency stop. + + +l.3 \usefonttheme + [onlymath]{serif} +*** (cannot \read from terminal in nonstop modes) + + +Here is how much of TeX's memory you used: + 18 strings out of 493312 + 443 string characters out of 3138906 + 53761 words of memory out of 3000000 + 3659 multiletter control sequences out of 15000+200000 + 3640 words of font info for 14 fonts, out of 3000000 for 9000 + 1141 hyphenation exceptions out of 8191 + 12i,0n,7p,125b,8s stack positions out of 5000i,500n,10000p,200000b,50000s +! ==> Fatal error occurred, no output PDF file produced! +======= This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex 2018.4.16) 4 FEB 2020 13:31 entering extended mode restricted \write18 enabled. @@ -1837,3 +1870,4 @@ PDF statistics: 188 named destinations out of 1000 (max. 500000) 280 words of extra memory for PDF output out of 10000 (max. 10000000) +>>>>>>> upstream/master diff --git a/Part 2 - Model_Selection/model-selection.tex b/Part 2 - Model_Selection/model-selection.tex index f667e74..b0e48b3 100644 --- a/Part 2 - Model_Selection/model-selection.tex +++ b/Part 2 - Model_Selection/model-selection.tex @@ -634,14 +634,14 @@ \section{Dimension Reduction} \begin{frame} \frametitle{Principal Components} \begin{center} -\includegraphics[height=0.85\textheight]{./resources/princomp1} +\includegraphics[width=3.5in]{./resources/princomp1} \end{center} \end{frame} \begin{frame} \frametitle{Principal Components} \begin{center} -\includegraphics[height=0.85\textheight]{./resources/princomp2} +\includegraphics[width=3.5in]{./resources/princomp2} \end{center} \end{frame} @@ -668,7 +668,7 @@ \section{Dimension Reduction} \begin{frame} \frametitle{Principal Components} \begin{center} -\includegraphics[height=0.85\textheight]{./resources/pcrridge} +\includegraphics[width=\textwidth]{./resources/pcrridge} \end{center} \end{frame} @@ -783,28 +783,28 @@ \section{Conclusion} \frametitle{Overall Comparison} \vspace{-15pt} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/comparisons} + \includegraphics[width=\textwidth]{./resources/comparisons} \end{center} \end{frame} \begin{frame} \frametitle{Overall Comparison} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/regressiontable} + \includegraphics[width=\textwidth]{./resources/regressiontable} \end{center} \end{frame} \begin{frame} \frametitle{Paths} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/ESLshrinkpathPositive} + \includegraphics[width=\textwidth]{./resources/ESLshrinkpathPositive} \end{center} \end{frame} \begin{frame} \vspace{-10pt} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/ESLshrinkpathNegative} + \includegraphics[width=\textwidth]{./resources/ESLshrinkpathNegative} \end{center} \end{frame} @@ -827,7 +827,7 @@ \subsection{Trade} \begin{frame} \vspace{-10pt} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/BaxterAbstract} + \includegraphics[height=\textheight]{./resources/BaxterAbstract} \end{center} \nocite{baxter2017robust} \end{frame} @@ -835,14 +835,14 @@ \subsection{Trade} \begin{frame} \vspace{-10pt} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/BaxterOLS} + \includegraphics[height=\textheight]{./resources/BaxterOLS} \end{center} \end{frame} \begin{frame} \vspace{-10pt} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/BaxterLassoPath} + \includegraphics[height=\textheight]{./resources/BaxterLassoPath} \end{center} \end{frame} @@ -851,21 +851,21 @@ \subsection{Crime} \begin{frame} \vspace{-10pt} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/QJELevitt} + \includegraphics[width=\textwidth]{./resources/QJELevitt} \end{center} \end{frame} \begin{frame} \vspace{-10pt} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/QJELevittScatter} + \includegraphics[width=\textwidth]{./resources/QJELevittScatter} \end{center} \end{frame} \begin{frame} \vspace{-10pt} \begin{center} - \includegraphics[height=0.85\textheight]{./resources/QJELevittTable} + \includegraphics[width=\textwidth]{./resources/QJELevittTable} \end{center} \end{frame} @@ -885,14 +885,14 @@ \subsection{Crime} \begin{frame} \vspace{-10pt} \begin{center} - \includegraphics[scale=0.5]{./resources/BCHLevittVars} + \includegraphics[width=\textwidth]{./resources/BCHLevittVars} \end{center} \end{frame} \begin{frame} \vspace{-10pt} \begin{center} - \includegraphics[scale=0.5]{./resources/BCHLevittTable} + \includegraphics[width=\textwidth]{./resources/BCHLevittTable} \end{center} \end{frame} diff --git a/ProblemSets/pset1/pset1_solutions.pdf b/ProblemSets/pset1/pset1_solutions.pdf new file mode 100644 index 0000000..37d2e05 Binary files /dev/null and b/ProblemSets/pset1/pset1_solutions.pdf differ