BookmarkSubscribeSubscribe to RSS Feed

Fitting models using data in a matrix

When I want to fit a regression model to a data set in script, I'll normally write something like the following:

dt = open("$SAMPLE_DATA/Big");

dt << Fit Model(
Y( :Height ),
Effects( :Weight ),
Personality( Standard Least Squares ),
Run Model

This assumes that the data is contained in a data table with columns named as in the example above, but is there a way to fit the same model using just data contained in columns of a matrix, i.e. without needing to turn that matrix into a data table first? If so, what would the syntax be?

Many thanks

Community Trekker


Jun 23, 2011

Hi David:

If it is truly OLS you are interested in:



Community Trekker


Jun 23, 2011

Perhaps you were thinking something like:

Hi Matt - yes, it's specifically OLS I've got in mind, and I'll probably end up writing the regression calculations out in matrix algebra as you have in you first post if there isn't an easier way. I'd actually been playing around with almost exactly what you suggested in your second post in the hope that I could bypass the need to do it in matrix algebra; but by the look of it that's probably going to be the simplest way - and the algebra's not difficult.

My main motivation for asking is to maximize the speed of the calculations, as I want to perform a large number of them in rapid succession, and don't want to waste time creating and then deleting large numbers of tables if it can be avoided, as I've found in the past that I can often speed things up dramatically by doing as much work as I can in matrix algebra.

Many thanks - it looks as if I'm on the right track, anyway.