Hello,
I need to obtain weighted means for a set of subjects with multiple measures over time. I am running a MAIC (Matched Adjusted Indirect Comparison) and am weighting my individual patient data with aggregate data from another study. That isn't really important though, the main thing is that I have missing data at each time point and the weighting won't work if there are NA's.
The MAIC package creates a vector with weights for each subject. All have baseline data, so I've used this 'full' dataset to create the weights, so that all subjects have a weight (wtr_stsbltx). This works fine. I have 679 subjects and the weight vector length is 679.
The problem comes when I try to apply the vector of weights (n=679) to a set of subjects with missing data for a subsequent time point. I get NAs for the means and SDs:
wk2ststx.adj=data.frame(noeds1tx %>%
mutate(wtr_stsbltx) %>%
summarise(N2 = sum(wtr_stsbltx) ,
STS_week2.mean = weighted.mean(STS_week2, wtr_stsbltx) ,
STS_week2.sd = sqrt(sum(wtr_stsbltx / sum(wtr_stsbltx) * (STS_week2 - STS_week2.mean)^2)),
WEEK_2_CFB_STS.mean = weighted.mean(WEEK_2_CFB_STS, wtr_stsbltx),
WEEK_2_CFB_STS.se = sqrt((blststx.adj$BASELINE_STS.sd^2/blststx.adj$NBL)+(STS_week2.sd^2/sum(wtr_stsbltx))),
))
my solution has been to get separate weights for each time point so that I don't have to deal with missing data. however this now seems wrong to me as I get different weights for the same subjects at different time points.
What I need to be able to do is locate the weights for the missing subjects and remove them. or if there is another way of thinking about this I'd be happy to hear it.
Many thanks in advance!