Question: Use R - software please We will use a data set that is included with the R package called mtcars, which has measures on 3
Use Rsoftware please We will use a data set that is included with the R package called mtcars, which has measures on cars from Motor Trend magazine from the model years.
If you type mtcars in the R console window, you will see an explanation of the data set displayed in the Help window.
You can view the first view rows of the data set by typing headmtcars in the console window.
We will estimate a regression model where we try to explain the miles per gallon measure abbreviated as mpg using the engine size of the car in cubic inches, known as displacement and abbreviated as disp. In other words, mpg will be the response variable and disp will be the explanatory variable.
Steps:
Issue the command attachmtcars so that the variables in the data set are in the search path when you issue a command; this allows you to refer to the variables directly. Otherwise, you would have to write mtcars$mpg and mtcars$disp to refer to the variables.
Use the plot function to create a scatter plot with mpg our response variable on the vertical axis and disp our explanatory variable on the horizontal axis. Remember to include your names in the main title of the plot using the main parameter.
Use the lm function which stands for linear model to estimate a regression equation with mpg as the response variable and disp as the explanatory variable. Remember to use the tilde special character ~ between the response variable and explanatory variable. The lm function returns the results as an object that you can assign to a variable such as result as illustrated in the chapter R software notes.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
