# Measuring R squared of a linear regression with GLM and Dataframes

**URL:** <https://discourse.julialang.org/t/measuring-r-squared-of-a-linear-regression-with-glm-and-dataframes/511>\
**Category:** General Usage\
**Tags:** question, glm\
**Created:** [November 23, 2016, 12:54am UTC](https://discourse.julialang.org/t/measuring-r-squared-of-a-linear-regression-with-glm-and-dataframes/511 "2016-11-23T00:54:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sevimora](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@sevimora](https://discourse.julialang.org/u/sevimora)\
**Post date:** [November 23, 2016, 12:54am UTC](https://discourse.julialang.org/t/measuring-r-squared-of-a-linear-regression-with-glm-and-dataframes/511/1 "2016-11-23T00:54:49Z")

</div>

Hi

I am new to Julia. I do not see how to get the R^2 of a linear regression using DataFrames and GLM. I can get the sum of squares of the errors (so I am almost there), but not the R^2.

Is there a way of getting form the output of the regression the R^2, or at least the variance of the LHS variable?

Sorry if this is a silly question.

Thanks!

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [November 23, 2016, 7:50am UTC](https://discourse.julialang.org/t/measuring-r-squared-of-a-linear-regression-with-glm-and-dataframes/511/2 "2016-11-23T07:50:47Z")

</div>

There’s an `r2` function in StatsBase for this, which is reexported by DataFrames: [http://statsbasejl.readthedocs.io/en/stable/statmodels.html](http://statsbasejl.readthedocs.io/en/stable/statmodels.html)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [November 23, 2016, 8:11am UTC](https://discourse.julialang.org/t/measuring-r-squared-of-a-linear-regression-with-glm-and-dataframes/511/3 "2016-11-23T08:11:13Z")

</div>

A good trick is to try `whos(GLM)`, which will show all names exported by GLM. If you scroll down you will find the command `r2`, and you can continue with `?r2`.

---

<div class="post-metadata">

**Author:** ![sevimora](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@sevimora](https://discourse.julialang.org/u/sevimora)\
**Post date:** [November 23, 2016, 10:51am UTC](https://discourse.julialang.org/t/measuring-r-squared-of-a-linear-regression-with-glm-and-dataframes/511/4 "2016-11-23T10:51:29Z")

</div>

Thanks SO SO much!!!

You guys are great!!!

SEVI
