Closed hhchang0210 closed 1 year ago
The only method that actually uses an adjusted number at risk table to estimate the survival curves is method="iptw_km"
. Because it is the only method for which this makes sense I did not implement a direct way to include them in the plot. The table is, however, included in the output of the adjustedsurv object when using said merhod.
To my knowledge there is no other package that offers functionalitx like that. Sorry to dissapoint.
Hi, I have no idea about how to get risk table using method = "iptw_km" after googling the internet. Could you please give me a hint? Thank you.
Sure. After calling the adjustedsurv
function with method="iptw_km"
you can either simply extract the risk table from the output object using output$n_at_risk
or you can use as_ggsurvplot_df(output)
to get a data.frame
that also includes the survival estimates as well.
Thank for kindly help. I'm curious that there is a function or package to plot risk table using output$n_at_risk?
As i mentioned in my first reply, there currently isn't as far as I know.
Hi, Is this a limitation in R or all statistic software? There are many papers with risk table when using IPTW. Take https://pubmed.ncbi.nlm.nih.gov/33239410/ for example.
The following is a survival curve with a risk table using IPTW.
Sorry, I know this problem is not irrelevant to this package, but I just wonder how they did it. Anyways, I really thank you for your kindly replies. Thank you very much.
It is of course not impossible to do this. Since you get the contents for the risk table out of the output all you need to do is write your own function to plot it.
Your simplest alternative would be to just create a table using something like pander, xtable or stargazer first. Screenshot this and put it under the survival curves. Of course actually writing code that plots it auromatically would be preferable but i am not aware of any package implementing this atm
Thank you for the reply. I am trying to plot it. But I found something strange. I used the following code to generate adjsurv:
#generate weight W.out <- WeightIt::weightit(statin ~ aki_stage+age+gender+ DM+HTN+CKD+CHF+LC+CVA+COPD+hyperlipidemia+IHD+ sofa+heart_rate_mean+mbp_mean+resp_rate_mean+ spo2_mean+glucose_mean+ hemoglobin_mean+platelets_mean+wbc_mean+aniongap_mean+ bicarbonate_mean+bun_mean+chloride_mean+ creatinine_mean+sodium_mean+potassium_mean+ GCS+charlson_comorbidity_index+ward+ethnicity+insurance_new+vasopressor, data = t1, method = "glm", estimand = "ATT")
t1$mw <- W.out$weights
t2 = filter(t1, aki_stage == 1)
The total number of t2 is 8681.
adjsurv <- adjustedsurv(data=t2, variable="statin", ev_time="discharge_death_365days_duration", event="discharge_death_365days", treatment_model = t2$mw, method="iptw_km", conf_int=FALSE, bootstrap=F )
I used adjsurv$n_at_risk to get the information of risk table. And the total number of adjsurv$n_at_risk is 1848. However, there is 8681 patients in t2 dataset. Why are they inconsistent? Is there something I made it wrong?
I unfortunately don't have the time to look into this more closely, but there are two things here that immediatly jump out to me. First of all, the number at risk is not necessarily equal to the number of people in the dataset. Secondly, when using method="iptw_km"
, a weighted number at risk is calculated, which is probably not equal to the crude number at risk at t. I can assure you that the code to calculate the weighted number at risk in this package is correct (it has been validated with exhaustive simulation studies).
Maybe reading the original article (Jun Xie and Chaofeng Liu (2005). "Adjusted Kaplan-Meier Estimator and Log- Rank Test with Inverse Probability of Treatment Weighting for Survival Data". In: Statistics in Medicine 24, pp. 3089-3110) will help settle your confusion. Hope this helps.
Hi, Thanks for sharing this wonderful package. I wonder if it is possible to get an adjusted survival curve with a number at risk table? Or are there other ways to get an adjusted survival curve with a number at risk table? Thank you.