You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{"type":"cell","id":"00cd9e","pos":6,"input":"We are going to try to see if there is an association between the ratings for Judicial Integrity and Demeanor. We can type\n\n```\nUSJudgeRatings$INTG\n```\n\neach time we want to use the Judicial Integrity variable or we could make a shortcut for ourselves. Try this\n\n```\nJI <-USJudgeRatings$INTG \n```","cell_type":"markdown"}
{"type":"cell","id":"083a58","pos":55,"input":"Make a scatterplot that includes the line of best fit. Make sure that the title and labels are correct.","cell_type":"markdown"}
{"type":"cell","id":"1ebad4","pos":20,"input":"Now we will create linear modelby performing a simple linear regression.\n```\nlinearMod <- lm(JI ~ DM )\n```","cell_type":"markdown"}
28
+
{"type":"cell","id":"21c591","pos":38,"input":"Now what if you had three new judges whose Demeanor ratings were 1, 7.3 and 10. What would you predict that their Judicial Integrity ratigns would be?\n```\npredict(linearMod,data.frame(DM = c(1,7.3,10)))\n```","cell_type":"markdown"}
29
+
{"type":"cell","id":"248152","pos":60,"input":"Predict the height of trees with girths 5, 6, 7, 8, 9, 10, 11, 12, 13 and 15.7","cell_type":"markdown"}
{"type":"cell","id":"38dc23","pos":45,"input":"Make shortcuts for the girth and height variables.","cell_type":"markdown"}
32
+
{"type":"cell","id":"3b54da","pos":4,"input":"Get a quick look at the data set by using the head command\n```\nhead(USJudgeRatings)\n```","cell_type":"markdown"}
{"type":"cell","id":"3e255a","pos":34,"input":"Now we can make a graph of the residuals\n```\nplot(DM,USJudgeRatings$Residuals,col = \"blue\",main = \"Residual Plot\",\ncex = 1.3,pch = 16,xlab = \"Demeanor\",ylab = \"Residuals\")\n```","cell_type":"markdown"}
{"type":"cell","id":"50bd95","pos":8,"input":"Now every time we type JI our program will read it as USJudgeRatings$INTG\n\nMake a shortcut for Demeanor\n```\nDM<-USJudgeRatings$DMNR\n```\n","cell_type":"markdown"}
38
+
{"type":"cell","id":"52a82a","pos":28,"input":"Now lets add the regression line to our scatterplot\n\n```\nplot(DM,JI,col = \"blue\",main = \"Judicial Integrity vs Demeanor Regression\",\nabline(lm(JI~DM)),cex = 1.3,pch = 16, \n xlab = \"Demeanor Rating\",ylab = \"Judicial Integrity Rating\")\n```\nThe only real difference is the *abline(lm(JI~DM))* before the cex.\n","cell_type":"markdown"}
39
+
{"type":"cell","id":"56b926","pos":52,"input":"What is the correlation between girth and height? What is R-squared?\n","cell_type":"markdown"}
40
+
{"type":"cell","id":"5d7a29","pos":18,"input":"You can also change the size of the dots by changing the number after cex and the shape of the dots by changing the number after pch. Try adjusting them now","cell_type":"markdown"}
41
+
{"type":"cell","id":"5fab55","pos":36,"input":"Do you see a pattern in the residuals?","cell_type":"markdown"}
42
+
{"type":"cell","id":"62ca92","pos":32,"input":"We can add this list to our data set through this command\n```\nUSJudgeRatings <- USJudgeRatings %>%\n mutate(Residuals = resid(linearMod))\n```\n","cell_type":"markdown"}
43
+
{"type":"cell","id":"66965b","pos":49,"input":"Find the equation of the line of best fit and explain in context what the slope and y-intercept tell us.","cell_type":"markdown"}
44
+
{"type":"cell","id":"6c6aef","pos":26,"input":"If we use the command\n```\nsummary(linearMod)\n```\nWe will get the model, R-squared, and a bunch of other interesting information that may come in handy later.","cell_type":"markdown"}
45
+
{"type":"cell","id":"8592eb","pos":16,"input":"To find a list of all the colors availible you can type\n```\ncolors()\n```","cell_type":"markdown"}
46
+
{"type":"cell","id":"8e6992","pos":14,"input":"You can also change the color of the by typing in different colors.Try typing in a few colors to see what happens","cell_type":"markdown"}
47
+
{"type":"cell","id":"9088cc","pos":30,"input":"Much like our calculators keep a list of all the residuals after running a regression R does as well\n```\nresid(linearMod)\n```","cell_type":"markdown"}
48
+
{"type":"cell","id":"9122d9","pos":40,"input":"## Trees\n\nIs there a relationship between the girth and height of a tree?\n```\ndata(trees)\n```","cell_type":"markdown"}
{"type":"cell","id":"9e9e8f","pos":47,"input":"Create a scatterplot of girth vs height where girth is the explanatory variable. Make sure that it has a good title, good labels, very small points, unusually shaped points, and a unique color.","cell_type":"markdown"}
{"type":"cell","id":"abbae5","pos":2,"input":"The data set we will look at is of Lawyers' ratings of state judges in the US Superior Court. Load the data set and use the \"?\" command to find out more about this data set.\n\n\n```\ndata(USJudgeRatings)\n?USJudgeRatings\n```\n\n","cell_type":"markdown"}
53
+
{"type":"cell","id":"adf14e","pos":22,"input":"By typing\n```\nprint(linearMod)\n```\nwe can see the regression line where Intercept is the y-intercept and the number under the variable is the coefficient of the variable.","cell_type":"markdown"}
54
+
{"type":"cell","id":"af4bb0","pos":42,"input":"Find out a little bit about your data set. How many trees are there? What are the variables? ","cell_type":"markdown"}
{"type":"cell","id":"b70881","pos":12,"input":"Notice that this way of making a scatterplot is slightly different than the one we made on Day 1. One advantage of this method is that it is more customizable. Notice that you can easily change the title and labels to whatever you want. Change the title to *Ratings of Judicial Integrity vs Demeanor* and the labels to *Judicial Integrity* and *Demeanor* ","cell_type":"markdown"}
57
+
{"type":"cell","id":"b788b9","pos":0,"input":"# Day 3: Linear Regression\n\nWe have learned how to minipulate a data set and how to make certain displays.\nToday we will learn how to perform a linear regression.\n\n\nFirst we need to load the helpful libraries of ```dplyr``` and ```ggplot2```.\n\n```\nlibrary(dplyr)\nlibrary(ggplot2)\n```\n\n","cell_type":"markdown"}
58
+
{"type":"cell","id":"c80fd9","pos":24,"input":"We can find the correlation between Judicial Integrity and Demeanor by using this command\n```\ncor(JI,DM)\n```","cell_type":"markdown"}
{"type":"cell","id":"d74585","pos":10,"input":"###### Now create a scatterplot of Judicial Integrity vs Demeanor of the judges. Notice where we used our new shortcuts!\n\n```\nplot(DM,JI,col = \"blue\",main = \"Ratings\",\ncex = 1.3,pch = 16,xlab = \"DEM\",ylab = \"JI\")\n```","cell_type":"markdown"}
0 commit comments