Re: regression function

"Michael Creel" <[email protected]> Fri, 7 Sep 2007 09:21:45 +0200
Newsgroups gmane.comp.gnu.octave.sources
Message-ID <[email protected]>
--===============0400525194==
Content-Type: multipart/alternative; 
	boundary="----=_Part_135_16542015.1189149706235"

------=_Part_135_16542015.1189149706235
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 9/7/07, Ghassen El Montasser <[email protected]> wrote:
>
> hi,
> I would like to contribute with the function"regression". This function
> like ols functions produces "beta","sigma" "residus" but besides my function
> produces the statistics of Student of estimated coefficients and the
> associated p values(bilateral or one sided tests). The statistics of Student
> and the p-values are very interesting for the significativity decision of
> the parameters.I believe with the function "regression" , we shall have
> richer output.
>


That sounds like a good idea to me. The following gives an idea of what I'd
like to see in such a function. Cheers, M

# Calculates ordinary LS estimator using the Huber-White heteroscedastic
# consistent variance estimator.

function [b, varb, e, ess] = mc_ols(y, x, names, silent, regularvc)
    k = columns(x);

    if nargin < 5 regularvc = 0; endif
    if nargin < 4 silent = 0; endif
    if (nargin < 3) || (rows(names) != k)
        names = 1:k;
        names = names';
    endif

    [b, sigsq, e] = ols(y,x);

    xx_inv = inv(x'*x);
    n = rows(x);

    ess = e' * e;

    # Ordinary or het. consistent variance estimate
    if regularvc
        varb = xx_inv*sigsq;
    else
        varb = HetConsistentVariance(x,e);
    endif

    seb = sqrt(diag(varb));
    t = b ./ seb;

    tss = y - mean(y);
    tss = tss' * tss;
    rsq = 1 - ess / tss;

    labels = str2mat("estimate","st.err.", "t-stat.", "p-value");
    if !silent

printf("\n*********************************************************\n");
        printf("OLS estimation results\n");
        printf("Observations %d\n",n);
        printf("R-squared %f\n",rsq);
        printf("Sigma-squared %f\n",sigsq);
        p = 2 - 2*t_cdf(abs(t), n - k);
        results = [b, seb, t, p];
        if regularvc
            printf("\nResults (Ordinary var-cov estimator)\n\n");
        else
            printf("\nResults (Het. consistent var-cov estimator)\n\n");
        endif
        prettyprint(results, names, labels);

printf("\n*********************************************************\n");
    endif
endfunction

------=_Part_135_16542015.1189149706235
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<br><br><div><span class="gmail_quote">On 9/7/07, <b class="gmail_sendername">Ghassen El Montasser</b> &lt;<a href="mailto:[email protected]">[email protected]</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>hi,</div>
<div>I would like to contribute with the function&quot;regression&quot;. This function like ols functions produces &quot;beta&quot;,&quot;sigma&quot; &quot;residus&quot; but besides my function produces the statistics of Student of estimated coefficients and the associated p values(bilateral or one sided tests). The statistics of Student and the p-values are very interesting for the significativity decision of the 
parameters.I believe with the function &quot;regression&quot; , we shall have richer output.</div>
</blockquote></div><br><br>That sounds like a good idea to me. The following gives an idea of what I&#39;d like to see in such a function. Cheers, M<br><br># Calculates ordinary LS estimator using the Huber-White heteroscedastic
<br># consistent variance estimator.<br><br>function [b, varb, e, ess] = mc_ols(y, x, names, silent, regularvc)<br>&nbsp;&nbsp;&nbsp; k = columns(x);<br><br>&nbsp;&nbsp;&nbsp; if nargin &lt; 5 regularvc = 0; endif<br>&nbsp;&nbsp;&nbsp; if nargin &lt; 4 silent = 0; endif
<br>&nbsp;&nbsp;&nbsp; if (nargin &lt; 3) || (rows(names) != k)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; names = 1:k;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; names = names&#39;;<br>&nbsp;&nbsp;&nbsp; endif<br><br>&nbsp;&nbsp;&nbsp; [b, sigsq, e] = ols(y,x);<br><br>&nbsp;&nbsp;&nbsp; xx_inv = inv(x&#39;*x);<br>&nbsp;&nbsp;&nbsp; n = rows(x);<br><br>&nbsp;&nbsp;&nbsp; ess = e&#39; * e;
<br><br>&nbsp;&nbsp;&nbsp; # Ordinary or het. consistent variance estimate<br>&nbsp;&nbsp;&nbsp; if regularvc<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; varb = xx_inv*sigsq;<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; varb = HetConsistentVariance(x,e);<br>&nbsp;&nbsp;&nbsp; endif<br><br>&nbsp;&nbsp;&nbsp; seb = sqrt(diag(varb));<br>
&nbsp;&nbsp;&nbsp; t = b ./ seb;<br><br>&nbsp;&nbsp;&nbsp; tss = y - mean(y);<br>&nbsp;&nbsp;&nbsp; tss = tss&#39; * tss;<br>&nbsp;&nbsp;&nbsp; rsq = 1 - ess / tss;<br><br>&nbsp;&nbsp;&nbsp; labels = str2mat(&quot;estimate&quot;,&quot;st.err.&quot;, &quot;t-stat.&quot;, &quot;p-value&quot;);<br>
&nbsp;&nbsp;&nbsp; if !silent<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;\n*********************************************************\n&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;OLS estimation results\n&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;Observations %d\n&quot;,n);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;R-squared %f\n&quot;,rsq);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;Sigma-squared %f\n&quot;,sigsq);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p = 2 - 2*t_cdf(abs(t), n - k);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; results = [b, seb, t, p];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if regularvc<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;\nResults (Ordinary var-cov estimator)\n\n&quot;);
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;\nResults (Het. consistent var-cov estimator)\n\n&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; endif<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prettyprint(results, names, labels);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;\n*********************************************************\n&quot;);
<br>&nbsp;&nbsp;&nbsp; endif<br>endfunction<br><br>

------=_Part_135_16542015.1189149706235--

--===============0400525194==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Octave-sources mailing list
[email protected]
https://www.cae.wisc.edu/mailman/listinfo/octave-sources

--===============0400525194==--