My dataset contains n observations $X_i$ of n individuals and I want to predict a binary outcome $Y_i$.
logistic regression model
It is fair to assume that this $Y_i$ is the realization of a Bernoulli experiment and is 1 with probability $\pi_i$. Under the logistic regression model, I model $\log\big(\frac{\pi_i}{1-\pi_i}\big) = \mathbf{X_i} \mathbf{\beta}$ which is fine by me. $\beta$ is solved for by optimizing the log-likelihood of the data under the model. The individual log-likelihood is
$$\log L_\beta(i)=\pi_i^{y_i}(1-\pi_i)^{1-y_i}$$
The total log likelihood is the sum of the individual likelihood, expressed in terms of $\beta$.
Changes I want to make
The trick is, I also have historical data about previous outcome ($Y$) for some individuals! I do not have the associated previous $X$ though. In my case, it is fair to assume that the probability $\pi_i$ does not change in the life of an individual so I want to take into account the previous outcome in the likelihood!
If I call $n(i)$ the total number of observations ($\geq1$) for individual $i$ and $Y_{i,j}$ the $j^{th}$ outcome observed for individual $i$, my new individual likelihood is:
$$\log L_\beta(i)= \sum_j^{n(i)} \pi_i^{y_{i,j}}(1-\pi_i)^{1-y_{i,j}}$$
And the total likelihood to optimize is the sum of this over $i$.
My questions
Does it make sense to do this or is there any obvious flaw I missed? I am open to alternatives.
Can I implement this using
glm
(R)? I would need to define my own family, I don't know if it is possible. I guess the likelihood above would have to be in the exponential family and I am not sure it is since the number of observations for a given individual is not fixed.Do I need to optimize manually (using
optim
for R for ex) to fit my model? I don't have a problem with this approach per se, but in the end I would like to use this likelihood in a LASSO or elastic net framework and it would be so much more convenient and effective to be able to useglmnet
!