- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- 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-value and R-squared from a linear regression in R?

We can use regression model object name with $r.squared to find the R-squared and a user defined function to extract the p-value.

## Example

Extracting R-Squared

> x<-c(32,37,68,87,32,43) > y<-c(12,8,6,3,5,3) > LinearRegression<-lm(y~x) > summary(LinearRegression)$r.squared [1] 0.2814271

Extracting p-value

> Regressionp <- function (modelobject) { if (class(modelobject) != "lm") stop("Not an object of class 'lm' ") f <- summary(modelobject)$fstatistic p <- pf(f[1],f[2],f[3],lower.tail=F) attributes(p) <- NULL return(p) > Regressionp(LinearRegression) [1] 0.2789025

- Related Questions & Answers
- How to extract the p-value from t test in R?
- How to display R-squared value on scatterplot with regression model line 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 extract the p-value and F-statistic from aov output in R?
- How to extract p-values for intercept and independent variables of a general linear model in R?
- How to extract the residuals and predicted values from linear model in R?
- How to extract first value from a list in R?
- How to find the mean squared error for linear model in R?
- How to find residual variance of a linear regression model in R?
- How to find the standardized coefficients of a linear regression model in R?
- How to perform group-wise linear regression for a data frame in R?
- How to extract correlation coefficient value from correlation test in R?
- How to extract the maximum value from named vector in R?
- How to extract characters from a string in R?

Advertisements