Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dealing with a regstats error

106 views
Skip to first unread message

Tim

unread,
May 3, 2012, 5:13:07 PM5/3/12
to
Hi, I have an issue with a regstats line in my code. Matlab keeps telling me that my " design matrix has more predictor variables than observations," but for the life of me I can't figure out why. I'm new to both Matlab and hardcore stats work, so any insight is greatly appreciated.

Currently, I have a dependent vector that's 36x1, and and independent matrix that's 36x20 (i.e., there are 36 different time points, one dependent variable, and 20 independent variables). It's in a FOR loop, and the line of code that's giving me the error is

stats(i) = regstats(dependentVar, independentVars,'linear',whichstats);

Whichstats is {'beta' 'rsquare' 'adjrsquare' 'tstat' 'fstat'}

I'm guessing the issue is the NaNs in the independent var matrix, but I'm had NaNs in regressions before and they haven't been a problem.

There are up to 9 missing entries from the time series (i.e. some rows are missing up to 9 data points) and up to 12 missing entries from each independent var (i.e., some columns are missing up to 12 data points).

I should have a specific question to ask, but unfortunately I can't pick one out yet. Can someone give me some guidance to help me determine where the issue is?

Steven_Lord

unread,
May 4, 2012, 10:01:26 AM5/4/12
to


"Tim " <timothy...@go.wustl.edu> wrote in message
news:jnusd3$eb6$1...@newscl01ah.mathworks.com...
If you remove all the rows from your independent matrix that contain at
least one NaN and remove the corresponding elements of your dependent
vector, what are the sizes of the new matrix and vector?

M = [magic(5); 1,2,3,4,5];
b = sum(M, 2);
stats = regstats(b, M, 'linear', 'all') % Works; 6 data points, 6 predictors
with the implicit constant
M([1 8]) = NaN
stats = regstats(b, M, 'linear', 'all') % Errors; only 4 data points (the
first two are removed) versus 6 predictors with the implicit constant
stats = regstats(b(3:end), M(3:end, :), 'linear', 'all') % Ditto

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tim

unread,
May 4, 2012, 2:14:07 PM5/4/12
to
Hey, thanks for helping me out! My code is still a mess, but can you help my Matlab understanding?

Given my limited knowledge and what you wrote, whenever I use the regstats function like this it'll only run the regression on the independent variable matrix rows that have no NaNs, and then the number of those rows (or, the number of entries in the dependent variable left) need to be one more than the columns in the independent matrix... something about degrees of freedom. Does that sound right?

The specific piece of code I was asking about turned out to be bad (the last thing I wrote that day), but understanding how regstats works will be very helpful in my program design.

Steven_Lord

unread,
May 6, 2012, 9:51:20 PM5/6/12
to


"Tim " <timothy...@go.wustl.edu> wrote in message
news:jo169f$m2g$1...@newscl01ah.mathworks.com...
> Hey, thanks for helping me out! My code is still a mess, but can you help
> my Matlab understanding?
>
> Given my limited knowledge and what you wrote, whenever I use the regstats
> function like this it'll only run the regression on the independent
> variable matrix rows that have no NaNs, and then the number of those rows
> (or, the number of entries in the dependent variable left) need to be one
> more than the columns in the independent matrix... something about degrees
> of freedom. Does that sound right?

You need at least as many rows as columns, I believe.

> The specific piece of code I was asking about turned out to be bad (the
> last thing I wrote that day), but understanding how regstats works will be
> very helpful in my program design.

0 new messages