cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-777716%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERisk%20Table%20of%20KM%20plot%20on%20JMP%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777716%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EAccording%20to%26nbsp%3B%3CA%20title%3D%22Displaying%20at%20risk%20tables%20under%20kaplan%20meier%22%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FDiscussions%2FDisplaying-at-risk-tables-under-kaplan-meier%2Fm-p%2F55338%2Fhighlight%2Ftrue%23M31302%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.jmp.com%2Ft5%2FDiscussions%2FDisplaying-at-risk-tables-under-kaplan-meier%2Fm-p%2F55338%2Fhighlight%2Ftrue%23M31302%3C%2FA%3E%26nbsp%3B%2C%20Could%20you%20please%20provide%20the%20method%20for%20generating%20a%20risk%20table%20underneath%20the%20KM%20plot%3F%20I%20tried%20to%20follow%20the%20script%20from%20the%20comment%20but%20it%20was%20closed%20to%20be%20solved.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20Current%20Data%20Table%20()%3B%0AminT%20%3D%200%3B%0AmaxT%20%3D%2025%3B%0AstepT%20%3D%201%3B%0A%0ASummarize(%20lv%20%3D%20by(%20%3Agroup)%20)%3B%0Aobj%20%3D%20Survival(%0A%09Y(%20%3Atime%20)%2C%0A%09Censor(%20%3A%22reject%22n%20)%2C%0A%09Grouping(%20%3Agroup%20)%2C%0A%09Failure%20Plot(%200%20)%2C%0A%09SendToReport(%0A%09%09Dispatch(%0A%09%09%09%7B%22Survival%20Plot%22%7D%2C%0A%09%09%09%221%22%2C%0A%09%09%09ScaleBox%2C%0A%09%09%09%7BMin(%200%20)%2C%20Max(%2025%20)%2C%20Inc(%201%20)%2C%20Minor%20Ticks(%201%20)%7D%0A%09%09)%2C%0A%09%09Dispatch(%0A%09%09%09%7B%22Survival%20Plot%22%7D%2C%0A%09%09%09%22time%22%2C%0A%09%09%09TextEditBox%2C%0A%09%09%09%7BSet%20Text(%20%22Times(years)%22%20)%7D%0A%09%09)%0A%09)%0A)%20%26lt%3B%26lt%3B%20report%3B%0Aobj%5BList%20Box(%202%20)%5D%20%26lt%3B%26lt%3B%20append(%20Table%20Box(%20String%20Col%20Box(%20%22No%20at%20Risk%20%7C%20Year%22%2C%20lv%20)%20)%20)%3B%0ATab1%20%3D%20(obj%5Blv%5B1%5D%5D%5BTable%20Box(%201%20)%5D%20%26lt%3B%26lt%3B%20get)%3B%0ATab2%20%3D%20(obj%5Blv%5B2%5D%5D%5BTable%20Box(%201%20)%5D%20%26lt%3B%26lt%3B%20get)%3B%0AFor(%20T%20%3D%20minT%2C%20T%20%26lt%3B%3D%20maxT%2C%20T%20%2B%3D%20stepT%2C%0A%09lp%20%3D%20Max(%20Loc(%20Matrix(%20Tab1%20%5Byears%5D%20)%20%26lt%3B%3D%20T%20)%20)%3B%0A%09AR1%20%3D%20Tab1%5B%22At%20Risk%22%5D%5Blp%5D%3B%0A%09lp%20%3D%20Max(%20Loc(%20Matrix(%20Tab2%20%5Byears%5D)%20%26lt%3B%3D%20T%20)%20)%3B%0A%09AR2%20%3D%20Tab2%5B%22At%20Risk%22%5D%5Blp%5D%3B%0A%09obj%5BList%20Box(%202%20)%5D%5BTable%20Box(%201%20)%5D%20%26lt%3B%26lt%3B%20append(%20Number%20Col%20Box(%20Char(%20T%20)%2C%20%7BAR1%2C%20AR2%7D%20)%20)%3B%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Ethe%20out%20put%20showed%20as%20the%20attachment%20picture.%20Could%20you%20please%20to%20correct%20the%20script%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-777716%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EData%20Exploration%20and%20Visualization%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-777727%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Risk%20Table%20of%20KM%20plot%20on%20JMP%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777727%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20attempted%20to%20parametrize%20the%20code%20a%20bit%20further%2C%20does%20this%20do%20what%20you%20are%20looking%20for%20if%20you%20change%20minT%2C%20maxT%2C%20stepT%2C%20ycol%2C%20grouping%20and%20use%20your%20table%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%0Adt%20%3D%20Open(%22%24SAMPLE_DATA%2FRats.jmp%22)%3B%0A%0AminT%20%3D%20100%3B%0AmaxT%20%3D%20350%3B%0AstepT%20%3D%2050%3B%0Aycol%20%3D%20%22days%22%3B%0Agrouping%20%3D%20%22Group%22%3B%0A%0ASummarize(dt%2C%20groups%20%3D%20by(Eval(grouping)))%3B%0A%0Aobj%20%3D%20dt%20%26lt%3B%26lt%3B%20Survival(%0A%09Y(Eval(ycol))%2C%0A%09Censor(%3ACensor)%2C%0A%09Grouping(Eval(grouping))%2C%0A%09Show%20Points(1)%2C%0A%09SendToReport(%0A%09%09Dispatch(%7B%22Survival%20Plot%22%7D%2C%20%221%22%2C%20ScaleBox%2C%0A%09%09%09%7BMin(minT)%2C%20Max(maxT)%2C%20Inc(stepT)%2C%20Minor%20Ticks(1)%7D%0A%09%09)%2C%0A%0A%09)%0A)%3B%0A%0Arep%20%3D%20Report(obj)%3B%0A%0Arep%5BList%20Box(2)%5D%20%26lt%3B%26lt%3B%20append(tb%20%3D%20Table%20Box(String%20Col%20Box(%22No%20at%20Risk%20(%22%7C%7Cycol%7C%7C%22)%22%2C%20groups)))%3B%0Arep%5BList%20Box(2)%5D%20%26lt%3B%26lt%3B%20Append(Spacer%20Box(Size(0%2C20)))%3B%0A%0Atabs%20%3D%20%7B%7D%3B%0AFor%20Each(%7Bgroup%7D%2C%20groups%2C%0A%09Insert%20Into(tabs%2C%20Eval%20List(%7Brep%5BOutlineBox(group)%2C%20Table%20Box(1)%5D%20%26lt%3B%26lt%3B%20get%7D))%3B%0A)%3B%0A%0A%0AFor(T%20%3D%20minT%2C%20T%20%26lt%3B%3D%20maxT%2C%20T%20%2B%3D%20stepT%2C%0A%09%0A%09ARs%20%3D%20%7B%7D%3B%0A%09For%20Each(%7Btab%7D%2C%20tabs%2C%0A%09%09lp%20%3D%20Max(Loc(Matrix(tab%5Bycol%5D)%20%26lt%3B%3D%20T))%3B%0A%09%09Insert%20Into(ARS%2C%20tab%5B%22At%20Risk%22%5D%5Blp%5D)%0A%09)%3B%0A%09%09%0A%09tb%20%26lt%3B%26lt%3B%20append(Number%20Col%20Box(Char(T)%2C%20ARs))%3B%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EEdit%3A%20small%20fixes%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-777758%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Risk%20Table%20of%20KM%20plot%20on%20JMP%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777758%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20Jarmo%2C%20Thank%20you%20for%20your%20help.%20It%20worked!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%2C%20Theerachai%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-777774%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Risk%20Table%20of%20KM%20plot%20on%20JMP%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-777774%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHere%20is%20also%20a%20script%20which%20can%20be%20used%20basically%20on%20Survivor%20report.%20It%20might%20work%20in%20most%20of%20the%20cases%20but%26nbsp%3B%20not%20sure%20if%20it%20will%20as%20I'm%20not%20that%20familiar%20with%20this%20JMP%20Platform%20or%20analysis.%20I%20also%20modified%20the%20calculations%20so%20they%20might%20not%20be%20exactly%20correct%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%20you%20have%20to%20have%20Survivor%20report%20open%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jthi_1-1722445639973.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_1-1722445639973.png%22%20style%3D%22width%3A%20220px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F66675iAA63344DD8E032F5%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jthi_1-1722445639973.png%22%20alt%3D%22jthi_1-1722445639973.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3Ethen%20you%20can%20run%20the%20script%20and%20it%20will%20ask%20for%20few%20things%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jthi_0-1722445470437.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1722445470437.png%22%20style%3D%22width%3A%20344px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F66674i2E34B119C45AA7AB%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jthi_0-1722445470437.png%22%20alt%3D%22jthi_0-1722445470437.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFill%20in%20those%20and%20press%20OK%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jthi_2-1722445724506.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_2-1722445724506.png%22%20style%3D%22width%3A%20344px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F66676i5A403C01C7780BEA%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jthi_2-1722445724506.png%22%20alt%3D%22jthi_2-1722445724506.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EIt%20will%20then%20add%20the%20table%20to%20your%20existing%20report%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jthi_3-1722445739773.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_3-1722445739773.png%22%20style%3D%22width%3A%20211px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F66677i64CDEACA9D82BC26%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jthi_3-1722445739773.png%22%20alt%3D%22jthi_3-1722445739773.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EScript%20below%20(and%20also%20attached).%20%3CSTRONG%3EUse%20at%20your%20own%20risk%2C%20the%20calculations%20have%20not%20been%20checked%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20class%3D%22lia-spoiler-container%22%3E%3CA%20class%3D%22lia-spoiler-link%22%20href%3D%22%23%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EView%20more...%3C%2FA%3E%3CNOSCRIPT%3E%20(Highlight%20to%20read)%3C%2FNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-border%22%3E%3CDIV%20class%3D%22lia-spoiler-content%22%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F*%22%22%22%20Add%20risk%20table%20to%20Survival%20platform%0A%0AAuthor%3A%20jthi%0ACreation%20Date%3A%202024-07-31%0ACreation%20JMP%20Version%3A%20JMP%20Pro%2018.0.1%0A%0ADescription%3A%20Based%20on%0A%09https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FDiscussions%2FDisplaying-at-risk-tables-under-kaplan-meier%2Fm-p%2F305898%2Fhighlight%2Ftrue%23M56162%0A%0ATodo%3A%0A%20%20%20%20*%20Show%20steps%20to%20user%20before%20pressing%20OK%0A%20%20%20%20*%20Remove%20modal%20window%0A%20%20%20%20*%20Turn%20into%20add-in%20%2F%20proper%20script%0A%20%20%20%20*%20Add%20instructions%20%2F%20title%20to%20UI%0A%20%20%20%20*%20Add%20utility%20modal%0A%09%0A%22%22%22*%2F%0A%0ANames%20Default%20To%20Here(1)%3B%0A%0Aask_steps%20%3D%20function(%7B%7D%2C%20%7BDefault%20Local%7D%2C%0A%09nw%20%3D%20New%20Window(%22Fill%20in%20Time%20to%20Event%20Steps%22%2C%20%26lt%3B%26lt%3B%20Type(%22Modal%20Dialog%22)%2C%20%26lt%3B%26lt%3B%20Return%20Result%2C%0A%09%09H%20List%20Box(%0A%09%09%09Panel%20Box(%22Fill%20in%20steps%22%2C%0A%09%09%09%09Lineup%20Box(N%20Col(2)%2C%0A%09%09%09%09%09Text%20Box(%22Min%20Time%22)%2C%0A%09%09%09%09%09neb_min%20%3D%20Number%20Edit%20Box(.)%2C%0A%09%09%09%09%09Text%20Box(%22Max%20Time%22)%2C%0A%09%09%09%09%09neb_max%20%3D%20Number%20Edit%20Box(.)%2C%0A%09%09%09%09%09Text%20Box(%22Step%20Time%22)%2C%0A%09%09%09%09%09neb_step%20%3D%20Number%20Edit%20Box(.)%2C%0A%09%09%09%09%09Text%20Box(%22Interpolate%20last%22)%2C%0A%09%09%09%09%09cb_interpolate%20%3D%20Check%20Box(%7B%22%22%7D%2C%20%26lt%3B%26lt%3B%20Set%20All(1))%0A%09%09%09%09)%0A%09%09%09)%2C%0A%09%09%09Spacer%20Box(Size(20%2C%200))%2C%0A%09%09%09Panel%20Box(%22Actions%22%2C%0A%09%09%09%09Button%20Box(%22OK%22)%2C%0A%09%09%09%09Button%20Box(%22Cancel%22)%0A%09%09%09)%0A%09%09)%0A%09%09%2C%20%26lt%3B%26lt%3B%20Set%20Window%20Icon(%22Survival%22)%0A%09)%3B%0A%09%0A%09If(nw%5B%22Button%22%5D%20!%3D%201%2C%0A%09%09Throw(%22Cancelled%22)%3B%0A%09)%3B%0A%09%0A%09min_t%20%3D%20nw%5B%22neb_min%22%5D%3B%0A%09max_t%20%3D%20nw%5B%22neb_max%22%5D%3B%0A%09step_t%20%3D%20nw%5B%22neb_step%22%5D%3B%0A%0A%09If(Any(Is%20Missing(min_t)%2C%20Is%20Missing(max_t)%2C%20Is%20Missing(step_t))%2C%0A%09%09Throw(%22Steps%20not%20filled%20in%22)%3B%0A%09)%3B%0A%09%0A%09interpolate_last%20%3D%20N%20Items(nw%5B%22cb_interpolate%22%5D)%3B%0A%0A%09return(Eval%20List(%7Bmin_t%2C%20max_t%2C%20step_t%2C%20interpolate_last%7D))%3B%0A)%3B%0A%0Aadd_risk_table%20%3D%20function(%7Bplatform_ref%2C%20min_t%2C%20max_t%2C%20step_t%2C%20interpolate_last%7D%2C%20%7BDefault%20Local%7D%2C%0A%0A%09rep%20%3D%20Report(platform_ref)%3B%0A%09dt%20%3D%20platform_ref%20%26lt%3B%26lt%3B%20Get%20Data%20Table%3B%0A%09%0A%09ycol%20%3D%20((rep%20%26lt%3B%26lt%3B%20XPath(%22%2F%2FTextBox%5Btext()%3D'Time%20to%20event%3A%20'%5D%22))%5B1%5D%20%26lt%3B%26lt%3B%20sib)%20%26lt%3B%26lt%3B%20get%20text%3B%0A%09grouping_col%20%3D%20((rep%20%26lt%3B%26lt%3B%20XPath(%22%2F%2FTextBox%5Btext()%3D'Grouped%20by%20'%5D%22))%5B1%5D%20%26lt%3B%26lt%3B%20sib)%20%26lt%3B%26lt%3B%20get%20text%3B%0A%09Summarize(dt%2C%20groups%20%3D%20by(Eval(grouping_col)))%3B%0A%0A%09steps%20%3D%20min_t%3A%3Amax_t%3A%3Astep_t%3B%0A%09vals%20%3D%20steps%3B%0A%09%0A%09For%20Each(%7Bgroup%7D%2C%20groups%2C%0A%09%09m_tb%20%3D%20rep%5BOutlineBox(group)%2C%20Table%20Box(1)%5D%20%26lt%3B%26lt%3B%20get%20as%20matrix%3B%0A%09%09%0A%09%09times%20%3D%20m_tb%5B0%2C%201%5D%3B%0A%09%09atrisk%20%3D%20m_tb%5B0%2C%20N%20Cols(m_tb)%5D%3B%0A%09%09cur_steps%20%3D%20Step(steps%2C%20times%2C%20atrisk)%3B%20%2F%2F%20Last%20one%20isn't%20assumed%20in%20this%0A%09%09%0A%09%09If(interpolate_last%2C%0A%09%09%09If(times%5BN%20Rows(times)%2C%201%5D%20%26lt%3B%20max_t%20%26amp%3B%20Is%20Missing(cur_steps%5BN%20Cols(cur_steps)%5D)%2C%0A%09%09%09%09cur_steps%5BN%20Cols(cur_steps)%5D%20%3D%20atrisk%5BN%20Rows(times)%2C%201%5D%3B%0A%09%09%09)%3B%09%09%09%0A%09%09)%3B%0A%09%09vals%20%3D%20vals%20%7C%2F%20cur_steps%3B%0A%09)%3B%0A%0A%0A%09pb%20%3D%20Panel%20Box(%22Risk%20Table%22%2C%20tb_results%20%3D%20Table%20Box(%0A%09%09String%20Col%20Box(Eval%20Insert(%22No%20at%20Risk%20(%5Eycol%5E)%22)%2C%20groups)%2C%0A%09))%3B%0A%0A%0A%09For(i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Cols(vals)%2C%20i%2B%2B%2C%0A%09%09cur_vals%20%3D%20vals%5B0%2C%20i%5D%3B%0A%09%09%0A%09%09title%20%3D%20Char(Remove%20From(cur_vals%2C%201)%5B1%5D)%3B%0A%09%09%0A%09%09tb_results%20%26lt%3B%26lt%3B%20Append(Number%20Col%20Box(title%2C%20cur_vals))%3B%0A%09)%3B%0A%0A%09rep%5BList%20Box(2)%5D%20%26lt%3B%26lt%3B%20Append(pb)%3B%0A%09rep%5BList%20Box(2)%5D%20%26lt%3B%26lt%3B%20Append(Spacer%20Box(Size(0%2C%2010)))%3B%0A)%3B%0A%0A%0A%0Acur_rep%20%3D%20Current%20Report()%3B%0AIf(Is%20Empty(cur_rep)%2C%0A%09Throw(%22No%20reports%20open%22)%3B%0A)%3B%0A%0Aob_ref%20%3D%20cur_rep%20%26lt%3B%26lt%3B%20XPath(%22%2F%2FOutlineBox%5B%40helpKey%3D'Surv'%5D%22)%3B%0A%0AIf(N%20Items(ob_ref)%20%3D%3D%200%2C%0A%09Throw(%22No%20Surv%20platform%20found%22)%3B%0A)%3B%0A%0ATry(%0A%09%7Bmin_t%2C%20max_t%2C%20step_t%2C%20interpolate_last%7D%20%3D%20ask_steps()%3B%0A%0A%09platform_ref%20%3D%20ob_ref%5B1%5D%20%26lt%3B%26lt%3B%20get%20scriptable%20object%3B%0A%0A%09add_risk_table(platform_ref%2C%20min_t%2C%20max_t%2C%20step_t%2C%20interpolate_last)%3B%0A%2C%0A%09Throw(%22Other%20issues%3A%20%22%20%7C%7C%20char(exception_msg))%3B%0A)%3B%0A%0A%0AWrite()%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3C%2FDIV%3E%3CNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-noscript-container%22%3E%3CDIV%20class%3D%22lia-spoiler-noscript-content%22%3E%0A%2F*%22%22%22%20Add%20risk%20table%20to%20Survival%20platform%0A%0AAuthor%3A%20jthi%0ACreation%20Date%3A%202024-07-31%0ACreation%20JMP%20Version%3A%20JMP%20Pro%2018.0.1%0A%0ADescription%3A%20Based%20on%0A%09%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FDiscussions%2FDisplaying-at-risk-tables-under-kaplan-meier%2Fm-p%2F305898%2Fhighlight%2Ftrue%23M56162%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.jmp.com%2Ft5%2FDiscussions%2FDisplaying-at-risk-tables-under-kaplan-meier%2Fm-p%2F305898%2Fhighlight%2Ftrue%23M56162%3C%2FA%3E%0A%0ATodo%3A%0A%20%20%20%20*%20Show%20steps%20to%20user%20before%20pressing%20OK%0A%20%20%20%20*%20Remove%20modal%20window%0A%20%20%20%20*%20Turn%20into%20add-in%20%2F%20proper%20script%0A%20%20%20%20*%20Add%20instructions%20%2F%20title%20to%20UI%0A%20%20%20%20*%20Add%20utility%20modal%0A%09%0A%22%22%22*%2F%0A%0ANames%20Default%20To%20Here(1)%3B%0A%0Aask_steps%20%3D%20function(%7B%7D%2C%20%7BDefault%20Local%7D%2C%0A%09nw%20%3D%20New%20Window(%22Fill%20in%20Time%20to%20Event%20Steps%22%2C%20%26lt%3B%26lt%3B%20Type(%22Modal%20Dialog%22)%2C%20%26lt%3B%26lt%3B%20Return%20Result%2C%0A%09%09H%20List%20Box(%0A%09%09%09Panel%20Box(%22Fill%20in%20steps%22%2C%0A%09%09%09%09Lineup%20Box(N%20Col(2)%2C%0A%09%09%09%09%09Text%20Box(%22Min%20Time%22)%2C%0A%09%09%09%09%09neb_min%20%3D%20Number%20Edit%20Box(.)%2C%0A%09%09%09%09%09Text%20Box(%22Max%20Time%22)%2C%0A%09%09%09%09%09neb_max%20%3D%20Number%20Edit%20Box(.)%2C%0A%09%09%09%09%09Text%20Box(%22Step%20Time%22)%2C%0A%09%09%09%09%09neb_step%20%3D%20Number%20Edit%20Box(.)%2C%0A%09%09%09%09%09Text%20Box(%22Interpolate%20last%22)%2C%0A%09%09%09%09%09cb_interpolate%20%3D%20Check%20Box(%7B%22%22%7D%2C%20%26lt%3B%26lt%3B%20Set%20All(1))%0A%09%09%09%09)%0A%09%09%09)%2C%0A%09%09%09Spacer%20Box(Size(20%2C%200))%2C%0A%09%09%09Panel%20Box(%22Actions%22%2C%0A%09%09%09%09Button%20Box(%22OK%22)%2C%0A%09%09%09%09Button%20Box(%22Cancel%22)%0A%09%09%09)%0A%09%09)%0A%09%09%2C%20%26lt%3B%26lt%3B%20Set%20Window%20Icon(%22Survival%22)%0A%09)%3B%0A%09%0A%09If(nw%5B%22Button%22%5D%20!%3D%201%2C%0A%09%09Throw(%22Cancelled%22)%3B%0A%09)%3B%0A%09%0A%09min_t%20%3D%20nw%5B%22neb_min%22%5D%3B%0A%09max_t%20%3D%20nw%5B%22neb_max%22%5D%3B%0A%09step_t%20%3D%20nw%5B%22neb_step%22%5D%3B%0A%0A%09If(Any(Is%20Missing(min_t)%2C%20Is%20Missing(max_t)%2C%20Is%20Missing(step_t))%2C%0A%09%09Throw(%22Steps%20not%20filled%20in%22)%3B%0A%09)%3B%0A%09%0A%09interpolate_last%20%3D%20N%20Items(nw%5B%22cb_interpolate%22%5D)%3B%0A%0A%09return(Eval%20List(%7Bmin_t%2C%20max_t%2C%20step_t%2C%20interpolate_last%7D))%3B%0A)%3B%0A%0Aadd_risk_table%20%3D%20function(%7Bplatform_ref%2C%20min_t%2C%20max_t%2C%20step_t%2C%20interpolate_last%7D%2C%20%7BDefault%20Local%7D%2C%0A%0A%09rep%20%3D%20Report(platform_ref)%3B%0A%09dt%20%3D%20platform_ref%20%26lt%3B%26lt%3B%20Get%20Data%20Table%3B%0A%09%0A%09ycol%20%3D%20((rep%20%26lt%3B%26lt%3B%20XPath(%22%2F%2FTextBox%5Btext()%3D'Time%20to%20event%3A%20'%5D%22))%5B1%5D%20%26lt%3B%26lt%3B%20sib)%20%26lt%3B%26lt%3B%20get%20text%3B%0A%09grouping_col%20%3D%20((rep%20%26lt%3B%26lt%3B%20XPath(%22%2F%2FTextBox%5Btext()%3D'Grouped%20by%20'%5D%22))%5B1%5D%20%26lt%3B%26lt%3B%20sib)%20%26lt%3B%26lt%3B%20get%20text%3B%0A%09Summarize(dt%2C%20groups%20%3D%20by(Eval(grouping_col)))%3B%0A%0A%09steps%20%3D%20min_t%3A%3Amax_t%3A%3Astep_t%3B%0A%09vals%20%3D%20steps%3B%0A%09%0A%09For%20Each(%7Bgroup%7D%2C%20groups%2C%0A%09%09m_tb%20%3D%20rep%5BOutlineBox(group)%2C%20Table%20Box(1)%5D%20%26lt%3B%26lt%3B%20get%20as%20matrix%3B%0A%09%09%0A%09%09times%20%3D%20m_tb%5B0%2C%201%5D%3B%0A%09%09atrisk%20%3D%20m_tb%5B0%2C%20N%20Cols(m_tb)%5D%3B%0A%09%09cur_steps%20%3D%20Step(steps%2C%20times%2C%20atrisk)%3B%20%2F%2F%20Last%20one%20isn't%20assumed%20in%20this%0A%09%09%0A%09%09If(interpolate_last%2C%0A%09%09%09If(times%5BN%20Rows(times)%2C%201%5D%20%26lt%3B%20max_t%20%26amp%3B%20Is%20Missing(cur_steps%5BN%20Cols(cur_steps)%5D)%2C%0A%09%09%09%09cur_steps%5BN%20Cols(cur_steps)%5D%20%3D%20atrisk%5BN%20Rows(times)%2C%201%5D%3B%0A%09%09%09)%3B%09%09%09%0A%09%09)%3B%0A%09%09vals%20%3D%20vals%20%7C%2F%20cur_steps%3B%0A%09)%3B%0A%0A%0A%09pb%20%3D%20Panel%20Box(%22Risk%20Table%22%2C%20tb_results%20%3D%20Table%20Box(%0A%09%09String%20Col%20Box(Eval%20Insert(%22No%20at%20Risk%20(%5Eycol%5E)%22)%2C%20groups)%2C%0A%09))%3B%0A%0A%0A%09For(i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Cols(vals)%2C%20i%2B%2B%2C%0A%09%09cur_vals%20%3D%20vals%5B0%2C%20i%5D%3B%0A%09%09%0A%09%09title%20%3D%20Char(Remove%20From(cur_vals%2C%201)%5B1%5D)%3B%0A%09%09%0A%09%09tb_results%20%26lt%3B%26lt%3B%20Append(Number%20Col%20Box(title%2C%20cur_vals))%3B%0A%09)%3B%0A%0A%09rep%5BList%20Box(2)%5D%20%26lt%3B%26lt%3B%20Append(pb)%3B%0A%09rep%5BList%20Box(2)%5D%20%26lt%3B%26lt%3B%20Append(Spacer%20Box(Size(0%2C%2010)))%3B%0A)%3B%0A%0A%0A%0Acur_rep%20%3D%20Current%20Report()%3B%0AIf(Is%20Empty(cur_rep)%2C%0A%09Throw(%22No%20reports%20open%22)%3B%0A)%3B%0A%0Aob_ref%20%3D%20cur_rep%20%26lt%3B%26lt%3B%20XPath(%22%2F%2FOutlineBox%5B%40helpKey%3D'Surv'%5D%22)%3B%0A%0AIf(N%20Items(ob_ref)%20%3D%3D%200%2C%0A%09Throw(%22No%20Surv%20platform%20found%22)%3B%0A)%3B%0A%0ATry(%0A%09%7Bmin_t%2C%20max_t%2C%20step_t%2C%20interpolate_last%7D%20%3D%20ask_steps()%3B%0A%0A%09platform_ref%20%3D%20ob_ref%5B1%5D%20%26lt%3B%26lt%3B%20get%20scriptable%20object%3B%0A%0A%09add_risk_table(platform_ref%2C%20min_t%2C%20max_t%2C%20step_t%2C%20interpolate_last)%3B%0A%2C%0A%09Throw(%22Other%20issues%3A%20%22%20%7C%7C%20char(exception_msg))%3B%0A)%3B%0A%0A%0AWrite()%3B%0A%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FNOSCRIPT%3E%3C%2FDIV%3E%3C%2FDIV%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
doraemengs
Level III

Risk Table of KM plot on JMP?

According to https://community.jmp.com/t5/Discussions/Displaying-at-risk-tables-under-kaplan-meier/m-p/55338/high... , Could you please provide the method for generating a risk table underneath the KM plot? I tried to follow the script from the comment but it was closed to be solved. 

dt = Current Data Table ();
minT = 0;
maxT = 25;
stepT = 1;

Summarize( lv = by( :group) );
obj = Survival(
	Y( :time ),
	Censor( :"reject"n ),
	Grouping( :group ),
	Failure Plot( 0 ),
	SendToReport(
		Dispatch(
			{"Survival Plot"},
			"1",
			ScaleBox,
			{Min( 0 ), Max( 25 ), Inc( 1 ), Minor Ticks( 1 )}
		),
		Dispatch(
			{"Survival Plot"},
			"time",
			TextEditBox,
			{Set Text( "Times(years)" )}
		)
	)
) << report;
obj[List Box( 2 )] << append( Table Box( String Col Box( "No at Risk | Year", lv ) ) );
Tab1 = (obj[lv[1]][Table Box( 1 )] << get);
Tab2 = (obj[lv[2]][Table Box( 1 )] << get);
For( T = minT, T <= maxT, T += stepT,
	lp = Max( Loc( Matrix( Tab1 [years] ) <= T ) );
	AR1 = Tab1["At Risk"][lp];
	lp = Max( Loc( Matrix( Tab2 [years]) <= T ) );
	AR2 = Tab2["At Risk"][lp];
	obj[List Box( 2 )][Table Box( 1 )] << append( Number Col Box( Char( T ), {AR1, AR2} ) );
);

the out put showed as the attachment picture. Could you please to correct the script?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Risk Table of KM plot on JMP?

I attempted to parametrize the code a bit further, does this do what you are looking for if you change minT, maxT, stepT, ycol, grouping and use your table

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Rats.jmp");

minT = 100;
maxT = 350;
stepT = 50;
ycol = "days";
grouping = "Group";

Summarize(dt, groups = by(Eval(grouping)));

obj = dt << Survival(
	Y(Eval(ycol)),
	Censor(:Censor),
	Grouping(Eval(grouping)),
	Show Points(1),
	SendToReport(
		Dispatch({"Survival Plot"}, "1", ScaleBox,
			{Min(minT), Max(maxT), Inc(stepT), Minor Ticks(1)}
		),

	)
);

rep = Report(obj);

rep[List Box(2)] << append(tb = Table Box(String Col Box("No at Risk ("||ycol||")", groups)));
rep[List Box(2)] << Append(Spacer Box(Size(0,20)));

tabs = {};
For Each({group}, groups,
	Insert Into(tabs, Eval List({rep[OutlineBox(group), Table Box(1)] << get}));
);


For(T = minT, T <= maxT, T += stepT,
	
	ARs = {};
	For Each({tab}, tabs,
		lp = Max(Loc(Matrix(tab[ycol]) <= T));
		Insert Into(ARS, tab["At Risk"][lp])
	);
		
	tb << append(Number Col Box(Char(T), ARs));
);

Edit: small fixes

-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Risk Table of KM plot on JMP?

I attempted to parametrize the code a bit further, does this do what you are looking for if you change minT, maxT, stepT, ycol, grouping and use your table

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Rats.jmp");

minT = 100;
maxT = 350;
stepT = 50;
ycol = "days";
grouping = "Group";

Summarize(dt, groups = by(Eval(grouping)));

obj = dt << Survival(
	Y(Eval(ycol)),
	Censor(:Censor),
	Grouping(Eval(grouping)),
	Show Points(1),
	SendToReport(
		Dispatch({"Survival Plot"}, "1", ScaleBox,
			{Min(minT), Max(maxT), Inc(stepT), Minor Ticks(1)}
		),

	)
);

rep = Report(obj);

rep[List Box(2)] << append(tb = Table Box(String Col Box("No at Risk ("||ycol||")", groups)));
rep[List Box(2)] << Append(Spacer Box(Size(0,20)));

tabs = {};
For Each({group}, groups,
	Insert Into(tabs, Eval List({rep[OutlineBox(group), Table Box(1)] << get}));
);


For(T = minT, T <= maxT, T += stepT,
	
	ARs = {};
	For Each({tab}, tabs,
		lp = Max(Loc(Matrix(tab[ycol]) <= T));
		Insert Into(ARS, tab["At Risk"][lp])
	);
		
	tb << append(Number Col Box(Char(T), ARs));
);

Edit: small fixes

-Jarmo
doraemengs
Level III

Re: Risk Table of KM plot on JMP?

Hi Jarmo, Thank you for your help. It worked!

 

Best, Theerachai

jthi
Super User

Re: Risk Table of KM plot on JMP?

Here is also a script which can be used basically on Survivor report. It might work in most of the cases but  not sure if it will as I'm not that familiar with this JMP Platform or analysis. I also modified the calculations so they might not be exactly correct

 

First you have to have Survivor report open

jthi_1-1722445639973.png

then you can run the script and it will ask for few things

jthi_0-1722445470437.png

Fill in those and press OK

jthi_2-1722445724506.png

It will then add the table to your existing report

jthi_3-1722445739773.png

 

Script below (and also attached). Use at your own risk, the calculations have not been checked

 

View more...
/*""" Add risk table to Survival platform

Author: jthi
Creation Date: 2024-07-31
Creation JMP Version: JMP Pro 18.0.1

Description: Based on
	https://community.jmp.com/t5/Discussions/Displaying-at-risk-tables-under-kaplan-meier/m-p/305898/highlight/true#M56162

Todo:
    * Show steps to user before pressing OK
    * Remove modal window
    * Turn into add-in / proper script
    * Add instructions / title to UI
    * Add utility modal
	
"""*/

Names Default To Here(1);

ask_steps = function({}, {Default Local},
	nw = New Window("Fill in Time to Event Steps", << Type("Modal Dialog"), << Return Result,
		H List Box(
			Panel Box("Fill in steps",
				Lineup Box(N Col(2),
					Text Box("Min Time"),
					neb_min = Number Edit Box(.),
					Text Box("Max Time"),
					neb_max = Number Edit Box(.),
					Text Box("Step Time"),
					neb_step = Number Edit Box(.),
					Text Box("Interpolate last"),
					cb_interpolate = Check Box({""}, << Set All(1))
				)
			),
			Spacer Box(Size(20, 0)),
			Panel Box("Actions",
				Button Box("OK"),
				Button Box("Cancel")
			)
		)
		, << Set Window Icon("Survival")
	);
	
	If(nw["Button"] != 1,
		Throw("Cancelled");
	);
	
	min_t = nw["neb_min"];
	max_t = nw["neb_max"];
	step_t = nw["neb_step"];

	If(Any(Is Missing(min_t), Is Missing(max_t), Is Missing(step_t)),
		Throw("Steps not filled in");
	);
	
	interpolate_last = N Items(nw["cb_interpolate"]);

	return(Eval List({min_t, max_t, step_t, interpolate_last}));
);

add_risk_table = function({platform_ref, min_t, max_t, step_t, interpolate_last}, {Default Local},

	rep = Report(platform_ref);
	dt = platform_ref << Get Data Table;
	
	ycol = ((rep << XPath("//TextBox[text()='Time to event: ']"))[1] << sib) << get text;
	grouping_col = ((rep << XPath("//TextBox[text()='Grouped by ']"))[1] << sib) << get text;
	Summarize(dt, groups = by(Eval(grouping_col)));

	steps = min_t::max_t::step_t;
	vals = steps;
	
	For Each({group}, groups,
		m_tb = rep[OutlineBox(group), Table Box(1)] << get as matrix;
		
		times = m_tb[0, 1];
		atrisk = m_tb[0, N Cols(m_tb)];
		cur_steps = Step(steps, times, atrisk); // Last one isn't assumed in this
		
		If(interpolate_last,
			If(times[N Rows(times), 1] < max_t & Is Missing(cur_steps[N Cols(cur_steps)]),
				cur_steps[N Cols(cur_steps)] = atrisk[N Rows(times), 1];
			);			
		);
		vals = vals |/ cur_steps;
	);


	pb = Panel Box("Risk Table", tb_results = Table Box(
		String Col Box(Eval Insert("No at Risk (^ycol^)"), groups),
	));


	For(i = 1, i <= N Cols(vals), i++,
		cur_vals = vals[0, i];
		
		title = Char(Remove From(cur_vals, 1)[1]);
		
		tb_results << Append(Number Col Box(title, cur_vals));
	);

	rep[List Box(2)] << Append(pb);
	rep[List Box(2)] << Append(Spacer Box(Size(0, 10)));
);



cur_rep = Current Report();
If(Is Empty(cur_rep),
	Throw("No reports open");
);

ob_ref = cur_rep << XPath("//OutlineBox[@helpKey='Surv']");

If(N Items(ob_ref) == 0,
	Throw("No Surv platform found");
);

Try(
	{min_t, max_t, step_t, interpolate_last} = ask_steps();

	platform_ref = ob_ref[1] << get scriptable object;

	add_risk_table(platform_ref, min_t, max_t, step_t, interpolate_last);
,
	Throw("Other issues: " || char(exception_msg));
);


Write();

 

 

-Jarmo