mean(cps$age)
median(cps$age)
mean(cps$earnwk, na.rm = TRUE)
median(cps$earnwk, na.rm = TRUE)
# histogram of weekly earnings with 92 bins (Freedman-Diaconis), with estimated density overlaid
hist(cpsemployed$earnwk, breaks=92, freq=FALSE, main="", xlab="Weekly earnings")
lines(density(cpsemployed$earnwk), col="blue", lwd=2)
abline(v=mean(cpsemployed$earnwk), col="red", lwd=2)
abline(v=median(cpsemployed$earnwk), col="green", lwd=2)
legend("topright", legend=c("Sample median","Sample mean"), col=c("green","red"), lty=c(1,1), lwd=c(2,2))
mean(sp500$T)
median(sp500$T)
mean(sp500$BAC)
median(sp500$BAC)
# graph-display format (two rows, one column)
par(mfrow = c(2,1))
# histograms of T and BAC returns, with density curves
hist(sp500$T, freq=FALSE, breaks=seq(-0.8,0.8,0.02), main="", xlab="Monthly return (T)")
lines(density(sp500$T), col="blue", lwd=2)
hist(sp500$BAC, freq=FALSE, breaks=seq(-0.8,0.8,0.02), main="", xlab="Monthly return (BAC)")
lines(density(sp500$BAC), col="blue", lwd=2)
# sample quartiles of weekly earnings
quantile(cpsemployed$earnwk, probs = c(0.25,0.50,0.75))
# sample quartiles of weekly earnings
quantile(cpsemployed$earnwk, probs = seq(0.1,0.9,0.1))
# histogram of weekly earnings with 92 bins (Freedman-Diaconis), with estimated density overlaid
hist(cpsemployed$earnwk, breaks=92, freq=FALSE, main="Weekly earnings distribution is right-skewed", xlab="Weekly earnings")
lines(density(cpsemployed$earnwk), col="blue", lwd=2)
abline(v=quantile(cpsemployed$earnwk,0.1), col="red", lwd=2)
abline(v=quantile(cpsemployed$earnwk,0.25), col="orange", lwd=2)
abline(v=median(cpsemployed$earnwk), col="blue", lwd=2)
abline(v=quantile(cpsemployed$earnwk,0.75), col="green", lwd=2)
abline(v=quantile(cpsemployed$earnwk,0.9), col="violet", lwd=2)
legend("topright", legend=c("Sample 10% quantile","Sample 25% quantile","Sample median","Sample 75% quantile","Sample 90% quantile"), col=c("red","orange","blue","green","violet"), lty=c(1,1),lwd=c(2,2))