setwd("I:\\classes\\statcomputingI.2012") setwd("I:/classes/statcomputingI.2012") data <- read.csv("SCBC2004.csv") summary(data) summary(data$stagen) mean(data$stagen, na.rm=T) q1 <- quantile(data$age, prob=c(0.025, 0.975)) age <- data$age stagen <- data$stagen site <- data$site x <- cbind(age, stagen) y <- data.frame(age, stagen) y <- as.data.frame(x) z <- cbind(site, age) is.vector(age) z <- c(1,2,3,4,5) ################## # EXAMPLES OF CODE TO HELP WITH THE HOMEWORK ################ # Read in the dataset setwd("I:/classes/statcomputingI") data <- read.csv("SCBC2004.csv") ####################### # what is the dimension of our dataset? dim(data) ################ # what are the names of the variables in our dataset? names(data) ################ # what are the mean, median, 1st and 3rd quartile of age? age <- data$age summary(age) quantile(age) quantile(age, prob=c(0.25, 0.75)) ########################## # create a boxplot of age boxplot(age) ######################### # create a histogram of age hist(age) ######################## # generate a new variable that is the log of age logage <- log(age) ######################### # generate a new categorical version of age agegrp <- cut(age, breaks=c(0,50,60,130)) ############################# # make a table of agegrp by er status table(agegrp, data$ern) ############################## # test that there is an association between age group # and er status using fisher's test tabi <- table(agegrp, data$ern) fisher.test(tabi) ######################### # test that there is an association between age and er using t-test t.test(age~data$ern)