1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> ###################################################
> ### chunk number 1: setup
> ###################################################
> options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
R>
R> options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
R>
R> library("AER")
Loading required package: car
Loading required package: carData
Loading required package: lmtest
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
Loading required package: survival
R>
R> suppressWarnings(RNGversion("3.5.0"))
R> set.seed(1071)
R>
R>
R> ###################################################
R> ### chunk number 2: journals-data
R> ###################################################
R> data("Journals", package = "AER")
R>
R>
R> ###################################################
R> ### chunk number 3: journals-dim
R> ###################################################
R> dim(Journals)
[1] 180 10
R> names(Journals)
[1] "title" "publisher" "society" "price"
[5] "pages" "charpp" "citations" "foundingyear"
[9] "subs" "field"
R>
R>
R> ###################################################
R> ### chunk number 4: journals-plot eval=FALSE
R> ###################################################
R> ## plot(log(subs) ~ log(price/citations), data = Journals)
R>
R>
R> ###################################################
R> ### chunk number 5: journals-lm eval=FALSE
R> ###################################################
R> ## j_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
R> ## abline(j_lm)
R>
R>
R> ###################################################
R> ### chunk number 6: journals-lmplot
R> ###################################################
R> plot(log(subs) ~ log(price/citations), data = Journals)
R> j_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
R> abline(j_lm)
R>
R>
R> ###################################################
R> ### chunk number 7: journals-lm-summary
R> ###################################################
R> summary(j_lm)
Call:
lm(formula = log(subs) ~ log(price/citations), data = Journals)
Residuals:
Min 1Q Median 3Q Max
-2.7248 -0.5361 0.0372 0.4662 1.8481
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.7662 0.0559 85.2 <2e-16
log(price/citations) -0.5331 0.0356 -15.0 <2e-16
Residual standard error: 0.75 on 178 degrees of freedom
Multiple R-squared: 0.557, Adjusted R-squared: 0.555
F-statistic: 224 on 1 and 178 DF, p-value: <2e-16
R>
R>
R> ###################################################
R> ### chunk number 8: cps-data
R> ###################################################
R> data("CPS1985", package = "AER")
R> cps <- CPS1985
R>
R>
R> ###################################################
R> ### chunk number 9: cps-data1 eval=FALSE
R> ###################################################
R> ## data("CPS1985", package = "AER")
R> ## cps <- CPS1985
R>
R>
R> ###################################################
R> ### chunk number 10: cps-reg
R> ###################################################
R> library("quantreg")
Loading required package: SparseM
Attaching package: 'SparseM'
The following object is masked from 'package:base':
backsolve
Attaching package: 'quantreg'
The following object is masked from 'package:survival':
untangle.specials
R> cps_lm <- lm(log(wage) ~ experience + I(experience^2) +
+ education, data = cps)
R> cps_rq <- rq(log(wage) ~ experience + I(experience^2) +
+ education, data = cps, tau = seq(0.2, 0.8, by = 0.15))
R>
R>
R> ###################################################
R> ### chunk number 11: cps-predict
R> ###################################################
R> cps2 <- data.frame(education = mean(cps$education),
+ experience = min(cps$experience):max(cps$experience))
R> cps2 <- cbind(cps2, predict(cps_lm, newdata = cps2,
+ interval = "prediction"))
R> cps2 <- cbind(cps2,
+ predict(cps_rq, newdata = cps2, type = ""))
R>
R>
R> ###################################################
R> ### chunk number 12: rq-plot eval=FALSE
R> ###################################################
R> ## plot(log(wage) ~ experience, data = cps)
R> ## for(i in 6:10) lines(cps2[,i] ~ experience,
R> ## data = cps2, col = "red")
R>
R>
R> ###################################################
R> ### chunk number 13: rq-plot1
R> ###################################################
R> plot(log(wage) ~ experience, data = cps)
R> for(i in 6:10) lines(cps2[,i] ~ experience,
+ data = cps2, col = "red")
R>
R>
R> ###################################################
R> ### chunk number 14: srq-plot eval=FALSE
R> ###################################################
R> ## plot(summary(cps_rq))
R>
R>
R> ###################################################
R> ### chunk number 15: srq-plot1
R> ###################################################
R> try(plot(summary(cps_rq)))
Warning messages:
1: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
Solution may be nonunique
2: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
Solution may be nonunique
R>
R>
R> ###################################################
R> ### chunk number 16: bkde-fit
R> ###################################################
R> library("KernSmooth")
KernSmooth 2.23 loaded
Copyright M. P. Wand 1997-2009
R> cps_bkde <- bkde2D(cbind(cps$experience, log(cps$wage)),
+ bandwidth = c(3.5, 0.5), gridsize = c(200, 200))
R>
R>
R> ###################################################
R> ### chunk number 17: bkde-plot eval=FALSE
R> ###################################################
R> ## image(cps_bkde$x1, cps_bkde$x2, cps_bkde$fhat,
R> ## col = rev(gray.colors(10, gamma = 1)),
R> ## xlab = "experience", ylab = "log(wage)")
R> ## box()
R> ## lines(fit ~ experience, data = cps2)
R> ## lines(lwr ~ experience, data = cps2, lty = 2)
R> ## lines(upr ~ experience, data = cps2, lty = 2)
R>
R>
R> ###################################################
R> ### chunk number 18: bkde-plot1
R> ###################################################
R> image(cps_bkde$x1, cps_bkde$x2, cps_bkde$fhat,
+ col = rev(gray.colors(10, gamma = 1)),
+ xlab = "experience", ylab = "log(wage)")
R> box()
R> lines(fit ~ experience, data = cps2)
R> lines(lwr ~ experience, data = cps2, lty = 2)
R> lines(upr ~ experience, data = cps2, lty = 2)
R>
R>
R> ###################################################
R> ### chunk number 19: install eval=FALSE
R> ###################################################
R> ## install.packages("AER")
R>
R>
R> ###################################################
R> ### chunk number 20: library
R> ###################################################
R> library("AER")
R>
R>
R> ###################################################
R> ### chunk number 21: objects
R> ###################################################
R> objects()
[1] "CPS1985" "Journals" "cps" "cps2" "cps_bkde"
[6] "cps_lm" "cps_rq" "i" "j_lm"
R>
R>
R> ###################################################
R> ### chunk number 22: search
R> ###################################################
R> search()
[1] ".GlobalEnv" "package:KernSmooth"
[3] "package:quantreg" "package:SparseM"
[5] "package:AER" "package:survival"
[7] "package:sandwich" "package:lmtest"
[9] "package:zoo" "package:car"
[11] "package:carData" "package:stats"
[13] "package:graphics" "package:grDevices"
[15] "package:utils" "package:datasets"
[17] "package:methods" "Autoloads"
[19] "package:base"
R>
R>
R> ###################################################
R> ### chunk number 23: assignment
R> ###################################################
R> x <- 2
R> objects()
[1] "CPS1985" "Journals" "cps" "cps2" "cps_bkde"
[6] "cps_lm" "cps_rq" "i" "j_lm" "x"
R>
R>
R> ###################################################
R> ### chunk number 24: remove
R> ###################################################
R> remove(x)
R> objects()
[1] "CPS1985" "Journals" "cps" "cps2" "cps_bkde"
[6] "cps_lm" "cps_rq" "i" "j_lm"
R>
R>
R> ###################################################
R> ### chunk number 25: log eval=FALSE
R> ###################################################
R> ## log(16, 2)
R> ## log(x = 16, 2)
R> ## log(16, base = 2)
R> ## log(base = 2, x = 16)
R>
R>
R> ###################################################
R> ### chunk number 26: q eval=FALSE
R> ###################################################
R> ## q()
R>
R>
R> ###################################################
R> ### chunk number 27: apropos
R> ###################################################
R> apropos("help")
[1] "help" "help.request" "help.search" "help.start"
R>
R>
R>
> proc.time()
user system elapsed
1.441 0.069 1.493
|