Forum Discussion

Silver75's avatar
Silver75
Frequent Visitor
9 years ago

Survival Analysis with PowerBI and R

Hi
I'm trying to realizing a Kaplan Mayer Survival non parametric model in PowerBI Desktop using script R, with filter in a drill-down
I have a flat file/table in PowerBI with main information for drill down, this is my script

 

library(survival)
time=dataset$tenure
event=dataset$censor
kmsurvival=survfit(Surv(time, event)~1, conf.type="none")
plot(kmsurvival, xlab="tenure", ylab="Survival Probability", col.lab="red", pch="1", lwd="3", col="blue", bg="yellow", xscale=1, xlim=c(1,24))


where
tenure is numeric
censor is numeric (1=died, 0=live)

The probability result seems to be overstimated


Can anyone please help me how to solve this? is my script  wrong?

thank you

 

4 Replies

  • v-huizhn-msft's avatar
    v-huizhn-msft
    Microsoft Employee

    Hi Silver75,

    Your script is right as I tested. I run the sample script and get expected result.

    I create a sample table.



    Then click R visual highlighted in red line in the following screenshot. Select the Test[tenure] andTest[censor] as value levels.

     

    Type the R script and run, you will get the desired result which is same with the picture in Rsudio.



    If there is any error message when you run the scipt? Could you please share more details for further analysis.

    Best Regards,
    Angelia

    • Silver75's avatar
      Silver75
      Frequent Visitor

      Hi v-huizhn-msft

      thank you, any error during the script, the survival probability is overstimated respect other software, in particular KM cut some time intervals.

       

      In add, If I insert in the dataset other variable (eg sex, civil status, etc..) the Drill – Down on survival graph doesn’t work

  • Anonymous's avatar
    Anonymous
    Not applicable

    Does any of you has any good advice on this important problem?