Prev: xPC Real-time interrupt source
Next: Linear combination of linearly independent rows/columns of matrix
From: Konrad on 22 Apr 2010 07:37 Hi everyone, I'm a MatLab greenhorn, so excuse me if my question seems too simple. I've been failing for hours to solve it. Within a small MatLab routine, I'm fitting a linear function to a data set of four x and four y values, using coefficients = polyfit (x, y, 1). I'd also like to know the coefficient of determination, aka R-square, but I haven't found out how to get it without opening the cftool or plunging deep into the mysteries of structures and "fittype" etc. (I tried "f=fittype('a*x+b'), in order to then get the rsquare out of "fit", but it gives an error message.) Thanks for help, Konrad
From: Yi Cao on 22 Apr 2010 07:53 "Konrad " <Konrad.Lehmann(a)uni-jena.de> wrote in message <hqpcd1$8qu$1(a)fred.mathworks.com>... > Hi everyone, > > I'm a MatLab greenhorn, so excuse me if my question seems too simple. I've been failing for hours to solve it. > > Within a small MatLab routine, I'm fitting a linear function to a data set of four x and four y values, using coefficients = polyfit (x, y, 1). I'd also like to know the coefficient of determination, aka R-square, but I haven't found out how to get it without opening the cftool or plunging deep into the mysteries of structures and "fittype" etc. (I tried "f=fittype('a*x+b'), in order to then get the rsquare out of "fit", but it gives an error message.) > > Thanks for help, > Konrad If you talk about the squared residual of the linear fitting, you can calculate it by r = y - c(1)*x - c(2); r2 = r.*r; HTH Yi
From: Konrad on 22 Apr 2010 08:24 Thanks, but your function returns the sum of squared errors. That is different from R² which nears 1 for a good fit. Does R² have a similarly simple formula? Thanks, Konrad "Yi Cao" <y.cao(a)cranfield.ac.uk> wrote in message <hqpdb1$oc4$1(a)fred.mathworks.com>... > "Konrad " <Konrad.Lehmann(a)uni-jena.de> wrote in message <hqpcd1$8qu$1(a)fred.mathworks.com>... > > Hi everyone, > > > > I'm a MatLab greenhorn, so excuse me if my question seems too simple. I've been failing for hours to solve it. > > > > Within a small MatLab routine, I'm fitting a linear function to a data set of four x and four y values, using coefficients = polyfit (x, y, 1). I'd also like to know the coefficient of determination, aka R-square, but I haven't found out how to get it without opening the cftool or plunging deep into the mysteries of structures and "fittype" etc. (I tried "f=fittype('a*x+b'), in order to then get the rsquare out of "fit", but it gives an error message.) > > > > Thanks for help, > > Konrad > > If you talk about the squared residual of the linear fitting, you can calculate it by > > r = y - c(1)*x - c(2); > r2 = r.*r; > > HTH > Yi
From: John D'Errico on 22 Apr 2010 08:24 "Konrad " <Konrad.Lehmann(a)uni-jena.de> wrote in message <hqpcd1$8qu$1(a)fred.mathworks.com>... > Hi everyone, > > I'm a MatLab greenhorn, so excuse me if my question seems too simple. I've been failing for hours to solve it. > > Within a small MatLab routine, I'm fitting a linear function to a data set of four x and four y values, using coefficients = polyfit (x, y, 1). I'd also like to know the coefficient of determination, aka R-square, but I haven't found out how to get it without opening the cftool or plunging deep into the mysteries of structures and "fittype" etc. (I tried "f=fittype('a*x+b'), in order to then get the rsquare out of "fit", but it gives an error message.) > > Thanks for help, > Konrad I'm pretty sure that I return the R^2 parameter from polyfitn. So you could use that tool instead of polyfit. http://www.mathworks.com/matlabcentral/fileexchange/10065 HTH, John
From: Konrad on 22 Apr 2010 09:03 Hi John, I've downloaded your function, but don't see how I get R² out of it. Could you please indicate how it is done? Best wishes, Konrad
|
Next
|
Last
Pages: 1 2 Prev: xPC Real-time interrupt source Next: Linear combination of linearly independent rows/columns of matrix |