EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials R Programming Tutorial Poisson Regression in R
Secondary Sidebar
R programming Tutorial
  • Regression in R
    • Simple Linear Regression in R
    • Linear Regression in R
    • Multiple Linear Regression in R
    • Logistic Regression in R
    • Poisson Regression in R
    • OLS Regression in R
    • P-Value in Regression
  • Basic
    • What is R Programming Language
    • Careers in R Programming
    • Install R
    • List of R Packages
    • Introduction of R Tools Technology
    • R Programming Language
    • DataSet in R
    • What is RStudio?
    • R-studio-Functions
    • R Packages
    • Time series?in R
    • R Data Types
    • R for data science
    • R Operators
    • R Data Frame
    • R Analytics Tool
    • R Tree Package
    • Vectors in R
  • Control statement
    • If Statement in R
    • If Else Statement in R
    • Else if in R
    • Switch Statement in R
  • Loops
    • Loops in R
    • For Loop in R
    • Nested For Loop in R
    • While Loop in R
    • Next in R
  • Chart/graphs
    • Graphs in R
    • Bar Charts in R
    • Pie Chart in R
    • Histogram in R
    • Line Graph in R
    • Plot Function in R
    • Scatterplot in R
    • R Boxplot labels
  • Anova in R
    • ANOVA in R
    • One Way ANOVA in R
    • Two Way ANOVA in R
  • Data Structure
    • R list
    • Arrays in R
    • Data Frames in R
    • Factors in R
    • R Vectors
  • Advanced
    • Statistical Analysis with R
    • R String Functions
    • Data Exploration in R
    • R CSV Files
    • KNN Algorithm in R
    • Sorting in R
    • lm Function in R
    • Hierarchical Clustering in R
    • R Normal Distribution
    • Binomial Distribution in R
    • Decision Tree in R
    • GLM in R
    • Arima Model in R
    • Linear Model in R
    • Predict Function in R
    • Survival Analysis in R
    • Standard Deviation in R
    • Statistical Analysis in R
    • Predictive Analysis?in R
    • T-test in R
    • Database in R
  • Programs
    • Functions in R
    • Boxplot in R
    • R Program Functions
    • Factorial in R
    • Random Number Generator in R
  • Interview question
    • R Interview Questions

Related Courses

R Programming Certification Course

Statistical Analysis Course Training

All in One Data Science Courses

Poisson Regression in R

By Priya PedamkarPriya Pedamkar

Poisson Regression in R

Introduction to Poisson Regression in R

Poisson Regression in R is a type of regression analysis model which is used for predictive analysis where there are multiple numbers of possible outcomes expected which are countable in numbers. R language provides built-in functions to calculate and evaluate the Poisson regression model. Poisson regression is useful to predict the value of the response variable Y by using one or more explanatory variable X. This is a preferred probability distribution which is of discrete type. One of the use cases of a Poisson regression model would be predicting the number of leads that will convert to customers within a particular time frame in an organization.

Implementing Poisson Regression

We’ll now proceed to understand how the model is applied. The following section gives a step-by-step procedure for the same. For this demonstration, we are considering the “gala” dataset from the “faraway” package. It pertains to the species diversity on the Galapagos Islands. There are altogether 7 variables in the dataset. We’ll use Poisson regression to define a relationship between the number of plant species (Species) with other variables in the dataset.

1. First load the “faraway” package. In case, the package is not present, download it using install.packages() function.

poission

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

2. Once the package is loaded, load the “gala” dataset into R using data() function as shown below.

poission regression in R

3. The loaded data should be visualized to study the variable and verify if there are any discrepancies. We can visualize either the entire data or just the first few rows of it using the head() function as shown in the below screenshot.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,241 ratings)

poission regression in R2

4. To get more insight into the dataset, we can use help functionality in R as below. It generates the R documentation as shown in the screenshot subsequent to the below screenshot.

poission regression in Rpoission regression in r

5. If we study the dataset as mentioned in the preceding steps, then we can find that Species is a response variable. We’ll now study a basic summary of the predictor variables.

poission

Note, as can be seen above, we have excluded the variable Species. The summary function gives us basic insights. Just observe the median values for each of these variables, and we can find that a huge difference, in terms of the range of values, exists between the first half and the second half, e.g. for Area variable median value is 2.59, but the maximum value is 4669.320.

6. Now that we are done with basic analysis, we’ll generate a histogram for Species in order to check if the variable follows the Poisson distribution. This is illustrated below.

poission regression in R

The above code generates a histogram for Species variable along with a density curve superimposed over it.

poission regression in R

The above visualization shows that Species follows a Poisson distribution, as the data is right-skewed. We can generate a boxplot too, to get more insight into the distribution pattern as shown below.

boxplot of species

7. Having done with the preliminary analysis, we’ll now apply Poisson regression as shown below

prilliminary analysis

Based on the above analysis, we find that variables Endemics, Area, and Nearest are significant and only their inclusion is sufficient to build the right Poisson regression model.

8. We’ll build a modified Poisson regression model taking into consideration three variables only viz. Endemics, Area, and Nearest. Let’s see what results we get.

fit.reduced

The output produces deviances, regression parameters, and standard errors. We can see that each of the parameters is significant at p < 0.05 level.

9. The next step is to interpret the model parameters. The model coefficients can be obtained either by examining Coefficients in the above output or by using coef() function.

poission

In Poisson regression, the dependent variable is modeled as the log of the conditional mean loge(l). The regression parameter of 0.0355 for Endemics indicates that a one-unit increase in the variable is associated with a 0.04 increase in the log mean number of Species, holding other variables constant. The intercept is a log mean number of Species when each of the predictors equals zero.

10. However, it is much easier to interpret the regression coefficients in the original scale of the dependent variable (number of Species, rather than log number of Species). The exponentiation of the coefficients will allow an easy interpretation. This is done as follows.

poission

From the above findings, we can say that one unit increase in Area multiples the expected number of species by 0.9999, and a unit increase in the number of endemic species represented by Endemics multiplies the number of species by 1.0361. The most important aspect of Poisson regression is that exponentiated parameters have a multiplicative rather than an additive effect on the response variable.

11. Using the above steps, we obtained a Poisson regression model for predicting the number of plant species on the Galapagos Islands. However, it is very important to check for overdispersion. In Poisson regression, the variance and means are equal.

Overdispersion occurs when the observed variance of the response variable is larger than would be predicted by the Poisson distribution. Analyzing overdispersion becomes important as it is common with count data, and can negatively impact the final results. In R, overdispersion can be analyzed using the “qcc” package. The analysis is illustrated below.

overdispersion

The above significant test shows that the p-value is less than 0.05, which strongly suggests the presence of overdispersion. We’ll try fitting a model using glm() function, by replacing family = “Poisson” with family = “quasipoisson”.  This is illustrated below.

coefficients

Closely studying the above output, we can see that the parameter estimates in the quasi-Poisson approach are identical to those produced by the Poisson approach, though the standard errors are different for both the approaches. Moreover, in this case, for Area, the p-value is greater than 0.05 which is due to larger standard error.

Importance of Poisson Regression

  • Poisson Regression in R is useful for correct predictions of the discrete / count variable.
  • It helps us identify those explanatory variables which have a statistically significant effect on the response variable.
  • Poisson Regression in R is best suitable for events of “rare” nature as they tend to follow a Poisson distribution as against common events that usually follow a normal distribution.
  • It is suitable for application in cases where the response variable is a small integer.
  • It has wide applications, as a prediction of discrete variables is crucial in many situations. In medicine, it can be used to predict the impact of the drug on health. It is heavily used in survival analysis like the death of biological organisms, failure of mechanical systems, etc.

Conclusion

Poisson regression is based on the concept of Poisson distribution. It is another category belonging to the set of regression techniques that combines the properties of both Linear as well as Logistic regressions. However, unlike Logistic regression which generates only binary output, it is used to predict a discrete variable.

Recommended Articles

This is a guide to Poisson Regression in R. Here we discuss the introduction Implementing Poisson Regression and Importance of Poisson Regression. You can also go through our other suggested articles to learn more–

  1. GLM in R
  2. Random Number Generator in R
  3. Regression Formula
  4. Logistic Regression in R
  5. Linear Regression vs Logistic Regression | Top Differences
  6. Learn the Concept of Regression in Machine Learning
  7. Guide to Boxplot in Matlab
Popular Course in this category
R Programming Training (13 Courses, 20+ Projects)
  13 Online Courses |  20 Hands-on Projects |  120+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Statistical Analysis Training (15 Courses, 10+ Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
2 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more