Multiple linear regression with constraint
Mostrar comentarios más antiguos
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 !
Respuesta aceptada
Más respuestas (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 comentarios
Cam_cat
el 25 de En. de 2014
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
el 25 de En. de 2014
Editada: John D'Errico
el 25 de En. de 2014
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
el 25 de En. de 2014
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
el 25 de En. de 2014
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
el 23 de Nov. de 2016
0 votos
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 comentarios
Torsten
el 23 de Nov. de 2016
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
el 23 de Nov. de 2016
But I don't recive any solution!
ARUN BORGOHAIN
el 26 de Jun. de 2017
0 votos
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)
Categorías
Más información sobre Linear Least Squares en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!