Understanding Regression Models: Predicting, Analyzing, and Interpreting Data in R
In this assignment, I explored simple and multiple linear regression using different datasets in R. Regression basically helps us understand how one variable affects another, and it can also be used to make predictions.
For the first example, I looked at a dataset withx as the predictor and y as the response. Using the linear model , I used R’s lm() function to find the intercept and slope. The slope told me how much y changes for each one-unit change in x, while the intercept gave the value of y when x = 0. This simple model makes it easy to see the trend in the data and predict y for any given x.Next, I worked with the faithful dataset to predict eruption durations based on the waiting time since the last eruption. Again, the regression model helped me quantify the relationship. Using lm(eruptions ~ waiting, data=faithful) and the predict() function, I estimated the discharge duration for a waiting time of 80 minutes. The positive slope confirmed that longer waiting times tend to lead to longer eruptions, which makes sense intuitively.
For the third part, I explored multiple regression with the mtcars dataset to see how miles per gallon (mpg) depends on displacement (disp), horsepower (hp), and weight (wt). Using lm(mpg ~ disp + hp + wt, data=input), I found coefficients for each predictor. These coefficients show how each car feature affects fuel efficiency while holding the others constant. For instance, heavier cars or cars with higher horsepower tend to have lower mpg, which aligns with what we’d expect in real life.
Finally, I looked at the rmr dataset from the ISwR package to examine metabolic rate versus body weight. Using lm(metabolic.rate ~ body.weight, data=rmr) and predict(), I estimated the metabolic rate for someone weighing 70 kg. The slope of the regression line indicated how much metabolic rate increases per kilogram of body weight, while the intercept represented the theoretical metabolic rate at zero weight.
Comments
Post a Comment