Linear Regression: order of estimated coefficients does not match input order
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Isabel Chen
el 22 de Feb. de 2015
Editada: John D'Errico
el 22 de Feb. de 2015
For example,
mdl = fitlm(data,'EXPOS ~ X1 + X2 + HEIGHT + AGE')
The output
mdl.Coefficients
produces the estimated coefficients in the following order: HEIGHT, AGE, X1 and X2. Why does it do that? It really messes up some calculations! Please help!
0 comentarios
Respuesta aceptada
John D'Errico
el 22 de Feb. de 2015
If you have created the dataset with those variables in the order (height, age, x1, x2) then that is the order they will appear in the final model, even though you specified the model as
'EXPOS ~ X1 + X2 + HEIGHT + AGE'
2 comentarios
John D'Errico
el 22 de Feb. de 2015
Editada: John D'Errico
el 22 de Feb. de 2015
You can extract the variable names from the data set, then use regexp (or some other tool, like strtok, or even my own function allwords on the File Exchange) to take apart the model string you will be using. Then sort the two sets of variable names to be consistent.
For example:
allwords('EXPOS ~ X1 + X2 + HEIGHT + AGE',' +~')
ans =
'EXPOS' 'X1' 'X2' 'HEIGHT' 'AGE'
Más respuestas (0)
Ver también
Categorías
Más información sobre Analysis of Variance and Covariance en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!