Question: R has a great function for fitting and summarizing linear regression models: the lm () function. lm () will fit a linear regression model

R has a great function for fitting and summarizing linear regression models:


R has a great function for fitting and summarizing linear regression models: the lm () function. lm () will fit a linear regression model to data using least squares (or other methods, when specified), and provide many summary statistics. Let's look at some basics of lm (). As we progress through the course, we'll learn to work with more and more of the output of the lm () function. The lm () function may take in several arguments, but only a small number of them are required. The first required argument is the formula : it should be in the following format: response ~ predictor1 + predictor2 + ... + predictorP. If your data are stored in a dataframe (which will often be the case), then the simplest thing to do is specify a second argument, namely data = NameOfDataFrame. Let's use lm () on the training subset of the marketing data, with just facebook as a predictor. Be sure to use the training data (not the entire marketing data). Store your Lm() object in the variable Lm_marketing. After you've fit the model using lm (), clearly write out the fitted model and interpret the parameter estimates.

Step by Step Solution

3.45 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres an example code to fit a linear regression model using the lm function in R assuming the training subset of the marketing data is stored in a da... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!