Prev: Passing data between functions in a GUI
Next: reshape
From: Ahren Ceisel on 9 Mar 2010 12:45 I am using the regress function to do linear fits of a number of three-dimensional data sets (two regressors and one observation) and seem to be getting R^2 values greater than 1 for some of the sets. From the info in Matlab's help, I get the impression that the first element in the "stats" vector that regress outputs is supposed to be the R^2 value. Am I looking at the wrong number or am I incorrect in my understanding that R^2 should never be greater than 1?
From: Wayne King on 9 Mar 2010 13:33 "Ahren Ceisel" <ceisahr(a)iit.edu> wrote in message <hn61f3$2i6$1(a)fred.mathworks.com>... > I am using the regress function to do linear fits of a number of three-dimensional data sets (two regressors and one observation) and seem to be getting R^2 values greater than 1 for some of the sets. From the info in Matlab's help, I get the impression that the first element in the "stats" vector that regress outputs is supposed to be the R^2 value. Am I looking at the wrong number or am I incorrect in my understanding that R^2 should never be greater than 1? Hi Ahren, are you including a column of 1's in your design matrix to represent the constant term? So if you have two predictor variables, you would have a Nx3 design matrix. Wayne
From: Aaron on 9 Mar 2010 13:44 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hn6491$66e$1(a)fred.mathworks.com>... > "Ahren Ceisel" <ceisahr(a)iit.edu> wrote in message <hn61f3$2i6$1(a)fred.mathworks.com>... > > I am using the regress function to do linear fits of a number of three-dimensional data sets (two regressors and one observation) and seem to be getting R^2 values greater than 1 for some of the sets. From the info in Matlab's help, I get the impression that the first element in the "stats" vector that regress outputs is supposed to be the R^2 value. Am I looking at the wrong number or am I incorrect in my understanding that R^2 should never be greater than 1? > > Hi Ahren, are you including a column of 1's in your design matrix to represent the constant term? So if you have two predictor variables, you would have a Nx3 design matrix. > > Wayne No, I hadn't been; thanks for bringing that to my attention. However, would that oversight somehow cause R^2 to be greater than 1 in some cases?
From: Wayne King on 9 Mar 2010 13:53 "Aaron " <ceisahr(a)iit.edu> wrote in message <hn64tl$h5a$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hn6491$66e$1(a)fred.mathworks.com>... > > "Ahren Ceisel" <ceisahr(a)iit.edu> wrote in message <hn61f3$2i6$1(a)fred.mathworks.com>... > > > I am using the regress function to do linear fits of a number of three-dimensional data sets (two regressors and one observation) and seem to be getting R^2 values greater than 1 for some of the sets. From the info in Matlab's help, I get the impression that the first element in the "stats" vector that regress outputs is supposed to be the R^2 value. Am I looking at the wrong number or am I incorrect in my understanding that R^2 should never be greater than 1? > > > > Hi Ahren, are you including a column of 1's in your design matrix to represent the constant term? So if you have two predictor variables, you would have a Nx3 design matrix. > > > > Wayne > > No, I hadn't been; thanks for bringing that to my attention. However, would that oversight somehow cause R^2 to be greater than 1 in some cases? It can cause all sorts of strange behavior including a negative R^2 (I think that case may be explicitly mentioned in the doc). Wayne
From: Aaron on 9 Mar 2010 14:10
"Wayne King" <wmkingty(a)gmail.com> wrote in message <hn65eh$llk$1(a)fred.mathworks.com>... > "Aaron " <ceisahr(a)iit.edu> wrote in message <hn64tl$h5a$1(a)fred.mathworks.com>... > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hn6491$66e$1(a)fred.mathworks.com>... > > > "Ahren Ceisel" <ceisahr(a)iit.edu> wrote in message <hn61f3$2i6$1(a)fred.mathworks.com>... > > > > I am using the regress function to do linear fits of a number of three-dimensional data sets (two regressors and one observation) and seem to be getting R^2 values greater than 1 for some of the sets. From the info in Matlab's help, I get the impression that the first element in the "stats" vector that regress outputs is supposed to be the R^2 value. Am I looking at the wrong number or am I incorrect in my understanding that R^2 should never be greater than 1? > > > > > > Hi Ahren, are you including a column of 1's in your design matrix to represent the constant term? So if you have two predictor variables, you would have a Nx3 design matrix. > > > > > > Wayne > > > > No, I hadn't been; thanks for bringing that to my attention. However, would that oversight somehow cause R^2 to be greater than 1 in some cases? > > It can cause all sorts of strange behavior including a negative R^2 (I think that case may be explicitly mentioned in the doc). > > Wayne I didn't see anything about negative R^2 in the documentation I have, but I do know that some methods of computing R^2 can yield negative values legitimately--but I've never heard of a method that leads to >1 outputs. I have to run it again with the column for the constants added anyway. However, I'm still concerned that something is wrong because R^2 should be equal to one minus the ratio of two positive numbers--and hence less than one--even if there is no constant term in the calculated linear equation. |