({{, (RefLink[LogRankTest, paclet:ref/LogRankTest])[{(Subscript[data, 1]),(Subscript[data, 2]),…}] 
tests for equal hazard rates among the (Subscript[data, i]) using a log-rank type test. }, {, (RefLink[LogRankTest, paclet:ref/LogRankTest])[{(Subscript[data, 1]),(Subscript[data, 2]),…},wspec] 
performs a weighted log-rank test with weights wspec. }, {, (RefLink[LogRankTest, paclet:ref/LogRankTest])[{(Subscript[data, 1]),…},wspec,"property"]
returns the value of "property".}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[LogRankTest, paclet:ref/LogRankTest]) performs a hypothesis test on the (Subscript[data, i]) with null hypothesis (Subscript[H, 0]) that the true hazard rates of the populations are equal (Subscript[h, 1]) (t)==(Subscript[h, 2])( t)==… for all t≤τ and alternative hypothesis (Subscript[H, a]) that at least one (Subscript[h, i]) (t) is different for some value of t≤τ.

The number τ is generally taken to be the largest event time in the (Subscript[data, i]).

By default, a probability value or p-value is returned.

A small p-value suggests that it is unlikely that (Subscript[H, 0]) is true.

The (Subscript[data, i]) must be univariate {(Subscript[x, 1]),(Subscript[x, 2]),…}.

The (Subscript[data, i]) can be a (RefLink[SparseArray, paclet:ref/SparseArray]) or (RefLink[EventData, paclet:ref/EventData]) object.

(RefLink[LogRankTest, paclet:ref/LogRankTest]) is effectively based on (∑_((Subscript[t, i])≤τ))w((Subscript[t, i])) (o((Subscript[t, i]))-e((Subscript[t, i]))) where o(t), e(t), and w(t) are the observed number of events, the expected number of events based on the pooled sample, and some weights, respectively.

For named weight methods, the weight at time t, w(t), is generally based on the number at risk y, the number of events d, the product limit estimator (OverHat[s])(t) of the pooled sample, or a similar estimator (OverTilde[s])(t)==(∏_((Subscript[t, i])≤t))(1-((Subscript[d, i])/((Subscript[y, i])+1))) of the pooled sample.

The following weight specifications wspec can be given:

The values of ρ and γ can be any non-negative numbers.

Specifying ρ and γ yields Fleming–Harrington weights of the form (((OverHat[s])((Subscript[t, i])-1))^ρ)(((1-(OverHat[s])((Subscript[t, i])-1)))^γ).

Possible named weight specifications include:

For interval-censored data, the Zhao–Zhao–Sun–Kim generalized log-rank test is used.

(RefLink[LogRankTest, paclet:ref/LogRankTest])[{(Subscript[data, 1]),…},wspec,"HypothesisTestData"] returns a (RefLink[HypothesisTestData, paclet:ref/HypothesisTestData]) object htd that can be used to extract additional test results and properties using the form htd["property"].

(RefLink[LogRankTest, paclet:ref/LogRankTest])[{(Subscript[data, 1]),…},wspec,"property"] can be used to directly give the value of "property".

Properties related to the reporting of test results include:

The following options can be given:

OpenersPrimaryExamplesSection(Spacer1)Examples  (26)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Compare hazard rates using some sample data:

d1={32,34,28,26,31,25,29,31,28,25};
d2={30,19,28,35,35,29,33,32,31,29};

LogRankTest[{d1,d2}]

Create a (RefLink[HypothesisTestData, paclet:ref/HypothesisTestData]) object for repeated property extraction:

ℋ=LogRankTest[{d1,d2},0,"HypothesisTestData"]

ℋ["Properties"]

Test some censored data:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

A significant difference is detected at the 5% level:

LogRankTest[{e1,e2}]

Perform a weighted log-rank test:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

Use a named weight scheme:

LogRankTest[{e1,e2},"Gehan","TestDataTable"]

Use Fleming–Harrington weights:

ρ=1;γ=0;

LogRankTest[{e1,e2},{ρ,γ},"TestDataTable"]

Test for equal hazard rates with many samples:

m=BlockRandom[SeedRandom[23];Table[EventData[RandomVariate[PoissonDistribution[30],500],RandomChoice[{.1,.9}->{0,1},500]],{5}]];

A visual comparison of the survival rates:

Plot[Table[SurvivalModelFit[i][x],{i,m}]//Evaluate,{x,20,45},Exclusions->None]

A significant difference is not detected:

LogRankTest[m]

OpenersExampleSection1(Spacer1)Scope  (11)

OpenersExampleSubsection0(Spacer1)Testing  (7)

Obtain the p-value from a log-rank test:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

LogRankTest[{e1,e2}]

Simultaneously test a large number of groups:

ng=20;

e=BlockRandom[SeedRandom[4];Table[EventData[RandomVariate[PoissonDistribution[30],100],RandomChoice[{.9,.1}->{0,1},100]],{ng}]];

LogRankTest[e]

Compute the p-value for weighted log-rank tests:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

Named weighting schemes:

wspec={"AndersenPeto","Gehan","Equal","TaroneWare"};

Table[{w,LogRankTest[{e1,e2},w]},{w,wspec}]//Grid

Manually set Fleming–Harrington type weights:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

Fleming–Harrington weights with ρ==0.5` and γ==0:

LogRankTest[{e1,e2},.5]

Use fully specified Fleming–Harrington type weights:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

Fleming–Harrington weights with ρ==0.5` and γ==1:

LogRankTest[{e1,e2},{.5,1}]

Extract some properties from a (RefLink[HypothesisTestData, paclet:ref/HypothesisTestData]) object:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

ℋ=LogRankTest[{e1,e2},0,"HypothesisTestData"];

The p-value and test statistic:

ℋ["PValue"]

ℋ["TestStatistic"]

Extract any number of properties simultaneously:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

ℋ=LogRankTest[{e1,e2},0,"HypothesisTestData"];

The p-value, test statistic, and degrees of freedom:

ℋ[{"PValue","TestStatistic","DegreesOfFreedom"}]

OpenersExampleSubsection1(Spacer1)Reporting  (4)

Tabulate test results:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

LogRankTest[{e1,e2},0,"TestDataTable"]

Values from the table:

LogRankTest[{e1,e2},0,"TestEntries"]

Retrieve properties for custom reporting:

e=BlockRandom[SeedRandom[4];Table[EventData[RandomVariate[PoissonDistribution[30],100],RandomChoice[{.9,.1}->{0,1},100]],{20}]];

{t,p,df}=LogRankTest[e,0,{"TestStatistic","PValue","DegreesOfFreedom"}];

Grid[{{"Log\[Hyphen]Rank Test",SpanFromLeft},{"(χ^2)","p-value","d.o.f"},{t,p,df}},Frame->All]

Tabulate p-values and test statistics:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

LogRankTest[{e1,e2},0,"PValueTable"]

LogRankTest[{e1,e2},0,"TestStatisticTable"]

Visualize normalized weights used in the test:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

wtdata=Table[{i,Transpose[LogRankTest[{e1,e2},i,{"EventTimes","EventWeights"}]]},{i,{"Gehan","TaroneWare","Peto","Equal"}}];

Named weighting schemes tend to emphasize early events:

ListLinePlot[wtdata[[All,2]],PlotLegends->wtdata[[All,1]]]

wtdata2=Table[{i,Transpose[LogRankTest[{e1,e2},i,{"EventTimes","EventWeights"}]]},{i,{{0,0},{0,1},{1,0},{1,.5}}}];

Fleming–Harrington weights can be used to emphasize other event regions:

ListLinePlot[wtdata2[[All,2]],PlotLegends->ToString/@wtdata2[[All,1]]]

OpenersExampleSection2(Spacer1)Options  (4)

OpenersExampleSubsection2(Spacer1)Method  (3)

By default, the asymptotic (χ^2) distribution of the test statistic is used to compute p-values:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

LogRankTest[{e1,e2},0,Method->Automatic]

Random permutation-based tests may give better results with small samples:

LogRankTest[{e1,e2},0,Method->"Permutation"]

Specify the number of random permutations to perform:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

Specify 250 random permutations:

LogRankTest[{e1,e2},0,Method->{"Permutation","MaxSamples"->250}]

Fix the seed used to generate random permutations:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

Use a seed of 9:

LogRankTest[{e1,e2},0,Method->{"Permutation","RandomSeed"->9}]

OpenersExampleSubsection3(Spacer1)SignificanceLevel  (1)

The significance level is used for "TestConclusion" and "ShortTestConclusion":

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

LogRankTest[{e1,e2},0,"TestConclusion",SignificanceLevel->.005]//TraditionalForm

LogRankTest[{e1,e2},0,"TestConclusion",SignificanceLevel->.05]//TraditionalForm

LogRankTest[{e1,e2},0,"ShortTestConclusion",SignificanceLevel->.005]

LogRankTest[{e1,e2},0,"ShortTestConclusion",SignificanceLevel->.05]

OpenersExampleSection3(Spacer1)Properties & Relations  (7)

By default, the test statistic is assumed to follow a (RefLink[ChiSquareDistribution, paclet:ref/ChiSquareDistribution]) under (Subscript[H, 0]):

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];
e2=EventData[{30,19,28,35,35,29,33,32,31,29},{0,0,1,0,0,1,0,1,0,1}];

{t,df,p}=LogRankTest[{e1,e2},0,{"TestStatistic","DegreesOfFreedom","PValue"}]

SurvivalFunction[ChiSquareDistribution[df],t]==p

Weighting schemes allow for particular time points to be emphasized:

m=Round@RandomVariate[WeibullDistribution[5,30],{2,(10^4)}];

etimes=LogRankTest[m,0,"EventTimes"];

wspec={"Gehan","AndersenPeto","Peto","TaroneWare","Equal"};

wts=Table[Transpose[{etimes,LogRankTest[m,w,"EventWeights"]}],{w,wspec}];

Named schemes tend to place more weight on early events:

ListLinePlot[wts,PlotLegends->wspec]

Fleming–Harrington parameters allow fine control over weighting:

fhw=Table[Transpose[{etimes,LogRankTest[m,w,"EventWeights"]}],{w,Tuples[Range[0,2,1],{2}]}];

ListLinePlot[fhw,PlotLegends->ToString/@Tuples[Range[0,2,1],{2}]]

(RefLink[MannWhitneyTest, paclet:ref/MannWhitneyTest]) can be used in the absence of censoring with two samples:

data=RandomVariate[PoissonDistribution[30],{2,(10^4)}];

The tests are asymptotically equivalent:

MannWhitneyTest[data]

LogRankTest[data,{1,0}]

The Kruskal–Wallis test can be used in the absence of censoring with more than two samples:

data=RandomVariate[PoissonDistribution[30],{5,(10^4)}];

The tests are asymptotically equivalent:

LocationEquivalenceTest[data,"KruskalWallis",VerifyTestAssumptions->None]

LogRankTest[data,{1,0}]

Use (RefLink[SurvivalModelFit, paclet:ref/SurvivalModelFit]) to estimate survival probabilities:

e1=EventData[{32,34,28,26,31,25,29,31,28,25},{0,0,0,0,0,0,0,0,0,1}];

mod=SurvivalModelFit[e1];

Estimate the survival curve:

Plot[mod[t],{t,20,40},Exclusions->None]

Create a 95% confidence interval about the survival probability at 30:

mod["PointwiseBands"][30]

Use (RefLink[CoxModelFit, paclet:ref/CoxModelFit]) to estimate survival probabilities in the presence of covariates:

y=EventData[{8,22,6,4,12,11,2,34,25,15,8,6,34,6,32,1,15,9,9,6},{0,0,0,0,0,0,0,1,1,0,0,0,1,1,1,0,0,1,1,0}];
x={{67,1},{11,0},{32,0},{50,1},{65,1},{44,1},{20,1},{26,0},{69,1},{50,1},{25,1},{18,0},{63,1},{41,0},{30,0},{32,1},{46,1},{35,0},{33,0},{22,0}};

mod=CoxModelFit[{x,y},{a,b},{a,b}]

Obtain parameter estimates:

mod["ParameterTable"]

Visualize survival estimate at covariate levels a==50 and b==1:

Plot[Evaluate@{mod["SF"][{50,1}][t],mod["PointwiseBands"][{50,1}][t]},{t,0,40},PlotPoints->100,Exclusions->None]

The log rank test recognizes the path structure of a (RefLink[TemporalData, paclet:ref/TemporalData]):

td=TemporalData[];

LogRankTest[td]

Use the values directly:

LogRankTest[td["ValueList"]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[SurvivalModelFit, paclet:ref/SurvivalModelFit])  ▪  (RefLink[CoxModelFit, paclet:ref/CoxModelFit])  ▪  (RefLink[EventData, paclet:ref/EventData])  ▪  (RefLink[DistributionFitTest, paclet:ref/DistributionFitTest])  ▪  (RefLink[LocationTest, paclet:ref/LocationTest])  ▪  (RefLink[VarianceTest, paclet:ref/VarianceTest])  ▪  (RefLink[IndependenceTest, paclet:ref/IndependenceTest])  ▪  (RefLink[EmpiricalDistribution, paclet:ref/EmpiricalDistribution])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Hypothesis Tests, paclet:guide/HypothesisTests])}, {▪(RefLinkPlain[Survival Analysis, paclet:guide/SurvivalAnalysis])}})}})