![]() ![]() The step() command will then add and remove parameters in search of a model with the lowest AIC score. We include in the scope of the search all fields given to us. We begin the process by checking the correlation between all independent variables and the dependent variable, Life Expectancy. The work is done with the step() command which evaluates models based on the Akaike Information Criterion (AIC) which measures the likelihood of a model and thus can be used for model evaluation. Step(lm(`Life Exp`~Murder, data=state), direction="both", scope=~Population+Income+Murder+Illiteracy+Area+Frost+`HS Grad`) We can also view other information such as the error sum of squares and mean sum of squares through the anova() command.Īdditionally, we can graphically analyze the statistical properties of our model. Since p < 0.05, we can reject the null hypothesis. The summary provides lots of data on the model such as the R squared and adjusted R squared values, the F statistic, and the p-value and is a valuable tool for evaluating the model. The output should look something like this: To view additional details of the model, use the summary() command: To visualize our regression line, we can overlay it with the original training data. From the output of the model, we can also see our regression line: Distance = -17.58 + 3.93 * Speed. We now have a trained linear model that predicts the stopping distance of a car given its speed. To train a linear model on the data, we use the lm() command: ![]() For our first model, we will train a model of the form Y = β 1 + β 2X + ε where Y is the car breaking distance and X is the car's speed. Now that we are convinced there is a relationship between the data, we can use the speed of a car to predict its stopping distance. This is high enough to indicate that the variables are indeed related in some fashion. ![]() We obtain a pearson correlation factors of 0.8068949 and a spearman correlation factor of 0.8303568. Cor(cars, use="complete.obs", method="pearson")Ĭor(cars, use="complete.obs", method="spearman") ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |