regression function

View: New views
2 Messages — Rating Filter:   Alert me  

regression function

by Ghassen El Montasser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

function [beta,sigma,residus,t_student,p_values]=regression(y,x,type)

##########written by Ghassen El Montasser
##########07/9/2007
##########mail:g.elmontasser@...

#######input description
#y the vector of dependent variable
#x the matrix of independent variables
#type takes the value of 1 or 2. If 1 we have a one sided  test of student on parameters significativity#, if 2 we have bilateral test of individual significativity.
 

#######output description
#beta like that of ols function in octave(octave manual,Edition 3 for Octave version 2.9.13,p266).
#sigma like that of ols function in octave
#residus like those of ols function in octave
#t_student the vector of calculated student statistics for each estimated coefficient
#p_values the vector of p values associated with calculates student statistics

beta=inv(x'*x)*x'*y;
sigma=(y-x*beta)'*(y-x*beta)/(rows(y)-columns(x));
residus=y-x*beta;
v=diag(sigma*inv(x'*x));
t_student=zeros(columns(x),1);
for i=1:columns(x)
t_student(i)=beta(i)/sqrt(v(i));
endfor
switch type
case { 1 }
p_values=zeros(columns(x),1);
for i=1:columns(x)
p_values(i)=1-tcdf(t_student(i),(rows(y)-columns(x)));
endfor
 case { 2 }
p_values=zeros(columns(x),1);
for i=1:columns(x)
p_values(i)=2*(1-tcdf(t_student(i),(rows(y)-columns(x))))
endfor
endswitch


_______________________________________________
Octave-sources mailing list
Octave-sources@...
https://www.cae.wisc.edu/mailman/listinfo/octave-sources

Re: regression function

by Michael Creel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On 9/7/07, Ghassen El Montasser <g.elmontasser@...> 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


_______________________________________________
Octave-sources mailing list
Octave-sources@...
https://www.cae.wisc.edu/mailman/listinfo/octave-sources
LightInTheBox - Buy quality products at wholesale price