Reading Data
# Read data from csv into a variable called 'data'
data <- read.csv("F:/COURSERA COURSES/Regression Modeling in Practice/DataSetW.csv")
Attach the dataset
# Attach data variables
attach(data)
# Display the data summary
summary(data)
## YEAR ENROLL UNEMPRATE
## Min. : 1 Min. : 5501 Min. : 5.700
## 1st Qu.: 8 1st Qu.:10167 1st Qu.: 7.000
## Median :15 Median :14395 Median : 7.500
## Mean :15 Mean :12707 Mean : 7.717
## 3rd Qu.:22 3rd Qu.:14969 3rd Qu.: 8.200
## Max. :29 Max. :16081 Max. :10.100
Building Simple Linear Regression Model
# Predict the response variable Enrollments (ENROLL) using the predictor variable
# unemployment rate (UNEMPRATE)
SLM_ENROLL <- lm(ENROLL ~ UNEMPRATE, data = data)
# Displaying The Linear Model
SLM_ENROLL
##
## Call:
## lm(formula = ENROLL ~ UNEMPRATE, data = data)
##
## Coefficients:
## (Intercept) UNEMPRATE
## 3957 1134
Summarizing the Model
# Display information about the linear model
summary(SLM_ENROLL)
##
## Call:
## lm(formula = ENROLL ~ UNEMPRATE, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7640.0 -1046.5 602.8 1934.3 4187.2
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3957.0 4000.1 0.989 0.3313
## UNEMPRATE 1133.8 513.1 2.210 0.0358 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3049 on 27 degrees of freedom
## Multiple R-squared: 0.1531, Adjusted R-squared: 0.1218
## F-statistic: 4.883 on 1 and 27 DF, p-value: 0.03579
Discussion
The results of the linear regression model indicated that Unemployement rate (Beta=1134, p=0.0358)
was significantly and positively associated with number of enrollments at the university.
But low value of R-square also suggests that the distribution is highly scattered (high deviation)
around the regression line.
Sample Prediction
# what is the expected enrollment (ENROLL) for a given year's unemployment rate (UNEMPRATE)?
# Year = 2015
# UNEMPRATE = 10%
# Then, ENROLL is:
3957 + 1134 * 10
## [1] 15297
Prediction Result Summary
The predicted enrollment at the university, for a given 10% unemployment rate, is 15,297 students in 2015.