Multiple linear regression with constraint
显示 更早的评论
I need some help with a code. I need to run a multiple linear regression such that the sum of the coefficients = 1 and I would like to drop the intercept. I have 7 variables, so i need 7 seven coefficients.
Thanks !
采纳的回答
更多回答(3 个)
If you have 7 coefficients and there is a constrain that sum of coefficients are 1. Then, isn't technically you need to find only 6 coefficients while the 7th will be 1 - sum(all 6 coefficients)?
You can rearrange your linear regression model to incorporate this constrain.
5 个评论
Cam_cat
2014-1-25
That part you missed out in the question.
You can use fmincon which can handle such constrains. You'll need to write the objective function that you're minimizing like abs(Y-Y_model)
John D'Errico
2014-1-25
编辑:John D'Errico
2014-1-25
NO NO NO NO NO NO NO NO! You do NOT need fmincon!!!!!! LSQLIN will suffice and is the appropriate tool to solve a linear problem subject to such types of constraints.
Amit
2014-1-25
Wow .. so many NOs. I agree LSQLIN would be better and easier.
I suggested FMINCON, because thats something I use more often than any other optimization. I never use linear regression. However, one thing I'd say that FMINCON can solve it too. Longer process but it will solve it. But thank you, I learnt something new today. Thats what I love about MATLAB Answers.
John D'Errico
2014-1-25
Ok, I just saw No, No, Nanette. :)
The point is, fmincon is a nonlinear solver. It uses an essentially iterative scheme to search for the solution, part of which requires it to differentiate the function.
If you KNOW the problem is essentially a linear one, then use a tool designed to solve a linear problem, so lsqlin here. It has no need to do any differentiation, no need to perform searches of the type that fmincon uses.
andrea capone
2016-11-23
0 个投票
I havee the same truble:
the code that i have wrote contain in input Y vector 36*1, and X matrix 36*8. I want to use this script:
%multivariate regression Y =data_2(:,1); X =data_3(:,1:8); lb = zeros(1,8); ub = ones(1,8); Aeq = ones(1,8); beq = 1; coef = lsqlin(X,Y,[],[],Aeq,beq,lb,ub);
The variables are eight.
I have this error:Warning: The trust-region-reflective algorithm can handle bound constraints only; using active-set algorithm instead. > In lsqlin (line 300)
2 个评论
Torsten
2016-11-23
The message you receive is not an error, but an information for you that the solution method has automatically been switched to active-set algorithm.
Best wishes
Torsten.
andrea capone
2016-11-23
But I don't recive any solution!
ARUN BORGOHAIN
2017-6-26
0 个投票
Can someone help me with regARIMA; as I donot have it; but I've both regression(say polyfit: I may use) & ARIMA tools; how to get the same output as with regARIMA! The same example as given in the matlab website can be taken! Beta=2.5 & -0.6; yt=2.5x2-0.6x1+ut; & in ut I would like to apply arima modelling & also get the same output! (Presently I m doing these in excel with lots of lots of consecutive steps & in R just in 3 steps!) But how to do in matlab!
https://in.mathworks.com/help/econ/regarima-class.html
Mdl = regARIMA('Intercept',0,'Beta',[2.5; -0.6],... 'AR',{0.7, -0.3, 0.1},'MA',{0.5, 0.2},... 'Variance',1,'D',1)
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!