par(mfrow = c(2,2))
s <- seq(-4,+4,0.01)
plot(s, dnorm(s,0, 1), type="l", col="blue", xlab="",ylab="")
lines(s, dnorm(s,0,1.5), col="black", lty=3)
s <- seq(-4,+8,0.01)
plot(s, dnorm(s,4, 1), type="l", col="blue", xlab="",ylab="")
lines(s, dnorm(s,0,1), col="black", lty=3)
s <- seq(-6,+8,0.01)
plot(s, dnorm(s,4, 1), type="l", col="blue", xlab="",ylab="")
lines(s, dnorm(s,0,2), col="black", lty=3)
s <- seq(-4,+10,0.01)
plot(s, dnorm(s,0,1), type="l", col="blue", xlab="",ylab="")
lines(s, dnorm(s,4,2), col="black", lty=3)
# interquartile range of weekly earnings
IQR(cps$earnwk, na.rm = TRUE)
# interquartile range of weekly earnings
IQR(cps$age)
# graph-display format (one row, two columns)
par(mfrow = c(1,2))
# box plot with whiskers and outliers (the default in R)
boxplot(cpsemployed$earnwk, ylab="Weekly earnings", main="Box plot (whiskers and outliers)")
# box plot with whiskers at min and max values
boxplot(cpsemployed$earnwk, range=0, ylab="Weekly earnings", main="Box plot (whiskers at min/max)")
# graph-display format (one row, two columns)
par(mfrow = c(1,2))
# box plot (whiskers and outliers) for AT&T
boxplot(sp500$T, ylab="Monthly return (T)", main="Box plot (whiskers and outliers)",ylim=c(-0.6,0.8))
# box plot (whiskers and outliers) for Bank of America
boxplot(sp500$BAC, ylab="Monthly return (BAC)", main="Box plot (whiskers and outliers)",ylim=c(-0.6,0.8))
# MAD for AT&T
mean(abs(sp500$T-mean(sp500$T)))
# MAD for Bank of America
mean(abs(sp500$BAC-mean(sp500$BAC)))
# sample variance and sample standard deviation for AT&T
var(sp500$T)
sd(sp500$T)
# sample variance and sample standard deviation for Bank of America
var(sp500$BAC)
sd(sp500$BAC)
cpsunion <- cpsemployed[cpsemployed$unionstatus=="Union",]
cpsnonunion <- cpsemployed[cpsemployed$unionstatus=="Non-union",]
par(mfrow = c(2,1))
hist(cpsunion$earnwk, breaks=seq(0,max(cpsunion$earnwk)+200,200), freq=FALSE, main="Weekly earnings (union)",xlim=c(0,6000),xlab="Weekly earnings")
lines(density(cpsunion$earnwk), col="blue", lwd=2)
hist(cpsnonunion$earnwk, breaks=seq(0,max(cpsnonunion$earnwk)+200,200), freq=FALSE, main="Weekly earnings (non-union)", xlim=c(0,6000),xlab="Weekly earnings")
lines(density(cpsnonunion$earnwk), col="blue", lwd=2)
cpsmale <- cpsemployed[cpsemployed$gender=="Male",]
cpsfemale <- cpsemployed[cpsemployed$gender=="Female",]
par(mfrow = c(2,1))
hist(cpsmale$earnwk, breaks=seq(0,max(cpsmale$earnwk)+200,200), freq=FALSE, main="Weekly earnings (male)",xlim=c(0,6000),xlab="Weekly earnings")
lines(density(cpsmale$earnwk), col="blue", lwd=2)
hist(cpsfemale$earnwk, breaks=seq(0,max(cpsfemale$earnwk)+200,200), freq=FALSE, main="Weekly earnings (female)", xlim=c(0,6000),xlab="Weekly earnings")
lines(density(cpsfemale$earnwk), col="blue", lwd=2)