Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
R Square or coefficient of determination

Subject: R Square or coefficient of determination

From: Frank Sabouri

Date: 26 Oct, 2010 03:58:03

Message: 1 of 3

Hello,

I need to creat a vector of *R square*, in that size of predicors or 'X' is 100-by-9 and size of responses is 100-by-6. Therefore, I would expect that the size of *R square* should be 56-by-1. I suppose that the function regress each column of 'X' vs. each column of 'Y' sperately. Please let me know which function I could use to compute this *R squre*.

RSQUARE=fun(x,y) ; What is fun?

Thanks,

Frank

Subject: R Square or coefficient of determination

From: Anyone

Date: 26 Oct, 2010 04:43:50

Message: 2 of 3

Frank Sabouri wrote on 25-Oct-10 20:58 ...
> Hello,
>
> I need to creat a vector of *R square*, in that size of predicors or 'X'
> is 100-by-9 and size of responses is 100-by-6. Therefore, I would expect
> that the size of *R square* should be 56-by-1. I suppose that the
> function regress each column of 'X' vs. each column of 'Y' sperately.
> Please let me know which function I could use to compute this *R squre*.
>
> RSQUARE=fun(x,y) ; What is fun?

The answer to that will become obvious to everyone as soon as you code it.

Subject: R Square or coefficient of determination

From: Ben Taylor

Date: 1 Feb, 2012 23:17:10

Message: 3 of 3

This will work:

function R2=COD(y,f)
    y=reshape(y,1,prod(size(y)));
    f=reshape(f,1,prod(size(f)));
    %This calculates the coefficient of determination
    ymean=mean(y); %
    SStot=0;
    SSerr=0;
    for i=1:length(y); %loop through each point
        SStot=SStot+(y(i)-ymean)^2;
        SSerr=SSerr+(y(i)-f(i))^2;
    end
    R2=1-SSerr/SStot;
end %End function...

See wikipedia def. I use reshape incase I have a multidimensional dataset.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us