2
|
5122 Views
|
2 Replies
|
4 Total Likes
View groups...
Share

# 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][] x2 = Transpose[data][] x3 = Transpose[data][] x4 = Transpose[data][] y = Transpose[data][] 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.
2 Replies
Sort By:
Posted 10 years ago
 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 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, JstarThen 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.