Effacer les filtres
Effacer les filtres

multivariate regression with multi dimensional variables

8 vues (au cours des 30 derniers jours)
Mathematics_jane
Mathematics_jane le 29 Mai 2021
Réponse apportée : Nipun le 22 Mai 2024
Dear Reader,
I'm having trouble with implementing a regression.
I have the following:
I have a 3D matrix results_demands(24,1,n) and a 3D matrix results_han(24,3,n)
Where 24 are the time steps and n are the observations.
I want to model the regression between the (24,1) vector results_demands and (24,3) matrix results_han
What I already tried is splitting up the results_han such that I have a matrix with n rows(observations) and 3 columns and every input is a (24,1) vector.
So that we have 3 response variables and 1 explanatory variable(results_demands) all variables in form of a vector.
How do I need to implement such extra dimensional case.
A visualization of the 3D matrices.
results_han : (24,3,n):
[ [vec_i] [vec_i] [vec_i]
[vec_i] [vec_i] [vec_i]
......................
...................... ]
with vec_i a (24,1) column vector
results_demands: (24,1,n):
[ [vec_k]
[vec_k]
..........]
with vec_k a (24,1) column vector
Thank you in advance!
  10 commentaires
Torsten
Torsten le 30 Mai 2021
Modifié(e) : Torsten le 30 Mai 2021
So the here and now decisions come from an underlying optimization model depending on demand vectors from three factories over a time horizon of 24 hours.
Is the complete demand vector for 24 hours known when the model starts to calculate the here and now decisions ? Or does the model only calculate the optimal strategy for the next hour knowing the demand for the next hour ?
Are the decisions taken from the 3 factories independent from another or do they take into account their respective demands and the deduced here and now decisions of the other factories ?
What you are supposed to do is to find a simpler (and faster) model than the big optimization model based on regression. But this won't be an easy task. My guess is that a neural network solution is the way to go. It is a (usually very complex) regression model, but the developer does not need to specify the dependencies, but the program tries to find them on its own in a training phase based on the demand/here and now decision data. Simple linear regression methods to reproduce the complex decisions coming from a nonlinear optimizer won't be sufficient in my opinion.
Ive J
Ive J le 26 Juin 2021
Modifié(e) : Ive J le 26 Juin 2021
As you've already mentioned in your title, your problem is a multivariate regression (doc mvregress) since your response is affected by your independent variable, and you have a 3D dependent variable. Please note that this is equivalent (as mentioned) if you perform 3 separate univariate fits (fitlm for instance):
X = randn(1000, 1); % one predictor
Y = randn(1000, 3); % 3 response vars
% multivariate regression
newX = [ones(size(X)), X]; % add design matrix
coef.mv = mvregress(newX, Y);
% fit 3 separate lm
for i = 1:3
mdl = fitlm(X, Y(:, i));
coef.uv(:, i) = mdl.Coefficients.Estimate.';
end
norm(coef.uv - coef.mv) < eps % they're equivalent
ans = logical
1
However, the difference lies in covariance matrix of errors (noise) since mv regression accounts for the correlation between responses (for instance, if you're doing some hypothesis testing).

Connectez-vous pour commenter.

Réponses (1)

Nipun
Nipun le 22 Mai 2024
Hi Jane,
I understand that you are trying to perform a regression analysis where your explanatory variable is a (24,1) vector from results_demands for each observation, and you have three response variables, each a (24,1) vector from results_han, across the same observations. Given the structure of your data, you're aiming to model the relationship between these variables across time steps and observations.
To achieve this, you'll need to reshape your 3D matrices into 2D matrices where each row represents a time step for a given observation, and then perform regression analysis on these reshaped matrices. Here's how you can approach this problem in MATLAB:
  1. Reshape your 3D matrices: Convert results_demands into a 2D matrix of size (24*n, 1) and results_han into a 2D matrix of size (24*n, 3). This flattens your data across the time steps and observations, aligning them for regression analysis.
  2. Perform regression: Once you have your matrices reshaped, you can use MATLAB's regression functions, such as fitlm for linear regression, to model the relationship between results_demands and each column of results_han.
Here is how you can implement it:
% Assuming results_demands is of size (24, 1, n)
% and results_han is of size (24, 3, n)
n = size(results_demands, 3); % Number of observations
numTimeSteps = 24;
% Reshape the matrices
demands_reshaped = reshape(results_demands, [numTimeSteps*n, 1]);
han_reshaped = reshape(permute(results_han, [1 3 2]), [numTimeSteps*n, 3]);
% Now, demands_reshaped is (24*n, 1) and han_reshaped is (24*n, 3)
% Perform regression for each response variable in results_han
% Here's an example using the first column of han_reshaped as the response variable
lm = fitlm(demands_reshaped, han_reshaped(:, 1));
% Display the regression model summary
disp(lm);
% Repeat the regression for the other columns of han_reshaped as needed
This code snippet demonstrates how to reshape your 3D matrices into 2D matrices suitable for regression analysis and perform a linear regression between your explanatory variable (results_demands) and one of the response variables in results_han. You would repeat the regression process for each response variable in results_han as needed.
Remember, the reshaping aligns all time steps of each observation into a single row for the regression analysis, effectively treating each time step as a separate observation in the regression model. This approach assumes that the relationship you're modeling is consistent across all time steps.
Hope this helps.
Regards,
Nipun

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by