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 个评论

Why is y2 dependent on y1 ? According to your model equations, this does not seem to be the case.
B2 include an equation with 3 variable (l,m,n) where l and m are known while n is a thermodynamic property based on the output of y1. I have simplified the equations in order to answer the question in a more straight forward way.

请先登录,再进行评论。

回答(1 个)

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 个评论

mvregress would only work if both equations could be solved independently however they are coupled.
If mvregress works for system of equation, I'm asking what the best way to set that up would be.
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.
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.
First, I'd like to say thank you for your response. I have read through your explanation and I think it's very clear and the closest thing to it would be choice #1 however, I'm not sure if this would work if they are dependent of eachother, please correct me if I'm wrong. Below I will write out the what I'm trying to do more clearly and hopefully it helps.
Values shown in pink are not known.
I have data for all other variable in a table.
I would like to solve for best combination of A_1 and A_2 that minimizes the error from the actual y_2 data
If I set up matrix, y1 is unknown and and I have to intiate problem with a guess value. If I do this and and use mvregress, I find there's no way to iterate and make sure A1 and A2 is a a proper regression or am I looking at this wrong in terms of providing an inital guess?
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 ?
No constraints on y1.
Yes, that is correct, y1 should be a vector of the same length as x1 once calculated. x1 can be different for different data sets but lets say it's a column vector with 10 values.
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".

请先登录,再进行评论。

类别

产品

版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by