Linear Regression using R

Course Outline

1) Simple Linear Regression

Example 1

modelContoh <- lm(Sales ~ Sqft, data = Data)                 # lm() function = produce simple linear regression (SLR)

summary(modelContoh)                                                    # summary() function = produce summary for SLR

anova(modelContoh)                                                          # anova() function = produce ANOVA table

Simple Linear Regression (Alternative)

There are several other R packages that can be used to produce Simple Linear Regression (SLR):

olsrr - Tools for Building OLS Regression Models


Example 1

install.packages("olsrr")                                 # install package "olsrr"

library(olsrr)                                                    # load package "olsrr"

ols_regress(Sales ~ Sqft, data = Data)        # ols_regress() function = produce SLR model

2) Multiple Linear Regression (MLR)

Example 1

modelContoh2 <- lm(Sales ~ Sqft + Bedroom + Bathroom + Garage + LotSize, data = Data)  # lm() function = produce MLR

summary(modelContoh2)                                                    # summary() function = produce summary for SLR

anova(modelContoh2)                                                          # anova() function = produce ANOVA table


Example 2

library(olsrr)                                                    # load package "olsrr"

ols_regress(Sales ~ Sqft + Bedroom + Bathroom + Garage + LotSize, data = Data)