Linear Models in R Tutorial | Survival Analysis in R

1. Linear Models in R – Objective

In this tutorial, we are going to discuss Generalized Linear Models in R with their types. Along with this, we will also cover uses, the syntax of different generalized models.

Generalized Linear Models in R Tutorial

Generalized Linear Models in R Tutorial

2. What are the Generalized Linear Models in R?

We are aware that the response variable is quantitative and normally distributed. So, now let us pay more attention to two types of models namely-
Logistic regression and Poisson regression.
As both belong to a family of regression models called generalized linear models.
After this model, some new models are extended called generalized linear model. That allows the mean to depend on the explanatory variables through a link function.
For Example – Normal, Poisson, Binomial
In R, we can use the function glm() to work with generalized linear models in R. Thus, the usage of glm() is like that of the function lm() which we before used for much linear regression. We use an extra argument family. That is to describe the error distribution. And link function to be used in the model to show the main difference.

GLM are fit using the glm( ) function. The form of the glm function is –
glm(formula, family=familytype(link=linkfunction), data=)

a. Logistic Regression

Logistic Regression is a method for fitting a regression curve, y = f(x) when y is a categorical variable. 
It is a classification algorithm. We use it to predict a binary outcome (1 / 0, Yes / No, True / False) given a set of independent variables. To represent binary / categorical outcome, we use dummy variables.
It is a regression model in which the response variable was categorical values such as True/False or 0/1. Thus, it actually measures the probability of a binary response.
To perform logistic regression in R, use the command:

> glm( response ~ explanantory_variables , family=binomial)

b. Poisson Regression

Data is often collected in counts. Hence, many discrete response variables have counted as possible outcomes. While binomial counts are the number of successes in a fixed number of trials, n.
Poisson counts are the number of occurrences of some event in a certain interval of time (or space). Apart from this, Poisson counts have no upper bound and binomial counts only take values between 0 and n. 
To perform logistic regression in R, we use the command:

> glm( response ~ explanantory_variables , family=poisson)

Next to learn in generalized linear models in R is the Survival Analysis in R.

R Quiz

3. Survival Analysis in R

a. What is Survival Analysis?

a. Model time to event (esp. failure)a.used in medicine, biology, actuary, finance, engineering, sociology, etc.
b. Able to account for censoring
c. Able to compare between 2+ groups
d. Able to access the relationship between covariates and survival time
Install Package




Description of the parameters in Survival anlaysis in R

  • time is the follow-up time until the event occurs.
  • Generally, the event indicates the status of occurrence of the expected event.
  • Moreover, the formula is the relationship between the predictor variables.

b. Steps to Perform Survival Analysis in R

a. Package: survival >library (survival)
b. Create a survival subject: Surv
c. Kaplan – Meier Estimator: survfit
d. Mantel-Haenzel Test: survdiff
e. Cox Model: coxph

c. Creating the survival object

Created by Surv function

>Surv (time, time2, event, type=c
('right', 'left', 'interval',
('right', 'left', 'interval',
'counting', 'interval2'), origin=0

So, this was all on generalized linear models in R. Hope you like our explanation of Survival Analysis in R.

4. Conclusion – Linear Models in R

Hence, we have studied different types of generalized linear models in R. Along with their definition, uses, and syntax. Thus, it is clear that the most beneficial thing is that this model provides more flexibility. Still, if you have any query regarding R Linear Models, ask in the comment tab.

Reference for R

Leave a Reply

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.