LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 10 Aug 2001 14:26:16 -0500
Reply-To:     seymour.d.douglas@ACCENTURE.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Seymour Douglas <seymour.d.douglas@ACCENTURE.COM>
Subject:      Logit model in IML
Content-type: text/plain; charset=iso-8859-1

1. DoubleMatrix2D x; 2. x = new DenseDoubleMatrix2D(T,K); 3. System.out.println(x); 4. DoubleMatrix2D y; 5. y = new DenseDoubleMatrix2D(T,1); 6. System.out.println(x); 7. 'x= transpose(DenseDoubleMatrix2D x) 8. x'x=mult( DenseDoubleMatrix2D x, DenseDoubleMatrix2D 'x) 9. invxx=inverse(DenseDoubleMatrix2D x'x) 10. 'y=transpose(DenseDoubleMatrix2D y) 11. x'y =mult( DenseDoubleMatrix2D x, DenseDoubleMatrix2D 'y) 12. bhat= mult(DenseDoubleMatrix2D invxx, DenseDoubleMatrix2D x'y) 13. Set initial log-likelihood l0 14. Count rows to get sample size t=nrow(x) 15. Count columns in x to get number of regressors k=ncol(x) 16. Count the number of ones in y, ysum-sum(y) 17. Define x*x= matrix multiplication of x, if x*x is a square matrix, inv(x*x) is the generalized inverse. 18. Define element by element matrix multiplication # 19. Generate the starting values for the regression b-hat=inv(x*x)*x'y 20. Declare a storage matrix (for results) 21. BEGIN ITERATION LOOP do it=1 to 25 while crit >1.0e-8) 22. Define z =x*b-hat 23. Define logistic probability distribution function pdf=exp(-z)/(1+exp (-z) 24. Define cumulative logistic distribution function cdf=1/(1+exp(-z) 25. Define the elements of the gradient vector grad=(y#(1-cdf)-(1-y)#cdf) #x 26. Define gradient vector grad =grad[+,]' 27. Let d =pdf 28. Define the information matrix inf=(x#d)'x 29. Define the inverse of the information matrix invinf=inv(inf) 30. Define current log-likehood loglhood= sum(y#log(cdf)+(1-y) #log*(1-cdf)) 31. Define the step towards maximum delta =invinf*grad 32. Let // Define vertical concatenation // 33. Let Max define the maximum element of a collection of elements 34. Define the convergence criteria a. The change in the log-likelihood Crit1=abs(loglhood-l0) b. The gradient length, Crit2 = ssq(grad) c. Step length, Crit 3 =ssq(delta) d. Concatentate criteria

35. Define All criteria -Critall=Crit1//Crit2//Crit3 36. Select maximum of all criteria crit=max(critall) 37. Update log-likelihood function b-hat=b-hat+delta 38. Print up results 39. end 40. Define logit covariance matrix cov= invinf 41. Let vecdiag be an operation that extracts the diagonal elements of a matrix. 42. Calculate the standard errors stderr=sqrt(vecdiag(cov)) 43. Calculate t-stat , t-stat= bhat/stderr Pri Accenture is the new name for Andersen Consulting as of January 1, 2001. Our web address is

Back to: Top of message | Previous page | Main SAS-L page