## Note: PDF files containing histograms will be saved into the current working directory. ## Please use setwd() and getwd(), as appropriate. # install packages from CRAN and load # install.packages("ExtremeBounds") # install.packages("sandwich") library("ExtremeBounds") # use 'sandwich' package to calculate heteroskedasticity-robust standard errors library("sandwich") se.robust <- function(model.object) { model.fit <- vcovHC(model.object, type = "HC") out <- sqrt(diag(model.fit)) return(out) } ### ### naive EBA ### naive.eba <- eba(formula = mpg ~ cyl + carb + disp + hp + vs + drat + wt + qsec + gear + am, data = mtcars, k = 0:9) print(naive.eba) pdf("naive.pdf", height=6, width=6) hist(naive.eba) dev.off() ## Alternatively, one can run the following to achieve the same result (uncomment the portion below): # naive.eba <- eba(data = mtcars, y = "mpg", doubtful = c("cyl", "carb", "disp", "hp", "vs", "drat", "wt", "qsec", "gear", "am"), k = 0:9) ### ### sophisticated EBA ### sophisticated.eba <- eba(formula = mpg ~ wt | cyl + carb + disp + hp | vs + drat + wt + qsec + gear + am, data = mtcars, exclusive = ~ cyl + carb + disp + hp | am + gear, vif = 7, se.fun = se.robust, weights = "lri") ## Alternatively, one can run the following to achieve the same result (uncomment the portion below): # doubtful.variables <- c("cyl", "carb", "disp", "hp", "vs", "drat", "wt", "qsec", "gear", "am") # engine.variables <- c("cyl", "carb", "disp", "hp") # transmission.variables <- c("am", "gear") # sophisticated.eba <- eba(data = mtcars, y = "mpg", free = "wt", # doubtful = doubtful.variables, focus = engine.variables, # exclusive = list(engine.variables, transmission.variables), # vif = 7, se.fun = se.robust, weights = "lri") pdf("sophisticated.pdf", height=6, width=6) hist(sophisticated.eba, variables = c("cyl", "carb", "disp", "hp"), main = c(cyl = "number of cylinders", carb = "number of carburetors", disp = "engine displacement", hp = "gross horsepower"), normal.show = TRUE) dev.off() print(sophisticated.eba)