> knitr::kable(head(credit))
| Score | Years | Sales | Networth | Profit | FLeverage | Industry | RiskLevel |
|---|---|---|---|---|---|---|---|
| 119 | 14 | 1600 | 3400 | 240 | 5.71 | Non-IT | HIGH |
| 103 | 7 | 640 | 180 | 60 | 2.35 | IT | HIGH |
| 126 | 16 | 1120 | 1870 | 450 | 2.34 | Non-IT | HIGH |
| 92 | 6 | 360 | 700 | 110 | 2.15 | Non-IT | HIGH |
| 102 | 6 | 370 | 790 | 45 | 1.96 | IT | HIGH |
| 105 | 24 | 1400 | 1850 | 240 | 1.87 | Non-IT | HIGH |
The objective for this dataset is to identify the factors which influence the credit score of a company. In this dataset, we can see our response variable (y var) is Score and there are 7 other possible predictor variables. Industry and RiskLevel are both categorical data and thus need indicator variables when doing linear regression to identify if they have any influence on Score.
> credit$isIT <- with(credit, ifelse(Industry=="IT", 1, 0))
> credit$isNonIT <- with(credit, ifelse(Industry=="Non-IT", 1, 0))
> credit$isHigh <- with(credit, ifelse(RiskLevel=="HIGH", 1, 0))
> credit$isMedium <- with(credit, ifelse(RiskLevel=="MEDIUM", 1, 0))
> credit$isLow <- with(credit, ifelse(RiskLevel=="LOW", 1, 0))
> normalityTest(~Score, test="shapiro.test", data=credit)
Shapiro-Wilk normality test
data: Score
W = 0.96191, p-value = 0.2321
> with(credit, Hist(Score, scale="frequency", breaks="Sturges",
+ col="darkgray"))
The histogram of Score appears to be normally distributed because it follows the bell curve shape and both tails are low
> Boxplot( ~ Score, data=credit, id=list(method="y"))
The boxplot looks to be very slightly right skewed as the top whisker is larger than the bottom whisker and mean > median. However, after viewing the normality test, histogram and boxplot, it is safe to say that we fail to reject the null hypothesis and the response variable Score is normally distributed.
> summary(credit)
Score Years Sales Networth
Min. : 66.0 Min. : 2.00 Min. : 45.0 Min. : 14
1st Qu.: 95.0 1st Qu.: 6.00 1st Qu.: 175.0 1st Qu.: 220
Median :105.0 Median : 8.00 Median : 640.0 Median : 800
Mean :111.3 Mean :11.24 Mean : 710.7 Mean :1079
3rd Qu.:126.0 3rd Qu.:15.00 3rd Qu.: 850.0 3rd Qu.:1600
Max. :165.0 Max. :28.00 Max. :3200.0 Max. :5600
Profit FLeverage Industry RiskLevel isIT
Min. : 6.0 Min. :0.150 IT :18 HIGH : 9 Min. :0.0000
1st Qu.: 46.0 1st Qu.:0.840 Non-IT:19 LOW :11 1st Qu.:0.0000
Median :110.0 Median :1.240 MEDIUM:17 Median :0.0000
Mean :180.5 Mean :1.376 Mean :0.4865
3rd Qu.:265.0 3rd Qu.:1.630 3rd Qu.:1.0000
Max. :720.0 Max. :5.710 Max. :1.0000
isNonIT isHigh isMedium isLow
Min. :0.0000 Min. :0.0000 Min. :0.0000 Min. :0.0000
1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.0000
Median :1.0000 Median :0.0000 Median :0.0000 Median :0.0000
Mean :0.5135 Mean :0.2432 Mean :0.4595 Mean :0.2973
3rd Qu.:1.0000 3rd Qu.:0.0000 3rd Qu.:1.0000 3rd Qu.:1.0000
Max. :1.0000 Max. :1.0000 Max. :1.0000 Max. :1.0000
After viewing the summary statistics, it seems most of the variables are slightly right skewed with mean > median but more testing needs to be done to see if any of these variables influence Score.
> scatterplot(Score~Sales, regLine=FALSE, smooth=FALSE, boxplots=FALSE,
+ data=credit)
The scatterplot between Score and Sales shows a strong positive correlation between the variables. Sales could be a good estimator of Score, but more analysis is needed.
> scatterplot(Score~Profit, regLine=FALSE, smooth=FALSE, boxplots=FALSE,
+ data=credit)
The scatterplot between Score and Profit shows a strong positive correlation between the variables. Profit could be a good estimator of Score, but more analysis is needed.
> scatterplot(Score~Networth, regLine=FALSE, smooth=FALSE, boxplots=FALSE,
+ data=credit)
The scatterplot between Score and Networth shows a strong positive correlation between the variables. Networth could be a good estimator of Score, but more analysis is needed.
Frequency table:
RiskLevel
Industry HIGH LOW MEDIUM
IT 2 5 11
Non-IT 7 6 6
Warning in chisq.test(.Table, correct = FALSE): Chi-squared approximation may be
incorrect
Pearson's Chi-squared test
data: .Table
X-squared = 4.3154, df = 2, p-value = 0.1156
The contingency table shows the tabular representation of our categorical data (RiskLevel and Industry). The frequencies and p-value of these variables are low and thus may not mean they are good estimators in analysis.
> RegModel.1 <- lm(Score~FLeverage+isHigh+isIT+Networth+Profit+Sales+Years,
+ data=credit)
> summary(RegModel.1)
Call:
lm(formula = Score ~ FLeverage + isHigh + isIT + Networth + Profit +
Sales + Years, data = credit)
Residuals:
Min 1Q Median 3Q Max
-25.1741 -8.7140 0.7981 8.1980 25.1072
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 98.508964 9.217589 10.687 1.43e-11 ***
FLeverage -4.901261 3.818160 -1.284 0.209
isHigh 1.311580 7.984201 0.164 0.871
isIT -7.061991 7.418803 -0.952 0.349
Networth 0.006605 0.008407 0.786 0.438
Profit 0.039517 0.032093 1.231 0.228
Sales 0.001388 0.016745 0.083 0.934
Years 0.661317 0.368333 1.795 0.083 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 13.51 on 29 degrees of freedom
Multiple R-squared: 0.7431, Adjusted R-squared: 0.6811
F-statistic: 11.98 on 7 and 29 DF, p-value: 4.443e-07
This model has an adjusted R-squared value of 0.68 which means that there is a strong correlation between the variables in this model and Score. To note, Years is the only significant variable at the 0.10 level, while the p-value of the other variables is quite high.
> confint(RegModel.1)
2.5 % 97.5 %
(Intercept) 79.65687726 117.36104988
FLeverage -12.71027439 2.90775210
isHigh -15.01794530 17.64110476
isIT -22.23514630 8.11116408
Networth -0.01058953 0.02380003
Profit -0.02611987 0.10515346
Sales -0.03285905 0.03563558
Years -0.09200794 1.41464153
When looking at the confidence intervals, there is a possibility of 0 being between the variables on each side of the distribution. For this reason, we fail to reject the null hypothesis.
> RegModel.2 <-
+ lm(Score~FLeverage+isLow+isMedium+isNonIT+Networth+Profit+Sales+Years,
+ data=credit)
> summary(RegModel.2)
Call:
lm(formula = Score ~ FLeverage + isLow + isMedium + isNonIT +
Networth + Profit + Sales + Years, data = credit)
Residuals:
Min 1Q Median 3Q Max
-23.9361 -8.4098 0.4851 9.1823 24.2895
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 90.206697 13.000194 6.939 1.52e-07 ***
FLeverage -3.633178 4.456049 -0.815 0.422
isLow 2.822377 10.847625 0.260 0.797
isMedium -0.885408 8.113017 -0.109 0.914
isNonIT 7.736566 7.598915 1.018 0.317
Networth 0.005505 0.008722 0.631 0.533
Profit 0.039847 0.032477 1.227 0.230
Sales 0.002431 0.017041 0.143 0.888
Years 0.609820 0.383444 1.590 0.123
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 13.67 on 28 degrees of freedom
Multiple R-squared: 0.7461, Adjusted R-squared: 0.6735
F-statistic: 10.28 on 8 and 28 DF, p-value: 1.401e-06
This model has an adjusted R-squared value of 0.67 which means that there is a strong correlation between the variables in this model and Score. To note, Years is not a significant variable in this model, and the p-value of the other variables is quite high. Additionally, the adjusted R-squared value has decreased in this model where the only changes were to include the other categorical variables isLow, isMedium and isNonIT. This could mean that having a HIGH risk and being in the IT Industry has slightly more influnce on Score than their counterparts.
> confint(RegModel.2)
2.5 % 97.5 %
(Intercept) 63.57700607 116.83638788
FLeverage -12.76097986 5.49462459
isLow -19.39797556 25.04272973
isMedium -17.50416993 15.73335451
isNonIT -7.82910628 23.30223919
Networth -0.01236078 0.02337160
Profit -0.02668004 0.10637306
Sales -0.03247628 0.03733778
Years -0.17562931 1.39526845
When looking at the confidence intervals, there is a possibility of 0 being between the variables on each side of the distribution. For this reason, we fail to reject the null hypothesis.
> RegModel.3 <- lm(Score~Networth+Profit+Sales, data=credit)
> summary(RegModel.3)
Call:
lm(formula = Score ~ Networth + Profit + Sales, data = credit)
Residuals:
Min 1Q Median 3Q Max
-26.762 -10.573 -0.117 6.016 33.724
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 92.093819 3.633116 25.348 < 2e-16 ***
Networth 0.005322 0.007894 0.674 0.50489
Profit 0.080132 0.026748 2.996 0.00516 **
Sales -0.001368 0.016273 -0.084 0.93349
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 14.27 on 33 degrees of freedom
Multiple R-squared: 0.6737, Adjusted R-squared: 0.6441
F-statistic: 22.71 on 3 and 33 DF, p-value: 3.676e-08
When looking at our third regression model, the explanatory variables from our scatterplots earlier have an adjusted R-squared value of 0.64. This R-squared value is lower than the R-squared value of our previous two models and we are observing an interaction effect. The interaction effect is that all the variables in this dataset combined have a significantly larger effect on Score than compared to the sum of the variables Sales, Profit and Networth. Despite the interaction effect, Profit does seem to be the best estimator of Score and is significant at the 0.01 level.
The best possible model of finding which variables influence price would be in the first regression model which included all the variables and the explanatory variables isHigh and isIT. This model produced the highest adjusted R-squared value of 0.68 meaning it has the strongest correlation between all the variables. When completing regression for the next two models, we observed that isHigh and isIT have slightly more influence on Score than isLow, isMedium and isNonIT. Then when we tested our third regression model which included only Profit, Sales and Networth, we found that there is an interaction effect present. The interaction effect is that all the variables in this dataset combined have a significantly larger effect on Score than compared to the sum of the variables Sales, Profit and Networth. For the confidence intervals in all models we fail to reject the null hypothesis and the best model to use is the first regression model.