Book Image

Clojure for Data Science

By : Henry Garner
Book Image

Clojure for Data Science

By: Henry Garner

Overview of this book

Table of Contents (18 chapters)
Clojure for Data Science
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Adjusted R-squared


As we add more independent variables to our regression, we might be encouraged by the fact that our R2 value always increases. Adding a new independent variable isn't going to make it harder to predict the dependent variable—if the new variable has no explanatory power, then its coefficient will simply be zero and the R2 will remain the same as it was without the independent variable.

However, this doesn't tell us whether a model has been improved by the addition of a new variable. If we want to know whether our new variable is really helping it to generate a better fit, we can use the adjusted R2, often written as and pronounced as "R-bar squared." Unlike R2, will only increase if the new independent variable increases R2 more than would be expected due to chance:

(defn matrix-adj-r-squared [coefs x y]
  (let [r-squared (matrix-r-squared coefs x y)
        n (count y)
        p (count coefs)]
    (- 1
       (* (- 1 r-squared)
          (/ (dec n)
             (dec (...