I want to get intuition into the calculation of propensity scores (PS) and inverse probability of treatment weights (IPTW) for a multinomial treatment using multinomial regression. One of the treatments is the baseline treatment.
I am aware that powerful packages automate this but for my analyses, I need to be able to create my own function that allows me to:
manuallythe PS using a multinomial regression model and
manuallythe IPTW from the estimated PS using the relevant formulas.
Here I use the data from here where each of the three categories of the variable
group represents a treatment, and the
group == 1 represents the baseline treatment (control group) to which each of the other treatments are compared. The approach discussed there gives several PS per row, which is not what I want - all I need is only one PS and one IPTW per row as I get when I use twang and any other similar package.
library("survival") require("survival") library("nnet") require("nnet") set.seed(42) days <- rpois(100, 3) group <- sample(c(1,2,3), 100, replace=TRUE) status <- rbinom(100,1,0.65) demo1 <- rnorm(100,100,25) demo2 <- rpois(100,10) demo3 <- rbinom(100,1,0.67) df <- data.frame(days, status, group, demo1, demo2,demo3)
Thanks in advance for any help.