How to calculate linear regression between two time series and remove?

7 views (last 30 days)
I want to calculate the following between two time series:
R^2, slope, intercept , p, q,
and if possible q^hat
I know how to get r^2 for the whole timeseries but I would like to get this as a timeseries of coefficients.
I need the slope, P and the intercept in order to calculate q^hat (if it is not possible to get directly using a function) so that I can remove the relationship trend between two time series from one timeseries, like what is done using FERRET here: http://ferret.pmel.noaa.gov/static/FAQ/analysis/regressions.html
So far, I only know of 'corrcoef' which I can use to get R^2 and 'regression' to get the slope.
Can anyone help me?
thanks, Michael

Accepted Answer

Star Strider
Star Strider on 23 Sep 2014
The easiest way is to use polyfit and polyval:
b = polyfit(p, q, 1); % Choose Degree ‘1’ for Linear Regression, b(1)=slope, b(2)=intercept
qhat = polyval(b, p);
Using corrcoef will give you the ‘R’ values, and you can get their statistical significance if you ask for ‘P’ as well.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!