Your plot should now appear similar to the one below. We can then add the regression model as a straight line with "a" and "b" parameters with the "abline()" function. Note that the order is opposite of the "plot()" command. The tilde character (~) indicates that we want to regress speed as the predictor (independent) variable against distance as the response (dependent) variable. The code below specifies the column "dist" within the "cars" table and the column "speed". To create a linear model, you can use the "lm()" function. You can also check the length of a vector or matrix with the "length()" function. You can display data by just typing the name of the variable. Enter the code below to make sure the "stats" library is loaded and then plot speed against distance. To get started, we'll load the "stats" library which contains a number of example data sets including a small table of speeds and distances for cars.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |