Say I have a continuous variable $C \sim N(0, 1)$, which was observed in a few points:
obsC <- seq(-1.5, 1.5, by = 1)
I also have a discrete variable $D \in \{0; 1\}$ as well as all the values for $\Pr(D = d | C = c)$:
DcondC <- matrix(c(.1, .2, .3, .4, .9, .8, .7, .6),
nrow = length(obsC), ncol = 2,
dimnames = list("C" = obsC, "D" = 0:1))
DcondC
D
C 0 1
-1.5 0.1 0.9
-0.5 0.2 0.8
0.5 0.3 0.7
1.5 0.4 0.6
My goal is to get to $\Pr(D = d)$.
In order to achieve this, my approach has begun with calculating the mixed joint density, defined as
$$ f_{C, D}(c, d) = \Pr(D = d | C = c) f_C(c). $$
I believe the code below correcly calculates these values:
mixedJointDens <- DcondC # just to create the matrix
for (row in 1:nrow(DcondC)) {
mixedJointDens[row, ] <- DcondC[row, ] * dnorm(obsC[row])
}
mixedJointDens
D
C 0 1
-1.5 0.01295176 0.11656584
-0.5 0.07041307 0.28165226
0.5 0.10561960 0.24644573
1.5 0.05180704 0.07771056
The densities above sum to less than 1, but I think this is either because this is not a proper PDF or because I am missing a chunk of the support for $C$. Anyway, apparently I need to recover the joint CDF by calculating
$$ F_{C, D}(c, d) = \sum_{t \leq d} \int_{s = -\infty}^c f_{C, D}(s, t)ds, $$
which I can't understand how to do, either algebraically or numerically. After that, I'll need to figure out a way to integrate out $C$ so I can end up with $F_D(d)$ and, by subtraction, $\Pr(D = d)$.
I've been trying to solve this problem for a couple of days now, and as my brain cells start giving up I can't help but think I am either over complicating this or missing something obvious. Am I on the correct path? Is there a better approach to getting to $\Pr(D = d)$ when one knows $\Pr(D = d | C = c)$ and $f_C(c)$?
integrate
function in R). I also don't see how sample values of $C$ are relevant if you know that $C\sim N(0,1)$. $\endgroup$