# Solved – Displaying regression results in MATLAB

Along the same lines as this question, is there a nice way to display regression results in MATLAB from a single or many regressions in table or graph form?

Contents

In the (regrettably proprietary) system I have been working on, I set up linear regression as an object and overrode the `display` method. The output looks something like this:

``lmetc = lm of:         # obs: 100     # params: 5                     fac1      fac2      fac3      fac4      betahat:      0.996   0.00696    0.0136   0.00845    intercept:      -0.23                     fac1      fac2      fac3      fac4        tstat:     51.7!!   0.402     0.767     0.494   intcpt tstat:    -12.5!!       sighat:    0.1756 ci: (    0.154,     0.205)          R^2:     0.967 ci: (     0.96,     0.974)            F:       462 (df1 = 6, df2 = 94)       F pval:         0          AIC:     123.7          BIC:     136.7 ``

After the observations and parameters there is a row of the regression coefficients, which is easy to scan across. These are output with something like

``display(sprintf('%12s : %s','betahat',sprintf('% 9.3g ',regression_parameters))); ``

Similarly, below that is a row of the t-statistics associated with each regression coefficient, possibly suffixed by a two character string (' *' for p-value < 0.05, ' !' for p-value < 0.01, etc.) Again, unfortunately you are on your own for this because Matlab does not have, outside the statistics tool-box, a cdf function for the t-distribution (I wrapped R's math library in a mex function. You can check the stats toolbox in octave-forge, perhaps.).

Below that is the estimate of \$sigma^2\$, with a confidence interval (good luck getting Chi-square quantiles in vanilla Matlab), the \$R^2\$, and then the F statistic under the null hypothesis that all regression coefficients are zero, and finally the p-value for that (again, no F cdf in vanilla Matlab).

Unfortunately my answer seems to be: "the closed nature of Matlab makes this too difficult to do without money or effort or both, but here's a decent way to format the results once you've gotten past those hurdles." Sorry about that. good luck!

Rate this post

# Solved – Displaying regression results in MATLAB

Along the same lines as this question, is there a nice way to display regression results in MATLAB from a single or many regressions in table or graph form?

In the (regrettably proprietary) system I have been working on, I set up linear regression as an object and overrode the `display` method. The output looks something like this:

``lmetc = lm of:         # obs: 100     # params: 5                     fac1      fac2      fac3      fac4      betahat:      0.996   0.00696    0.0136   0.00845    intercept:      -0.23                     fac1      fac2      fac3      fac4        tstat:     51.7!!   0.402     0.767     0.494   intcpt tstat:    -12.5!!       sighat:    0.1756 ci: (    0.154,     0.205)          R^2:     0.967 ci: (     0.96,     0.974)            F:       462 (df1 = 6, df2 = 94)       F pval:         0          AIC:     123.7          BIC:     136.7 ``

After the observations and parameters there is a row of the regression coefficients, which is easy to scan across. These are output with something like

``display(sprintf('%12s : %s','betahat',sprintf('% 9.3g ',regression_parameters))); ``

Similarly, below that is a row of the t-statistics associated with each regression coefficient, possibly suffixed by a two character string (' *' for p-value < 0.05, ' !' for p-value < 0.01, etc.) Again, unfortunately you are on your own for this because Matlab does not have, outside the statistics tool-box, a cdf function for the t-distribution (I wrapped R's math library in a mex function. You can check the stats toolbox in octave-forge, perhaps.).

Below that is the estimate of \$sigma^2\$, with a confidence interval (good luck getting Chi-square quantiles in vanilla Matlab), the \$R^2\$, and then the F statistic under the null hypothesis that all regression coefficients are zero, and finally the p-value for that (again, no F cdf in vanilla Matlab).

Unfortunately my answer seems to be: "the closed nature of Matlab makes this too difficult to do without money or effort or both, but here's a decent way to format the results once you've gotten past those hurdles." Sorry about that. good luck!

Rate this post