Last data update: 2014.03.03
|
R: titanicgrp
titanicgrp | R Documentation |
titanicgrp
Description
The data is an grouped version of the 1912 Titanic passenger survival
log,
Usage
data(titanicgrp)
Format
A data frame with 12 observations on the following 5 variables.
survive number of passengers who survived
cases number of passengers with same pattern of covariates
age 1=adult; 0=child
sex 1=male; 0=female
class ticket class 1= 1st class; 2= second class; 3= third class
Details
titanicgrp is saved as a data frame.
Used to assess risk ratios
Source
Found in many other texts
References
Hilbe, Joseph M (2015), Practical Guide to Logistic Regression, Chapman & Hall/CRC.
Hilbe, Joseph M (2014), Modeling Count Data, Cambridge University Press.
Hilbe, Joseph M (2007, 2011), Negative Binomial Regression, Cambridge University Press.
Hilbe, Joseph M (2009), Logistic Regression Models, Chapman & Hall/CRC.
Examples
library(MASS) # if not automatically loaded
# LOGISTIC REGRESSION
library(LOGIT)
data(titanicgrp)
tg <- titanicgrp
head(tg)
tg$died <- tg$cases - tg$survive
summary(mylr <- glm( cbind(survive, died) ~ age + sex + factor(class),
family=binomial, data=tg))
toOR(mylr)
P__disp(mylr)
# SCALED LOGISTIC REGRESSION
summary(myqr <- glm( cbind(survive, died) ~ age + sex + factor(class),
family=quasibinomial, data=tg))
toOR(myqr)
# POISSON REGRESSION
# library(COUNT)
data(titanicgrp)
titanicgrp$class <- as.factor(titanicgrp$class)
titanicgrp$logcases <- log(titanicgrp$cases)
glmpr <- glm(survive ~ age + sex + class + offset(logcases), family= poisson, data=titanicgrp)
summary(glmpr)
exp(coef(glmpr))
#lcases <- log(titanicgrp$cases)
#nb2o <- nbinomial(survive ~ age + sex + factor(class),
# formula2 =~ age + sex,
# offset = lcases,
# mean.link="log",
# scale.link="log_s",
# data=titanicgrp)
#summary(nb2o)
#exp(coef(nb2o))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(LOGIT)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/LOGIT/titanicgrp.rd_%03d_medium.png", width=480, height=480)
> ### Name: titanicgrp
> ### Title: titanicgrp
> ### Aliases: titanicgrp
> ### Keywords: datasets
>
> ### ** Examples
>
> library(MASS) # if not automatically loaded
>
> # LOGISTIC REGRESSION
> library(LOGIT)
> data(titanicgrp)
> tg <- titanicgrp
> head(tg)
survive cases age sex class
1 1 1 child women 1st class
2 13 13 child women 2nd class
3 14 31 child women 3rd class
4 5 5 child man 1st class
5 11 11 child man 2nd class
6 13 48 child man 3rd class
> tg$died <- tg$cases - tg$survive
> summary(mylr <- glm( cbind(survive, died) ~ age + sex + factor(class),
+ family=binomial, data=tg))
Call:
glm(formula = cbind(survive, died) ~ age + sex + factor(class),
family = binomial, data = tg)
Deviance Residuals:
Min 1Q Median 3Q Max
-4.232 -2.365 1.038 3.180 4.362
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.0619 0.2980 10.275 < 2e-16 ***
ageadults -1.0556 0.2427 -4.350 1.36e-05 ***
sexman -2.3695 0.1453 -16.313 < 2e-16 ***
factor(class)2nd class -1.0106 0.1949 -5.184 2.17e-07 ***
factor(class)3rd class -1.7664 0.1707 -10.347 < 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: 581.40 on 11 degrees of freedom
Residual deviance: 110.84 on 7 degrees of freedom
AIC: 157.77
Number of Fisher Scoring iterations: 5
> toOR(mylr)
or delta zscore pvalue exp.loci. exp.upci.
(Intercept) 21.3677 6.3677 10.2746 0 11.9150 38.3196
ageadults 0.3480 0.0844 -4.3502 0 0.2163 0.5599
sexman 0.0935 0.0136 -16.3129 0 0.0704 0.1243
factor(class)2nd class 0.3640 0.0710 -5.1841 0 0.2484 0.5334
factor(class)3rd class 0.1710 0.0292 -10.3468 0 0.1223 0.2389
> P__disp(mylr)
Pearson Chi2 = 100.8828
Dispersion = 14.41183
>
> # SCALED LOGISTIC REGRESSION
> summary(myqr <- glm( cbind(survive, died) ~ age + sex + factor(class),
+ family=quasibinomial, data=tg))
Call:
glm(formula = cbind(survive, died) ~ age + sex + factor(class),
family = quasibinomial, data = tg)
Deviance Residuals:
Min 1Q Median 3Q Max
-4.232 -2.365 1.038 3.180 4.362
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.0619 1.1313 2.706 0.03035 *
ageadults -1.0556 0.9212 -1.146 0.28949
sexman -2.3695 0.5514 -4.297 0.00358 **
factor(class)2nd class -1.0106 0.7400 -1.366 0.21433
factor(class)3rd class -1.7664 0.6481 -2.725 0.02953 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for quasibinomial family taken to be 14.41183)
Null deviance: 581.40 on 11 degrees of freedom
Residual deviance: 110.84 on 7 degrees of freedom
AIC: NA
Number of Fisher Scoring iterations: 5
> toOR(myqr)
or delta zscore pvalue exp.loci. exp.upci.
(Intercept) 21.3677 24.1736 2.7065 0.0068 2.3269 196.2167
ageadults 0.3480 0.3206 -1.1459 0.2518 0.0572 2.1168
sexman 0.0935 0.0516 -4.2971 0.0000 0.0317 0.2756
factor(class)2nd class 0.3640 0.2694 -1.3656 0.1721 0.0854 1.5525
factor(class)3rd class 0.1710 0.1108 -2.7255 0.0064 0.0480 0.6089
>
>
> # POISSON REGRESSION
> # library(COUNT)
> data(titanicgrp)
> titanicgrp$class <- as.factor(titanicgrp$class)
> titanicgrp$logcases <- log(titanicgrp$cases)
> glmpr <- glm(survive ~ age + sex + class + offset(logcases), family= poisson, data=titanicgrp)
> summary(glmpr)
Call:
glm(formula = survive ~ age + sex + class + offset(logcases),
family = poisson, data = titanicgrp)
Deviance Residuals:
Min 1Q Median 3Q Max
-4.1793 -0.4240 0.1258 1.0760 2.9891
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.48446 0.15961 3.035 0.002403 **
ageadults -0.48297 0.14562 -3.317 0.000911 ***
sexman -1.16566 0.09502 -12.267 < 2e-16 ***
class2nd class -0.37829 0.11758 -3.217 0.001294 **
class3rd class -0.76908 0.10704 -7.185 6.74e-13 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 291.608 on 11 degrees of freedom
Residual deviance: 38.304 on 7 degrees of freedom
AIC: 107.06
Number of Fisher Scoring iterations: 4
> exp(coef(glmpr))
(Intercept) ageadults sexman class2nd class class3rd class
1.6232966 0.6169489 0.3117178 0.6850337 0.4634390
>
> #lcases <- log(titanicgrp$cases)
> #nb2o <- nbinomial(survive ~ age + sex + factor(class),
> # formula2 =~ age + sex,
> # offset = lcases,
> # mean.link="log",
> # scale.link="log_s",
> # data=titanicgrp)
> #summary(nb2o)
> #exp(coef(nb2o))
>
>
>
>
>
>
> dev.off()
null device
1
>
|