- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to extract p-values for intercept and independent variables of a general linear model in R?
General linear model does not assume that the variables under consideration are normally distributed, therefore, we can use other probability distributions to create a general linear model. We should actually say that if the data does not follow normal distribution then we can try different distributions using general linear model and check whether the model is appropriate or not. The p-values plays an important role in selecting the best model and we might want to extract them from the model object. This can be done by using coef function.
Example
Consider the below data frame −
> set.seed(123) > var1<-rnorm(20,0.5) > var2<-rnorm(20,1.5) > var3<-rnorm(20,2.5) > Response<-rpois(20,2) > df<-data.frame(var1,var2,var3,Response) > df
Output
var1 var2 var3 Response 1 -0.06047565 0.4321763 1.8052930 2 2 0.26982251 1.2820251 2.2920827 1 3 2.05870831 0.4739956 1.2346036 1 4 0.57050839 0.7711088 4.6689560 1 5 0.62928774 0.8749607 3.7079620 1 6 2.21506499 -0.1866933 1.3768914 6 7 0.96091621 2.3377870 2.0971152 1 8 -0.76506123 1.6533731 2.0333446 0 9 -0.18685285 0.3618631 3.2799651 1 10 0.05433803 2.7538149 2.4166309 3 11 1.72408180 1.9264642 2.7533185 2 12 0.85981383 1.2049285 2.4714532 4 13 0.90077145 2.3951257 2.4571295 2 14 0.61068272 2.3781335 3.8686023 3 15 -0.05584113 2.3215811 2.2742290 2 16 2.28691314 2.1886403 4.0164706 2 17 0.99785048 2.0539177 0.9512472 3 18 -1.46661716 1.4380883 3.0846137 3 19 1.20135590 1.1940373 2.6238542 5 20 0.02720859 1.1195290 2.7159416 2
> General_LM<-glm(Response~var1+var2+var3,df,family=poisson()) > summary(General_LM)
Output
Call: glm(formula = Response ~ var1 + var2 + var3, family = poisson(), data = df) Deviance Residuals: Min 1Q Median 3Q Max -1.8886 -0.6977 -0.1502 0.7453 1.4222 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 1.00642 0.50653 1.987 0.0469 * var1 0.18546 0.16256 1.141 0.2539 var2 -0.04053 0.18234 -0.222 0.8241 var3 -0.10772 0.16206 -0.665 0.5063 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 18.704 on 19 degrees of freedom Residual deviance: 16.376 on 16 degrees of freedom AIC: 74.43 Number of Fisher Scoring iterations: 5 > coef(summary(General_LM))[,4] (Intercept) var1 var2 var3 0.0469347 0.2539288 0.8241122 0.5062662
- Related Articles
- How to extract the residuals and predicted values from linear model in R?
- How to extract odds ratio of intercept and slope coefficient from simple logistic model in R?
- How to extract p-value and R-squared from a linear regression in R?
- How to extract the regression coefficients, standard error of coefficients, t scores, and p-values from a regression model in R?
- How to display p-value with coefficients in stargazer output for linear regression model in R?
- How to change the order of independent variables for regression summary output in R?
- How do we identify dependent variable and independent variables in linear graph ?
- How to create a predictive linear regression line for a range of independent variable in base R?
- Create scatterplot for two dependent variables and one independent variable in R.
- Differentiate between categorical and numerical independent variables in R.
- How to extract the model equation from model object in R?
- How to display regression intercept using model in a plot created by ggplot2 in R?
- How to calculate root mean square error for linear model in R?
- How to find the mean squared error for linear model in R?
- How to extract variables of an S4 object in R?

Advertisements