m1 <- glm(sex ~ body_mass_g, data = penguins, family = "binomial")10:00
Imagine your sample has \(n=180\), with \(70\) positive observations, and \(110\) negative ones.
\[ \text{Best case: } \begin{pmatrix} 110 & 0 \\ 0 & 70 \end{pmatrix} \qquad \text{Worst case: } \begin{pmatrix} 0 & 70 \\ 110 & 0 \end{pmatrix} \]
(Intercept) body_mass_g
-5.162541644 0.001239819
Write down the mathematical expression for the estimated probability that a penguin that weighs 4000 g is a female. Then write down the code to extract the same number.
Don’t forget that female is the reference level, \(Y=0\), so …
\[ \widehat{P} (\mbox{female} \mid \mbox{body_mass_g} = 4000 g ) = 1 - \widehat{p} (\mbox{body_mass_g} = 4000 g)= 1 - \frac1{1 + {\rm e}^{-\left( -5.162541644 + 0.001239819 \cdot 4000 \right)}} \]
01:00
# A tibble: 4 × 3
# Groups: sex [2]
sex sex_hat n
<fct> <chr> <int>
1 female female 109
2 female male 56
3 male female 74
4 male male 94
01:00
(56+74)/(109+56+74+94) = 130/333
(94)/(94+56) = 94/150
(94)/(94+74) = 94/168
It’s up to you but I’d say misclassifying a male penguin as female or vice versa seems equally problematic. But maybe it isn’t. It depends on what you do with that prediction.
(Intercept) body_mass_g bill_length_mm
-6.91208086 0.00101530 0.06112808
Open up RStudio and fit the model here in the slides. What are the predicted sexes of these two penguins, using a probability threshold of 0.5?
01:00
November 18 & November 20
Warning
We will be conducting an actual experiment in class on these dates.
You need to be present to participate!
It’s gonna be soooo much fun!
05:00
45:00
