lOMoARcPSD|11700591
ISYE 6414 HOMEWORK 4 PEER ASSESSMENT SOLUTIONS ISYE 6414 INSTRUCTOR FALL 2022
Peer Grader Guidance Please review the student expectations for peer review grading and peer review comments. Overall, we ask that you score with accuracy. When grading your peers, you will not only learn how to improve your future homework submissions but you will also gain deeper understanding of the concepts in the assignments. When assigning scores, consider the responses to the questions given your understanding of the problem and using the solutions as a guide. Moreover, please give partial credit for a concerted effort, but also be thorough. Add comments to your review, particularly when deducting points, to explain why the student missed the points. Ensure your comments are specific to questions and the student responses in the assignment.
Background The owner of a company would like to be able to predict whether employees will stay with the company or leave. The data contains information about various characteristics of employees. See below for the description of these characteristics.
Data Description The data consists of the following variables: 1. Age.Group: 1-9 (1 corresponds to teen, 2 corresponds to twenties, etc.) (numerical) 2. Gender: 1 if male, 0 if female (numerical) 3. Tenure: Number of years with the company (numerical) 4. Num.Of.Products: Number of products owned (numerical) 5. Is.Active.Member: 1 if active member, 0 if inactive member (numerical) 6. Staying: Fraction of employees that stayed with the company for a given set of predicting variables
Read the data # import the data data = read.csv("hw4_data.csv", header=TRUE, fileEncoding="UTF-8-BOM") data$Staying = data$Stay/data$Employees head(data)
1
lOMoARcPSD|11700591
# Age.Group Gender Tenure Num.Of.Products Is.Active.Member Stay Employees ## 1 2 1 3 1 0 5 11 ## 2 2 1 4 1 0 5 10 ## 3 2 1 4 1 1 2 13 ## 4 2 0 7 1 0 3 10 ## 5 2 1 7 1 0 2 14 ## 6 2 0 4 2 0 4 12 # Staying # 1 0.4545455 # 2 0.5000000 # 3 0.1538462 # 4 0.3000000 # 5 0.1428571 # 6 0.3333333
Question 1: Fitting a Model - 6 pts Fit a logistic regression model using Staying as the response variable with Num.Of.Products as the predictor and logit as the link function. Call it model1. (a) 2 pts - Display the summary of model1. What are the model parameters and estimates? Option 1 (Num.Of.Products treated as numeric): # Create model1 model1 = glm(Staying ~ Num.Of.Products, data=data, family= summary(model1) ## # Call: # glm(formula = Staying ~ Num.Of.Products, family = "binomial", # data = data, weights = Employees) ## ## Deviance Residuals: ## Min 1Q Median 3Q Max ## -4.2827 -1.4676 -0.1022 1.4490 4.7231 ## ## Coefficients: ## Estimate Std. Error z value Pr(>|z|) ## (Intercept) 2.1457 0.1318 16.27 <2e-16 *** ## Num.Of.Products -1.7668 0.1031 -17.13 <2e-16 *** ## --## Signif. codes: 0 0.001 0.01 0.05 . 0.1 1 ## # (Dispersion parameter for binomial family taken to be 1) # # Null deviance: 981.04 on 157 degrees of freedom # Residual deviance: 632.04 on 156 degrees of freedom # AIC: 1056.8 ## ## Number of Fisher Scoring iterations: 4 The model parameters are β0 and β1 and their estimates are: 2 Downloaded by Answerdone (arshadhussain57172@gmail.com)
, weights=Employees)
lOMoARcPSD|11700591
ˆ β0
ˆ
=21457 .
= 1 7668
β1−.
2
Note that since there are no error terms, there is no parameter for the variance of the error (σ ). Option 2 (Num.Of.Products treated as categorical): # Create model1 data$Num.Of.Products.Cat<-as.factor(data$Num.Of.Products) model1_categorical = glm(Staying ~ Num.Of.Products.Cat, data=data, family= , weights=Employees) summary(model1_categorical) ## # Call: # glm(formula = Staying ~ Num.Of.Products.Cat, family = "binomial", # data = data, weights = Employees) ## ## Deviance Residuals: ## Min 3Q Max 1Q Median ## -4.2827 -1.4676 -0.1022 1.4490 4.7231 ## ## Coefficients: ## Estimate Std. Error z value Pr(>|z|) ## (Intercept) 0.37886 0.04743 7.988 1.37e-15 *** ## Num.Of.Products.Cat2 -1.76683 0.10313 -17.132 < 2e-16 *** ## --## Signif. codes: 0 0.001 0.01 0.05 . 0.1 1 ## # (Dispersion parameter for binomial family taken to be 1) # # Null deviance: 981.04 on 157 degrees of freedom # Residual deviance: 632.04 on 156 degrees of freedom # AIC: 1056.8 ## ## Number of Fisher Scoring iterations: 4 The model parameters are β0 and β1 and their estimates are: ˆ
= 0 37886
β0
ˆ
.
= 1 7668
β1−.
Note that since there are no error terms, there is no parameter for the variance of the error (ˆσ). Note: Only one correct option is needed for credit. The above are di fferent examples of possible answers.
(b) 2 pts - Write down the equation for the odds of staying. Option 1 (Num.Of.Products treated as numeric):
p
staying
p
= e2.1457 − 1.7668∗
X
N um.Of.P roducts
1 − staying Option 2 (Num.Of.Products treated as categorical):
p
1−
staying
p
= e0.37886 − 1.7668∗
staying
3
X
N um.Of.P roducts.C at2
lOMoARcPSD|11700591
Note: Only one correct option is needed for credit. The above are di fferent examples of possible answers.
(c) 2 pts - Provide a meaningful interpretation for the coe fficient for Num.Of.Products with respect to the log-odds of staying and the odds of staying. Option 1 (Num.Of.Products treated as numeric): Log-odds: • An one unit increase in Num.Of.Products decreases the log-odds of staying by 1.7668. Odds: • An one unit increase in Num.Of.Products decreases the odds of staying by 82.91%. 1−e−
1.7668
= 0.8291
• An one unit increase in Num.Of.Products changes the odds of staying by a factor of 0.1709. e− = 0.1709
1.7668
Note: Only one correct interpretation with respect to the odds of staying is needed for credit. Option 2 (Num.Of.Products treated as categorical): Log-odds: • For an employee with Num.Of.ProductsCat2 vs. an employee with Num.Of.ProductsCat1, the logodds of staying decreases by 1.7668. Odds: • The odds of staying for an employee with Num.Of.ProductsCat2 is 82.91% lower than that of an 1.7668 employee with Num.Of.ProductsCat1. 1 − e− = 0.8291 • The odds of staying for an employee with Num.Of.ProductsCat2 changes by a factor of 0.1709 1.7668 relative to an employee with Num.Of.ProductsCat1. e− = 0.1709. Note: Only one correct interpretation with respect to the odds of staying is needed for credit. Note: Only one correct option is needed for credit. The above are di fferent examples of possible answers.
Question 2: Inference - 9 pts (a) 3 pts - Using model1, find a 90% confidence interval for the coe fficient for Num.Of.Products. • Option 1: # Calculate it by hand cat("[",-1.7668-1.645*0.1031,",",-1.7668+1.645*0.1031,"]") #
[ -1.936399 , -1.597201 ] • Option 2:
4
lOMoARcPSD|11700591
# Have R calculate the confidence interval using the Wald interval confint.default(model1, "Num.Of.Products", level=0.9) ## 5 % 95 % ## Num.Of.Products -1.936459 -1.597197 • Option 3:
# Have R calculate the confidence interval using profile-likelihood confint(model1, "Num.Of.Products", level=0.9) ## Waiting for profiling to be done... ## 5 % 95 % ## -1.938361 -1.598965 The 90% confidence interval for Num.Of.Products is ~ (-1.94,-1.60). Note: Only one correct option is needed for credit. The above are different examples of possible answers. (b) 3 pts - Is model1 significant overall? How do you come to your conclusion? We will use a chi-square test to compare the fitted model to the null model. # Calculate overall significance 1-pchisq((model1$null.dev - model1$deviance), (model1$df.null - model1$df.resid)) ## [1] 0 The p-value is very close to zero, indicating that the model is significant overall. (c) 3 pts - Which coefficients are significantly nonzero at the 0.01 significance level? Which are significantly negative? Why? We look at the estimates and p-values given in the model summary. We can see that the coefficients associated to the intercept and Num.Of.Products are significantly nonzero with p-values very close to zero. To test for significantly negative coefficients, if the estimate is negative, and half the given p-value is below 0.01, then the p-value is significantly negative. The estimate for Num.Of.Products is negative, and the corresponding p-value is very close to zero. Half of the p-value of Num.Of.Products is still less than 0.01, indicating that Num.Of.Products is significantly negative.
Question 3: Goodness of fit - 9 pts (a) 3.5 pts - Perform goodness of fit hypothesis tests using both deviance and Pearson residuals. What do you conclude? Explain the differences, if any, between these findings and what you found in Question 2b.
5