Selecting only p-value and r squared value from linear regression result

0 votes

I have built this linear regression model on top of the 'mtcars' data-set:

lm(mpg~disp+hp,data = mtcars)->mod1

Now, i'd want to see only the r.squared and p-value from the linear regression summary result.

summary(mod1)


Call:

lm(formula = mpg ~ disp + hp, data = mtcars)


Residuals:

    Min      1Q  Median      3Q     Max 

-4.7945 -2.3036 -0.8246  1.8582  6.9363 


Coefficients:

             Estimate Std. Error t value Pr(>|t|)    

(Intercept) 30.735904   1.331566  23.083  < 2e-16 ***

disp        -0.030346   0.007405  -4.098 0.000306 ***

hp          -0.024840   0.013385  -1.856 0.073679 .  

---

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


Residual standard error: 3.127 on 29 degrees of freedom

Multiple R-squared:  0.7482, Adjusted R-squared:  0.7309 

F-statistic: 43.09 on 2 and 29 DF,  p-value: 2.062e-09

May 22, 2018 in Data Analytics by BHARANI
• 420 points
1,386 views

1 answer to this question.

0 votes

You can use the $ symbol to select only the r.squared value:

summary(mod1)$r.squared

Similarly, you have to select the 4th column from the 'coefficients':

summary(mod1)$coefficients[,4]
answered May 22, 2018 by Bharani
• 4,660 points

Related Questions In Data Analytics

0 votes
1 answer

Dynamically select element from a list and work with it - Shiny R

Follow these steps: Import the data into R Check ...READ MORE

answered Dec 5, 2018 in Data Analytics by Maverick
• 10,840 points
3,732 views
0 votes
0 answers

Split a string and store it in multiple columns from a field in R

How to Split a string and store ...READ MORE

Jun 29, 2019 in Data Analytics by Anand
862 views
0 votes
1 answer

Read from database and store in R as dataframe

Your code would fetch you a MySQL ...READ MORE

answered Jul 30, 2019 in Data Analytics by anonymous
• 33,030 points
1,083 views
0 votes
1 answer

Steps to evaluate Linear Regression in R

 These are sequential steps which need to ...READ MORE

answered Jul 25, 2018 in Data Analytics by CodingByHeart77
• 3,750 points
1,178 views
+5 votes
2 answers
+1 vote
1 answer

R programming: Linear programming problems

The documentation for the lp package provides ...READ MORE

answered Feb 4, 2019 in Data Analytics by Tyrion anex
• 8,700 points
874 views
0 votes
1 answer

R programming: Linear Equation

Use expand.grid to get all possible combinations ...READ MORE

answered Apr 30, 2019 in Data Analytics by Sophie may
• 10,620 points
1,123 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
1,130 views
+1 vote
2 answers

Finding number of missing values and removing those missing values from a data-frame

To find number of missing values for ...READ MORE

answered Aug 14, 2019 in Data Analytics by anonymous
1,064 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP