Skip to content

Data Science Tutorials

  • Home
  • R
  • Statistics
  • Course
  • Machine Learning
  • Guest Blog
  • Contact
  • About Us
  • Toggle search form
  • How to Replace Inf Values with NA in R
    How to Replace Inf Values with NA in R R
  • Top 7 Skills Required to Become a Data Scientist
    Top 7 Skills Required to Become a Data Scientist Machine Learning
  • How to Add a title to ggplot2 Plots in R
    How to Add a caption to ggplot2 Plots in R? R
  • Augmented Dickey-Fuller Test in R
    Augmented Dickey-Fuller Test in R R
  • Data Scientist in 2023
    How to Become a Data Scientist in 2023 Machine Learning
  • How to do Pairwise Comparisons in R?
    How to do Pairwise Comparisons in R? R
  • How to perform kruskal wallis test in r
    How to perform the Kruskal-Wallis test in R? R
  • Methods for Integrating R and Hadoop
    Methods for Integrating R and Hadoop complete Guide R
Survival Plot in R

How to Perform a Log Rank Test in R

Posted on May 30May 30 By Jim No Comments on How to Perform a Log Rank Test in R
Tweet
Share
Share
Pin

 How to Perform a Log Rank Test in R, The most frequent technique to compare survival curves between two groups is to use a log-rank test.

The following hypotheses are used in this test

H0: There is no difference in survival between the two groups.

HA: There is a difference in survival between the two groups.

Artificial Intelligence Examples-Quick View – Data Science Tutorials

We can reject the null hypothesis and conclude that there is enough evidence to claim there is a difference in survival between the two groups if the p-value of the test is less than some significance level (e.g. =0.05).

In R, we may use the survdiff() function from the survival package to do a log-rank test, which has the following syntax.

Best Books to Learn R Programming – Data Science Tutorials

How to Perform a Log Rank Test in R

survdiff(Surv(time, status) ~ predictors, data)

The Chi-Squared test statistic and related p-value are returned by this function.

This function is used to execute a log-rank test in R, as seen in the example below.

Example: Log Rank Test in R

We’ll use the ovarian dataset from the survival package for this example. The following information about 26 patients may be found in this dataset:

After being diagnosed with ovarian cancer, how long do you live (in months)?

Whether or whether the time spent surviving was censored

(rx = 1 or rx = 2) Type of treatment received

The following code demonstrates how to inspect the dataset’s first six rows.

Principal Component Analysis in R »

library(survival)

Let’s view the first six rows of the dataset

head(ovarian)
  futime fustat     age resid.ds rx ecog.ps
1     59      1 72.3315        2  1       1
2    115      1 74.4932        2  1       1
3    156      1 66.4658        2  1       2
4    421      0 53.3644        2  2       1
5    431      1 50.3397        2  1       1
6    448      0 56.4301        1  1       2

The following code demonstrates how to use a log-rank test to see if patients who got various treatments had different survival rates.

make a log-rank test

survdiff(Surv(futime, fustat) ~ rx, data=ovarian)
Call:
survdiff(formula = Surv(futime, fustat) ~ rx, data = ovarian)
      N Observed Expected (O-E)^2/E (O-E)^2/V
rx=1 13        7     5.23     0.596      1.06
rx=2 13        5     6.77     0.461      1.06
 Chisq= 1.1  on 1 degrees of freedom, p= 0.3

With one degree of freedom, the Chi-Squared test statistic is 1.1, and the associated p-value is 0.3. We cannot reject the null hypothesis because the p-value is not smaller than 0.05.

To put it another way, we don’t have enough evidence to establish that the two treatments have a statistically significant difference in survival.

Best Books on Data Science with Python – Data Science Tutorials

The survival curves for each group can alternatively be plotted using the following syntax.

For each therapy group, draw a survival curve.

plot(survfit(Surv(futime, fustat) ~ rx, data = ovarian),
     xlab = "Time",
     ylab = "Survival probability")

In R, a plot of survival curves.

Although the survival curves change somewhat, the difference is not statistically significant, according to the log-rank test.

Tweet
Share
Share
Pin
R

Post navigation

Previous Post: How to compare variances in R
Next Post: Interactive 3d plot in R-Quick Guide

Related Posts

  • How to Calculate Relative Frequencies in R
    How to Calculate Relative Frequencies in R? R
  • How to compare the performance of different algorithms in R
    How to compare the performance of different algorithms in R? R
  • Add new calculated variables to a data frame and drop all existing variables
    Add new calculated variables to a data frame and drop all existing variables R
  • Radar plot in R
    How to create Radar Plot in R-ggradar R
  • Detecting and Dealing with Outliers
    Detecting and Dealing with Outliers: First Step R
  • Gamma distribution in R
    Gamma distribution in R R

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • About Us
  • Contact
  • Disclaimer
  • Guest Blog
  • Privacy Policy
  • YouTube
  • Twitter
  • Facebook
  • Tips for Data Scientist Interview Openings
  • What is Epoch in Machine Learning?
  • Dynamic data visualizations in R
  • How Do Machine Learning Chatbots Work
  • Convex optimization role in machine learning

Check your inbox or spam folder to confirm your subscription.

  • Sampling from the population in R
  • Two of the Best Online Data Science Courses for 2023
  • Process of Machine Learning Optimisation?
  • ggplot2 scale in R (grammar for graphics)
  • ggplot aesthetics in R (Grammer of graphics)
  • Load Multiple Packages in R
    Load Multiple Packages in R R
  • How to Find Optimal Clusters in R, K-means clustering is one of the most widely used clustering techniques in machine learning.
    How to Find Optimal Clusters in R? R
  • Best Online Course For Statistics
    Free Best Online Course For Statistics Course
  • best books about data analytics
    Best Books to learn Tensorflow Course
  • How do confidence intervals work
    How do confidence intervals work? R
  • Correlation Coefficient p value in R
    Correlation Coefficient p value in R R
  • How to change the column positions in R?
    How to change the column positions in R? R
  • Defensive Programming Strategies in R
    Defensive Programming Strategies in R Machine Learning

Copyright © 2023 Data Science Tutorials.

Powered by PressBook News WordPress theme