Professional Documents
Culture Documents
PIUS
2022-11-28
#2.Fitseveral simple logistic regression models with fracture as outcome and age,sex,bmi=(weight_kg/hei
#creating a new variable bmi and bind it with the dateset
1
bmi= bmd_9_$weight_kg/(bmd_9_$ height_cmˆ2)
bmd_9_1 = cbind(bmd_9_,bmi)
str(bmd_9_1)
##
## Call:
## glm(formula = fracture ~ age, family = binomial, data = bmd_9_1)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.3290 -1.0699 0.6217 0.8552 1.4446
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 5.01898 1.07675 4.661 3.14e-06 ***
## age -0.06341 0.01583 -4.007 6.15e-05 ***
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 205.27 on 168 degrees of freedom
## Residual deviance: 186.75 on 167 degrees of freedom
## AIC: 190.75
##
## Number of Fisher Scoring iterations: 4
##
## Call:
## glm(formula = fracture ~ sex, family = binomial, data = bmd_9_1)
##
## Deviance Residuals:
2
## Min 1Q Median 3Q Max
## -1.5719 -1.5492 0.8288 0.8466 0.8466
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.84157 0.23925 3.517 0.000436 ***
## sexM 0.05043 0.33710 0.150 0.881078
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 205.27 on 168 degrees of freedom
## Residual deviance: 205.25 on 167 degrees of freedom
## AIC: 209.25
##
## Number of Fisher Scoring iterations: 4
##
## Call:
## glm(formula = fracture ~ bmi, family = binomial, data = bmd_9_1)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.7180 -1.1338 0.6310 0.8163 1.5906
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -4.004 1.212 -3.305 0.00095 ***
## bmi 1990.643 501.959 3.966 7.32e-05 ***
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 205.27 on 168 degrees of freedom
## Residual deviance: 185.52 on 167 degrees of freedom
## AIC: 189.52
##
## Number of Fisher Scoring iterations: 4
##
## Call:
## glm(formula = fracture ~ medication, family = binomial, data = bmd_9_1)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
3
## -1.7712 -1.5486 0.8471 0.8471 1.0842
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.2231 0.6708 0.333 0.739
## medicationGlucocorticoids 1.1119 0.8382 1.326 0.185
## medicationNo medication 0.6172 0.6964 0.886 0.375
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 205.27 on 168 degrees of freedom
## Residual deviance: 203.42 on 166 degrees of freedom
## AIC: 209.42
##
## Number of Fisher Scoring iterations: 4
##
## Call:
## glm(formula = fracture ~ waiting_time, family = binomial, data = bmd_9_1)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.6850 -1.4114 0.7628 0.8208 1.3661
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 1.25668 0.27556 4.560 5.11e-06 ***
## waiting_time -0.01899 0.01028 -1.847 0.0648 .
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 205.27 on 168 degrees of freedom
## Residual deviance: 201.85 on 167 degrees of freedom
## AIC: 205.85
##
## Number of Fisher Scoring iterations: 4
##
## Call:
## glm(formula = fracture ~ bmd, family = binomial, data = bmd_9_1)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.4960 -0.4453 0.2083 0.5191 2.3003
##
4
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -10.607 1.767 -6.002 1.95e-09 ***
## bmd 15.785 2.497 6.321 2.59e-10 ***
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 205.27 on 168 degrees of freedom
## Residual deviance: 116.02 on 167 degrees of freedom
## AIC: 120.02
##
## Number of Fisher Scoring iterations: 6
#a a.Do you think that there is a relationship between the outcome and each of the variables?
#considering the p-value in the above logistic regression models,the p-values of age,bmi and
#3.What's the proportion of respondents who have a fracture? What are the odds of having fracture given
# 4.Fitting a multiple logistic regression model with fracture as outcome and age, sex,bmi medication,
#a.Assess correlation between the 4 variables age, sex,bmi, medication, waiting_time and bmd
bmi= bmd_9_$weight_kg/(bmd_9_$ height_cmˆ2)
bmd_9_1 = cbind(bmd_9_,bmi)
str(bmd_9_1)
5
## $ bmi : num 0.00265 0.00297 0.00251 0.00274 0.00212 ...
## $ fracture : Factor w/ 2 levels "fracture","no fracture": 2 2 2 2 2 2 2 2 2 2 ...
## $ sex_F : int 1 1 0 1 0 0 0 1 0 0 ...
## $ sex_M : int 0 0 1 0 1 1 1 0 1 1 ...
## $ medication_Anticonvulsant : int 1 0 0 0 0 0 0 0 0 0 ...
## $ medication_Glucocorticoids: int 0 0 0 0 0 0 0 0 1 0 ...
## $ medication_No.medication : int 0 1 1 1 1 1 1 1 0 1 ...
## - attr(*, ".internal.selfref")=<externalptr>
cor(bmd_9_2[,c(2,6,5,9:13)])
full_model = glm(fracture~age + sex + bmi +medication + waiting_time +bmd ,data = bmd_9_, family = binom
full_model
##
## Call: glm(formula = fracture ~ age + sex + bmi + medication + waiting_time +
## bmd, family = binomial, data = bmd_9_)
##
## Coefficients:
## (Intercept) age sexM
## -10.390568 -0.015957 -1.005031
## bmi medicationGlucocorticoids medicationNo medication
## 381.283499 1.212862 -0.617993
6
## waiting_time bmd
## -0.006878 16.979549
##
## Degrees of Freedom: 168 Total (i.e. Null); 161 Residual
## Null Deviance: 205.3
## Residual Deviance: 105 AIC: 121
#c
##
## Call:
## glm(formula = fracture ~ +sex + medication + bmd, family = binomial,
## data = bmd_9_1)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.7172 -0.3439 0.1466 0.4884 2.5164
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -11.5445 2.0357 -5.671 1.42e-08 ***
## sexM -1.0743 0.5201 -2.065 0.0389 *
## medicationGlucocorticoids 1.4650 1.1698 1.252 0.2104
## medicationNo medication -0.5083 0.9399 -0.541 0.5886
## bmd 18.1430 2.9031 6.250 4.12e-10 ***
## ---
## Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 205.27 on 168 degrees of freedom
## Residual deviance: 105.98 on 164 degrees of freedom
## AIC: 115.98
##
## Number of Fisher Scoring iterations: 6