Regression model with two equation
显示 更早的评论
What is the best way to create a regression model that is based on two equations ?
For example:
y1=A1x1+B1
y2=A2x2+B2
Where y2 is dependent on y1.
All input values is array of data and not just one point.
I've tried using fminsearch, fitlm, lsqr. I'm just not sure how to couple the two equation while also doing a regression and finding the best combination on A1 and A2 terms.
2 个评论
Torsten
2023-1-12
Why is y2 dependent on y1 ? According to your model equations, this does not seem to be the case.
Tasha Williams
2023-1-12
回答(1 个)
the cyclist
2023-1-12
0 个投票
As @Torsten mentions in his comment, the way you have written your equations, it is not possible to see why they are coupled.
That being said, the MATLAB function you need maybe the mvregress function. See that documentation page for details, and also you could take a look at this answer of mine, which gives some example design matrices.
8 个评论
Tasha Williams
2023-1-12
the cyclist
2023-1-12
You are mistaken when you say that mvregress would only work if both equations could be solved independently. The entire point of the mvregress function is when the two equations share coefficients (i.e. are coupled). Both the documentation and my answer that I linked to show this. Did you try to read and understand those two resources?
The "best way to set that up" depends on your specific equations. You told us
y1=A1x1+B1
y2=A2x2+B2
and "y2 is dependent on y1". But -- saying this now for the third time in this thread -- you have not shown us how they are dependent, and the equations you wrote do not (explicitly) show any independence.
We need more information to help you more. We can't guess. For example, maybe B2 is a function of y1. Or maybe x2 is a function of y1. We simply cannot tell.
the cyclist
2023-1-12
编辑:the cyclist
2023-1-12
I saw your comment here before I saw your comment about B2 having dependence on y1.
Your comment there is really still not enough to understand the full form of the dependence. You need to be more explicit about that. I understand that you tried to simplify it, but I think you over-simplified to the point that we can't really answer.
Tasha Williams
2023-1-12
the cyclist
2023-1-12
This is getting more helpful. You are absolutely correct that mvregress is not going to solve this problem.
I would say that this is not technically even a regression problem, because you've got y1 on both sides of your equation (and I am assuming that the function f might be non-linear).
The coupling between the "y1 = ..." and the "y2 = ..." equations is still not explicit. (I see no mention of the [l,m,n] variables that you talk about in a prior comment.)
Frankly, to make progress (and have the greatest chance of more helpful eyeballs seeing this), I would start over with a new question where you:
- Give it a new title, something like "Trying to solve a system of non-linear equations"
- Don't try to simplify what you have, because I think the hard part is exactly the stuff you are leaving out
- Include the image of the equations you put here, but truly including all the individual variables (e.g. the [l,m,n] set you mention)
- Be very clear about which terms are data (with the size of the data), which terms are known parameters, and which terms are parameters you are trying to solve for.
I think if someone does stumble on this thread, it will be more difficult for them to sort through this whole discussion, than if they start from scratch as I describe here.
You should be able to tag me on that question, but I will also keep an eye out for it, in case I can be helpful.
Are there any constraints on the range of the y1 values ?
Am I correct that A1 and A2 are constant scalar values while y1 is a vector of the same length as x1 ? If yes, what is the size of x1 ?
Tasha Williams
2023-1-13
Torsten
2023-1-13
If the relation
y1 = rho_suc*D*E - A1*x1
has to be satisfied with equality for all elements of the x1 vector, then your problem should be formulated as
min: (y2 - B2(y1) - A2*x2).^2
under the constraint
y1 - (rho_suc(y1)*D*E - A1*x1) = 0
with y1, A1 and A2 as unknowns.
You can use fmincon to solve where the constraint can be implemented in function "nonlcon".
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
