



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Introduction to Statistical Learning (James/Witten/Hastie/Tibshirani)
Typology: Exercises
1 / 7
This page cannot be seen from the preview
Don't miss anything!
(a). Use the read.csv() function to read the data into R. Call the loaded data college. Make sure that you have the directory set to the correct location for the data.
college= read.csv ("College.csv")
(b). Look at the data using the fix() function. You should notice that the first column is just the name of each university. We don’t really want R to treat this as data. However, it may be handy to have these names for later. Try the following commands :
fix (college)
This will bring up a data viewer. In R-studio you can also use the "View()" function or click the dataset name in the Environment tab in the top right pane
rownames (college)=college[,1]
This line tells R to use the first column in the dataset(college names) as the rownames. Have a look at the fix() function output to see this.
college=college[,-1]
We then remove the first column of data , since we do not need the school names as a variable. Row names are still there for us but for reference only.
(c). (i) Use the summary() function to produce a numerical summary of the variables in the data set.
summary (college)
Among other things, we can see that 565 of the 777 schools in the dataset are private, out of state tuition is $10,441 on average, there exists a school for which somehow 118% of the students graduate, as well as one for which 0% of alumni donate.
Anomolies like the graduation rate happen all the time. This highlights the importance of always needing to explore the data.
(ii) Use the pairs() function to produce a scatterplot matrix of the first ten columns or variables of the data.
pairs (college[,1:10])
Private schools are more expensive!
(iv) Create a new qualitative variable, called Elite, by binning the Top10perc variable. We are going to divide universities into two groups based on whether or not the proportion of students coming from the top 10% of their high school classes exceeds 50%.
Elite = rep ("No", nrow (college)) Elite[college$Top10perc>50] = "Yes" Elite = as.factor (Elite) college = data.frame (college, Elite) summary (college$Elite)
plot (college$Elite, college$Outstate)
(v) Use the hist() function to produce some histograms with differing numbers of bins for a few of the quantitative variables. You may find the command par(mfrow=c(2,2)) useful: it will divide the print window into four regions so that four plots can be made simultaneously. Modifying the arguments to this function will divide the screen in other ways.
par (mfrow= c (2,2)) hist (college$Apps) hist (college$perc.alumni, col=2) hist (college$S.F.Ratio, col=3, breaks=10) hist (college$Expend, breaks=100)
college$Outstate
college$Grad.Rate
college$Accept/college$Apps
college$S.F.Ratio
college$Top10perc
college$Grad.Rate