Message Boards Message Boards

2
|
5387 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Multivariate Linear Regression [Constraining to a specific constant]

Posted 10 years ago

I have data of the form {y, x1, x2, x3, x4} for about 20 entries. I want to end up with a regression model in the from y = ax1+bx2+cx3+dx4+6.9. Here's what I have done:

data := Imported data from Excel.
x1 = Transpose[data][[2]]
x2 = Transpose[data][[3]]
x3 = Transpose[data][[4]]
x4 = Transpose[data][[5]]
y = Transpose[data][[1]]
J = Transpose[{x1, x2, x3, x4, y}]
LinearModelFit[ J, {1, x1, x2, x3, x4}, {x1, x2, x3, x4}]

That works except I obviously don't get 6.9 for my constant and when I try to replace 1 with 6.9, I get an error. How should I go about constraining the constant so I get the result I want? I tried using FindFit but I'm having all sorts of syntax errors. Basically, I think FindFit will do what I want because I can constrain constants/coefficients, but I'm having trouble with the syntax. Any help would be lovely and I can provide more information or code if needed.

POSTED BY: Jeffrey Korum
2 Replies

I don't know why I didn't think of that; I guess I was just pretty sure there had to be some way to manually do it. This however is probably easier on the computer (I use larger data sets than just 20 most often). Thanks again!

POSTED BY: Jeffrey Korum
Posted 10 years ago

I think one way is to just subtract 6.9 from your y and fit your regression to new y's:

 ystar = y - 6.9

Put this ystar in your J data matrix, call new data matrix with ystar, Jstar

Then fit the regression to ystar without a constant using the option IncludeConstantBasis -> False

LinearModelFit[Jstar, {x1, x2, x3, x4}, {x1, x2, x3, x4}, IncludeConstantBasis -> False]

Your "constrained" model is then the coefficients from above regression with the intercept 6.9 as required.

POSTED BY: Peter Crosbie
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract