## Read in data, attach file, and print variable names airq4 <- read.fwf("http://www.stat.ufl.edu/~winner/sta6166/airq4data.txt", width=c(3,6,11,10,6,8,10,8,10), col.names=c("city1","city2","pop1","pop2","dist","fare00","pass00","fare01","pass01")) attach(airq4); names(airq4) ## Create revenue variables for 2000, 2001, and % change variable rev00 <- 13*fare00*pass00 rev01 <- 13*fare01*pass01 pctchng <- 100*(rev01-rev00)/rev00 ## Obtain Summary Stats and histogram for pctchng summary(pctchng) hist(pctchng,breaks=50) ## Obtain and print mean, variance, and standard deviation for pctchng (pct_mean <- mean(pctchng)) (pct_var <- var(pctchng)) (pct_sd <- sd(pctchng)) ## Obtain and print out z(.025), the 97.5th %-ile for Z-distribution (z.025 <- qnorm(.975,0,1)) ## Define margin of Error and compute and print Sample size needed E <- 4 (n.me4 <- (z.025^2*pct_var)/E^2) ## Obtain critical z-value for 1-sided test with alpha=0.05 (z.05 <- qnorm(.95,0,1)) ## Compute and print rejection region wrt ybar for n=25 (rr.25 <- -z.05*pct_sd/sqrt(25)) ## Compute and print the power (Prob we reject H0 given true mu) (pow.25 <- pnorm(rr.25,pct_mean,pct_sd/sqrt(25))) ###### Obtain random sample of 50 markets pct.samp <- sample(pctchng,50,replace=F) ## Compute and print the sample mean and standard deviation (pct.samp.mean <- mean(pct.samp)) (pct.samp.sd <- sd(pct.samp)) ## Compute and print the critical t-value and 95% CI for mu (t.49.025 <- qt(.975,49)) (pct.samp.ci <- c(pct.samp.mean-t.49.025*pct.samp.sd/sqrt(50), pct.samp.mean+t.49.025*pct.samp.sd/sqrt(50))) ## Compute the t-statistic and lower tail P-value (pct.samp.ts <- pct.samp.mean/(pct.samp.sd/sqrt(50))) (pct.samp.pv <- pt(pct.samp.ts,49))