0
0
R Programmingprogramming~30 mins

Linear regression (lm) in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Simple Linear Regression with lm in R
📖 Scenario: You are a data analyst at a small company. You want to understand how advertising spending affects sales. You have data on advertising budgets and sales for several months.
🎯 Goal: Build a simple linear regression model using lm in R to predict sales based on advertising spending.
📋 What You'll Learn
Create a data frame with advertising and sales data
Create a variable for the formula to use in the model
Use the lm function to build the linear regression model
Print the summary of the model to see the results
💡 Why This Matters
🌍 Real World
Linear regression is used in business to understand relationships between variables, like advertising spend and sales.
💼 Career
Data analysts and data scientists use linear regression to build predictive models and make data-driven decisions.
Progress0 / 4 steps
1
Create the data frame
Create a data frame called ad_data with two columns: advertising and sales. Use these exact values: advertising = c(10, 20, 30, 40, 50), sales = c(15, 25, 35, 45, 55).
R Programming
Need a hint?

Use data.frame() to create the data frame with the exact column names and values.

2
Create the formula variable
Create a variable called model_formula that stores the formula sales ~ advertising.
R Programming
Need a hint?

Use the tilde ~ to create the formula for the model.

3
Build the linear regression model
Use the lm function to create a linear model called model using model_formula and the data frame ad_data.
R Programming
Need a hint?

Use lm(formula, data = ...) to build the model.

4
Print the model summary
Print the summary of the linear model model using the summary() function.
R Programming
Need a hint?

Use print(summary(model)) to see the details of the regression.