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
library(gregmisc) | |
minor2 = function(mat, idx){ | |
little_mat = mat[idx,idx] | |
return(det(little_mat)) | |
} | |
index_vec = combinations(nrow(mat),2) | |
minors = apply(index_vec, MARGIN=1, FUN=function(ix){ minor2(mat,ix)}) |
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
minors = NULL | |
for(i in 1:(nrow(mat)-1)){ | |
start = i +1 | |
for(j in start:nrow(mat)){ | |
thisminor = det(mat[c(i,j),c(i,j)]) | |
minors = c(minors, thisminor) | |
} | |
} |
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
latlong = aggregate(mydat[,3:4], list(BusID=mydat$BusID), | |
FUN=mean, na.rm=TRUE) | |
mycleandat = merge(mydat[,-c(3,4)], latlong) | |
mycleandat[mycleandat$BusID==1,] |
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
set.seed(209) | |
N_firms =125 | |
N_periods =25 | |
BusID = 1:N_firms | |
period = 1:N_periods | |
long = runif(N_firms, -124, -68.25) | |
lat = runif(N_firms, 26, 47) |
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
x11 = NULL | |
for(i in 1:1000){ | |
x11 = c(trick_works(1,1),x11) | |
} |
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
trick_works = function(num_times=1, num_decks=1){ | |
deck = rep(1:13, each=4,times =num_decks) | |
facedeck = pmin(deck, 10) | |
init= 1:10 | |
secretnum = init | |
stop = length(deck)*num_times | |
mycards = sample(facedeck, replace=FALSE) ## Shuffle the Deck | |
data = init | |
draws = 1:stop |
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
secretnum = 1:10 | |
stop = 150 | |
faceval = round(floor(13*runif(stop))+0.999) | |
faceval = pmin(10,faceval) | |
data = secretnum | |
draws = 1:stop | |
for(i in draws){ | |
secretnum = secretnum -1 |
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
set.seed(209) | |
myiv = iv(y~x1+x2+p, p~z1+z2, data=mktshare) | |
myivboot = ivboot(y~x1+x2+p, p~z1+z2, data=mktshare) | |
mtable(myiv, myivboot) |
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
ivboot <- function(sec,fir,data,boots=500){ | |
dat <- data | |
sec <- as.formula(sec) | |
fir <- as.formula(fir) | |
thisiv <- iv(sec, fir,data) | |
booter <- function(dat,i){ | |
coef(iv(sec,fir,data=dat[i,])) | |
} | |
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
library(tonymisc) | |
library(boot) | |
data(mktshare) |
NewerOlder