Message Boards Message Boards

6 Replies
6 Total Likes
View groups...
Share this post:

How does one use LinearModelFit with multiple y variables?

Using a list as the y variable would seem most natural but doesn't work.
POSTED BY: Philip Maymin
6 Replies
Wonderful! Thank you Vitaliy and Daniel.
POSTED BY: Philip Maymin
You'd lose the covarianece between the two variables. In some applications, that's fine, and people just do several independent univariate regressions. But sometimes you really want to do a single multivariate one. There's a whole literature on it, the general linear model, MANOVA, etc.
POSTED BY: Philip Maymin
Is there some reason to do this other than one at a time? Offhand I do not see a drawback to that approach.
POSTED BY: Daniel Lichtblau
For example let's say we want to simultaneously predict GDP and Population as a linear function of the Area and Coastline Length for each country having sufficient data:
data = Cases[  Table[CountryData[country, property], {country,     CountryData[]}, {property, {"Area", "CoastlineLength", "GDP",      "Population"}}], {_Real ..}];
There is no problem predicting either GDP or Population separately. Each of the following works:
LinearModelFit[data[[All, {1, 2, 3}]], {area, coast}, {area, coast}]
LinearModelFit[data[[All, {1, 2, 4}]], {area, coast}, {area, coast}]
And one would imagine this would generalize to multivariate regressions with multiple outcome variables naturally:
LinearModelFit[{#1, #2, {#3, #4}} & @@@ data, {area, coast}, {area,   coast}]
But this comes back with an error:
LinearModelFit::notdata: The first argument is not a vector, matrix, or a list containing a design matrix and response vector. >>
POSTED BY: Philip Maymin
Could you please post the example of code that you tried and couldn’t get to work? Also you probably use some data that you are fitting; - it’d be very useful to point us to them or give a code that generates a similar test data set. Without this info it is hard to proceed. 
POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract