I'm trying to do multiple linear regression and having a hard time understanding the error messages I'm getting because web search doesn't find them or because the messages use terminology that isn't defined in the documentation.
Here's the synthetic data set I'm using at the moment:
data = {{5, 10, 20, 30}, {7, 13, 25, 36}, {9, 16, 30, 42}, {11, 19, 35, 48}, {13, 22, 40, 54}, {15, 25, 45, 60}, {17, 28, 50, 66}, {19, 31, 55, 72}, {21, 34, 60, 78}, {23, 37, 65, 84}, {25, 40, 70, 90}}
That's built by data = Transpose[{x1, x2, x3, x4}] where x1 = Table[2*x + 5, {x, 0, 10, 1}] and so forth.
When I try to fit it like this:
ftp = LinearModelFit[data, {c1, c2, c3}, p1]
I get this message which leaves it unclear what's wrong. Is the problem with the list of functions {c1, c2, c3} (in what sense are these functions? My functions are 2*x + 5, etc. Is the list too short or too long? What does the (3) and (1) refer to?) And what exactly are the "coordinates" and "variables" mentioned in the message? Documentation uses neither of these terms in this context.
LinearModelFit::fitc: Number of coordinates (3) is not equal to the number of variables (1).
Many aimless permutations ensued, including this random effort, which at least produced a new but equally murky message:
ftp = LinearModelFit[data, {c1, c2, c3}, {p1, p2, p3}]
LinearModelFit::desmat: Unable to construct a numeric design matrix. Nominal variables may need to be specified, or non-numeric entries for numeric variables may need to be replaced.
LinearModelFit[data, {c1, c2, c3}, {c1, c2, c3}]
$\endgroup$LinearModelFit
interprets each 4 item sub-list as three independent values with the fourth dependent on the first three. From your description it sounds like you really want four separate fits, but its not terribly clear. $\endgroup$LinearModeFit
does have a "different" syntax that takes a bit of getting used to. What you want (and is shown in the online help) is something like the following:LinearModelFit[data, {c1, c2, c3}, {c1, c2, c3}]
. A more "natural" syntax is found withNonlinearModelFit
where one has the input parameters as data, model, coefficients, and predictor variables (You can fit linear models withNonlinearModelFit
.) Not to be insulting but looking carefully at the documentation with the idea that there are plenty of subtleties helps considerably. $\endgroup$Correlation[data]
.) $\endgroup$