data1 <- data.frame(
race = c("White","White","White","Black","Black","Black"),
religion = c("Protestant","Catholic","Other","Protestant","Catholic","Other"),
yes = c(817,519,48,298,39,119),
no = c(250,194,9,86,13,38)
)
library(tidyr)
data1_long <- data1 |>
pivot_longer(cols = c(yes,no),
names_to = "belief",
values_to = "count")
data1_long$belief <- ifelse(data1_long$belief=="yes",1,0)
model_logistik <- glm(belief ~ race + religion,
family = binomial,
weights = count,
data = data1_long)
summary(model_logistik)
##
## Call:
## glm(formula = belief ~ race + religion, family = binomial, data = data1_long,
## weights = count)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.998223 0.140065 7.127 1.03e-12 ***
## raceWhite -0.007062 0.122283 -0.058 0.9539
## religionOther 0.271507 0.201252 1.349 0.1773
## religionProtestant 0.206471 0.105220 1.962 0.0497 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 2693.8 on 11 degrees of freedom
## Residual deviance: 2689.0 on 8 degrees of freedom
## AIC: 2697
##
## Number of Fisher Scoring iterations: 5
exp(coef(model_logistik))
## (Intercept) raceWhite religionOther religionProtestant
## 2.7134552 0.9929629 1.3119402 1.2293325
data2 <- data.frame(
daerah = c("A","A","A","B","B","B"),
umur = c("15-24","25-34","35-44","15-24","25-34","35-44"),
kasus = c(1,16,30,4,38,119),
populasi = c(172675,123065,96216,181343,146207,121374)
)
data2$daerah <- factor(data2$daerah)
data2$umur <- factor(data2$umur)
model_poisson <- glm(kasus ~ daerah + umur,
family = poisson(link = "log"),
offset = log(populasi),
data = data2)
summary(model_poisson)
##
## Call:
## glm(formula = kasus ~ daerah + umur, family = poisson(link = "log"),
## data = data2, offset = log(populasi))
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -11.8134 0.4639 -25.464 < 2e-16 ***
## daerahB 1.0193 0.1658 6.147 7.88e-10 ***
## umur25-34 2.6250 0.4675 5.615 1.96e-08 ***
## umur35-44 3.8398 0.4547 8.445 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 297.9850 on 5 degrees of freedom
## Residual deviance: 1.6237 on 2 degrees of freedom
## AIC: 36.853
##
## Number of Fisher Scoring iterations: 4
Berdasarkan analisis yang dilakukan, regresi logistik menunjukkan bahwa faktor agama, khususnya Protestan, berpengaruh terhadap kepercayaan terhadap kehidupan setelah kematian. Sementara itu, regresi Poisson menunjukkan bahwa faktor wilayah dan umur berpengaruh signifikan terhadap jumlah kasus kanker kulit, dimana daerah B dan kelompok umur yang lebih tua memiliki risiko yang lebih tinggi.