Date post: | 17-Jan-2016 |
Category: |
Documents |
Upload: | colleen-parsons |
View: | 216 times |
Download: | 1 times |
A preliminary exploration into the Binomial Logistic Regression Models in
R and their potential application
Andrew Trant
PPS Arctic - Labrador Highlands Research Group
One presentation in two parts
Part 1 (today)
-comparing binomial logistical regressions in R and Minitab
-binomial GLMs and Odds Ratios
Part 2 (next time)
-using GLMs in conservation biology
-an exploration of the past
Start off small…..
before …and after
type Nrelease NrecapTypical 201 34Melanism 601 205
Kettlewell, H B D (1956)
Research Question:Are the odds of survival higher for dark form (Melanic) than the light form (Typical)?
Odds = e (o) + e (Type) + error (link = logit)
e ( o) = survival odds, typical form
e ( Type) = odds ratio, melanic relative to typical form
e ( o + Type) = survival odds, melanic form
In Minitab:
Predictor Coef SE Coef z P Odds RatioConstant -1.5916 0.1881 -6.54 0.000Type - Melanic 0.9332 0.2069 4.51 0.000 2.54
Log-Likelihood: -477.062Test that all slopes are zero: G=22.977, DF =1, P-value=0.000
95% CILower Upper
1.70 3.81
In R…
glm(formula = Nrecap/Nrel ~ type, family = binomial, data = moth,weights = Nrel) Call:
Coefficients:(Intercept) typeTyp -0.6584 -0.9332
Degrees of Freedom: 1 Total (i.e. Null); 0 ResidualNull Deviance: 22.98 Residual Deviance: 1.592e-13 AIC: 15.93
> summary(moth)
Deviance Residuals: [1] 0 0
Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -0.65840 0.08604 -7.652 1.98e-14 ***typeTyp -0.93323 0.20689 -4.511 6.46e-06 ***---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 2.2977e+01 on 1 degrees of freedomResidual deviance: 1.5921e-13 on 0 degrees of freedomAIC: 15.929
Number of Fisher Scoring iterations: 3
In Minitab:
Predictor Coef SE Coef z P Odds RatioConstant -1.5916 0.1881 -6.54 0.000Type - Melanic 0.9332 0.2069 4.51 0.000 2.54
Log-Likelihood: -477.062Test that all slopes are zero: G=22.977, DF =1, P-value=0.000
95% CILower Upper
1.70 3.81
In R…Estimate Std. Error z-value Pr(>|z|)
(Intercept) -0.6584 0.08604 -7.652 1.98e-14 ***type Typical -0.93323 0.20689 -4.511 6.46e-06 ***
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Odds = e (o) + e (Type) + error
BUTR assumes that o = melanistic NOT typical
>exp(-0.6584) = 0.5176e ( o) = survival odds, melanistic form R:
Estimate Std. Error z-value Pr(>|z|)(Intercept) -0.6584 0.08604 -7.652 1.98e-14 ***
type Typical -0.93323 0.20689 -4.511 6.46e-06 ***
e ( o + Type) = survival odds, melanic form MINITAB:
Predictor Coef SE Coef z P Odds RatioConstant -1.5916 0.1881 -6.54 0.000Type - Melanic 0.9332 0.2069 4.51 0.000 2.54
Log-Likelihood: -477.062Test that all slopes are zero: G=22.977, DF =1, P-value=0.000
95% CILower Upper
1.70 3.81
>exp(-1.5916+0.9332) = 0.5177
Odds = e (o) + e (Type) + error
BUTR assumes that o = melanistic NOT typical
e ( o) = survival odds, melanistic form
>exp(-0.6584) = 0.5176R:
Estimate Std. Error z-value Pr(>|z|)(Intercept) -0.6584 0.08604 -7.652 1.98e-14 ***
type Typical -0.93323 0.20689 -4.511 6.46e-06 ***
e ( o + Type) = survival odds, melanic form MINITAB:
Predictor Coef SE Coef z P Odds RatioConstant -1.5916 0.1881 -6.54 0.000Type - Melanic 0.9332 0.2069 4.51 0.000 2.54
Log-Likelihood: -477.062Test that all slopes are zero: G=22.977, DF =1, P-value=0.000
95% CILower Upper
1.70 3.81
>exp(-1.5916+0.9332) = 0.5177
SAME(ish)
R:
Estimate Std. Error z-value Pr(>|z|)(Intercept) -0.6584 0.08604 -7.652 1.98e-14 ***
type Typical -0.93323 0.20689 -4.511 6.46e-06 ***
MINITAB: >exp(0.9332) = 2.5426
Predictor Coef SE Coef z P Odds RatioConstant -1.5916 0.1881 -6.54 0.000Type - Melanic 0.9332 0.2069 4.51 0.000 2.54
Log-Likelihood: -477.062Test that all slopes are zero: G=22.977, DF =1, P-value=0.000
95% CILower Upper
1.70 3.81
e ( Type) = odds ratio
Odds Ratio
>exp(-0.9332) = 0.3933
>1/exp(-0.9332)=2.5426
Calculating 95% Confidence Intervals
CI = e Estimate±(SE*z-value)
>exp(0.9332±(0.2069*1.96))
Lower = 1.694989
Upper= 3.814174
You have reached the end of part one
But there is a preliminary stab at part two
Dave’s Barnacles
Tetraclita squamosa
Acanthia sp.
>avthickathole<-glm(formula=Npartial/N~AvThickAtHole,family=binomial, weights=N,data=test)
ThickAtHoleN Nlive Npartial Odds ln(Odds) w/wbar ln(w/wbar)0.75 4 0 0 0 * 0 *1.25 5 3 2 1.5 0.40547 1.4 0.336471.75 12 4 5 0.5 -0.69315 0.77778 -0.251312.25 27 9 11 0.5 -0.69315 0.77778 -0.251312.75 32 5 7 0.18519 -1.6864 0.36458 -1.0093.25 25 10 16 0.66667 -0.40547 0.93333 -0.068993.75 17 14 14 4.66667 1.54045 1.92157 0.653144.25 19 14 18 2.8 1.02962 1.7193 0.541924.75 4 3 4 3 1.09861 1.75 0.559625.75 2 1 2 1 0 1.16667 0.15415
Average thickness at hole
LMGLM
Average thickness at hole
General Linear Model:>lm.avthickathole<-lm(w.wbar~AvThickAtHole,data=test)
Estimate Std. Error t value Pr(>|t|)(Intercept) 0.37983 0.39358 0.965 0.3628AvThickAtHole 0.02368 0.01194 1.983 0.0827
Generalized Linear Model:>avthickathole<-glm(formula=Npartial/N~AvThickAtHole,family=binomial, weights=N,data=test)
Estimate Std. Error z value Pr(>|z|)(Intercept) -3.40918 0.72386 -4.71 2.48e-06 ***AvThickAtHole 0.12493 0.02483 5.031 4.88e-07 ***
Odds Ratio: 1.13 (remember…exp(0.1249))
Average thickness residuals plots
LMGLM
QuickTime™ and aTIFF (Uncompressed) decompressor
are needed to see this picture.
QuickTime™ and aTIFF (Uncompressed) decompressor
are needed to see this picture.
Summary of model comparison…GLM vs LM
Trait LM (p-value) GLM (p-value) more sensitive?AvThickAtHole 0.0827 4.88e-07 *** GLM
Height of barnacle
General Linear Model:>lm(w.wbar ~ Ht, data = height)
Generalized Linear Model: >glm.height<-glm(Npartial/N~Ht,family=binomial,weights=N,data=height))
Odds Ratio: 1.26
Estimate Std. Error z value Pr(>|z|)(Intercept) -3.40988 1.16226 -2.934 0.00335 **Ht 0.2431 0.07862 3.092 0.00199 **
Estimate Std. Error t value Pr(>|t|)(Intercept) -0.4576 0.4408 -1.038 0.3263Ht 0.09389 0.02951 3.182 0.0112 *
Height of barnacle residuals plots
QuickTime™ and aTIFF (Uncompressed) decompressor
are needed to see this picture.
QuickTime™ and aTIFF (Uncompressed) decompressor
are needed to see this picture.
LMGLM
Summary of model comparisons…GLM vs LM
Trait LM (p-value) GLM (p-value) more sensitive?AvThickAtHole 0.0827 4.88e-07 *** GLM
Height 0.0112 * 0.00199 ** GLM
Max Diameter
General Linear Model:>lm(w.wbar ~ MaxDiam, data = maxdiam)
Generalized Linear Model:>glm(Npartial/N ~ MaxDiam, family = binomial, data = maxdiam,weights = N)
Odds Ratio: 1.073
Estimate Std. Error t value Pr(>|t|)(Intercept) 0.2427 0.50788 0.478 0.642MaxDiam 0.03485 0.02551 1.366 0.199
Estimate Std. Error z value Pr(>|z|)(Intercept) -1.37102 1.12028 -1.224 0.221MaxDiam 0.07833 0.05714 1.371 0.17
Max Diameter residuals plots
LMGLM
QuickTime™ and aTIFF (Uncompressed) decompressor
are needed to see this picture.
QuickTime™ and aTIFF (Uncompressed) decompressor
are needed to see this picture.
Summary of model comparisons…GLM vs LM
Trait LM (p-value) GLM (p-value) more sensitive?AvThickAtHole 0.0827 4.88e-07 *** GLM
Height 0.0112 * 0.00199 ** GLMMax Diameter 0.199 0.17 GLM
Okay, that’s it…