Borrar filtros
Borrar filtros

how to label the variance decomposition table

28 visualizaciones (últimos 30 días)
NAFISA SIDDIQUI
NAFISA SIDDIQUI el 3 de Jul. de 2024 a las 2:17
Comentada: Paul el 3 de Jul. de 2024 a las 21:43
Currently I have this code where I have 7 predictors Age, Weight, ...MaxPulse where Oxygen is the response variable
which gives the following output
However I want to modify the code such that in place of Var1, Var2, Var3, ....Var7 I have the predictors Intercept, Age, Weight, ....,MaxPulse.

Respuesta aceptada

Paul
Paul el 3 de Jul. de 2024 a las 3:33
Editada: Paul el 3 de Jul. de 2024 a las 3:35
Check the doc page collintest and review how to use the VarNames input. Or, instead of pulling all the variables out from data, and then stuffing those into an array, why not take advantage of the fact that collintest an accept a table as an input, and the DataVariables argument indicates which table variables are of interest.
collintest(data,DataVariables=["x0" "Age" etc])
Read the linked doc page for more information. Feel free to post a comment to this answer with the code if still having a problem.
  2 comentarios
NAFISA SIDDIQUI
NAFISA SIDDIQUI el 3 de Jul. de 2024 a las 17:48
Hello Paul, when I tried doing this
I get the output
Paul
Paul el 3 de Jul. de 2024 a las 21:43
The VarNames argument is used if the input data is an array. The DataVariables argument is used if the input data is a table.
For the former
collintest(Predictors,VarNames=["Intercept", "Age", etc ])
For the latter
collintest(data,DataVariables=["Intercept", "Age", etc])
Again, read the doc page collintest to better understand those two usages. It's possible that the output arguments might be different as well.

Iniciar sesión para comentar.

Más respuestas (1)

Umar
Umar el 3 de Jul. de 2024 a las 3:16

Hi Nafisa,

You asked, However I want to modify the code such that in place of Var1, Var2, Var3, ....Var7 I have the predictors Intercept, Age, Weight, ....,MaxPulse.

To answer your question, I need to update the variable names in the regression model. Below is a detailed example along with an explanation of how to accomplish this task:

Let us generate sample data with 100 samples and 7 predictors.

>> % Sample data for demonstration data = randn(100, 7); % Assuming 100 samples and 7 predictors response = randn(100, 1); % Response variable (Oxygen)

Then, create a table predictorTable with predictor variables named 'Intercept', 'Age', 'Weight', 'Var4', 'Var5', 'Var6', and 'MaxPulse'.

>> % Create a table with predictor variables predictorTable = array2table(data, 'VariableNames', {'Intercept', 'Age', 'Weight', 'Var4', 'Var5', 'Var6', 'MaxPulse'});

Then, fit a linear regression model lm using the fitlm function with the predictor table and the response variable.

>> % Fit a linear regression model lm = fitlm(predictorTable, response);

Finally, display the regression results using disp(lm).

>> % Display the regression results disp(lm);

Hope this will help resolve your problem.

  2 comentarios
Paul
Paul el 3 de Jul. de 2024 a las 3:34
How does fitlm relate at all to this question?
Umar
Umar el 3 de Jul. de 2024 a las 3:47
Hi Paul,
It effectively uses specific predictor names in linear regression model. Hence, the reason. But it sounds like you have provided your input as well which is well appreciated. Thanks for your contribution towards resolving this problem.

Iniciar sesión para comentar.

Categorías

Más información sobre Specification Testing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by