Rev 25034 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
c-----------------------------------------------------------------------cc R : A Computer Language for Statistical Data Analysisc Copyright (C) 1996, 1997 Robert Gentleman and Ross Ihakac Copyright (C) 2003 The R Foundationcc This program is free software; you can redistribute it and/or modifyc it under the terms of the GNU General Public License as published byc the Free Software Foundation; either version 2 of the License, orc (at your option) any later version.cc This program is distributed in the hope that it will be useful,c but WITHOUT ANY WARRANTY; without even the implied warranty ofc MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See thec GNU General Public License for more details.cc You should have received a copy of the GNU General Public Licensec along with this program; if not, write to the Free Softwarec Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAcc-----------------------------------------------------------------------cc lminfl computes basic quantities useful for computingc regression diagnostics.cc on entrycc x double precision(ldx,k)c the qr decomposition as computed by dqrdc or dqrdc2.cc ldx integerc the leading dimension of the array x.cc n integerc the number of rows of the matrix x.cc k integerc the number of columns in the matrix k.cc docoef integer (logical) indicating if coef(*,*) should be computedc Computation of coef(.) is O(n^2 * k) which may be too much.cc qraux double precision(k)c auxiliary information about the qr decomposition.cc resid double precision(k)c the residuals from the regression.cc on returncc hat double precision(n)c the diagonal of the hat matrix.cc coef double precision(n,p)c a matrix which has as i-th row the estimatedc regression coefficients when the i-th case is omittedc from the regression.cc sigma double precision(n)c the i-th element of sigma contains an estimatec of the residual standard deviation for the model withc the i-th case omitted.cc This version dated Aug 24, 1996.c Ross Ihaka, University of Auckland.c `docoef' option added Feb 17, 2003; Martin Maechler ETH Zurich.subroutine lminfl(x, ldx, n, k, docoef, qraux, resid,+ hat, coef, sigma, tol)integer ldx, n, k, docoefdouble precision x(ldx,k), qraux(k), resid(n),+ hat(n), coef(n,k), sigma(n)c coef(.,.) can be dummy(1) when docoef is 0(false)integer i, j, infodouble precision sum, denom, dummycc hat matrix diagonalcdo 10 i = 1,nhat(i) = 0.0d010 continuedo 40 j = 1,kdo 20 i = 1,nsigma(i) = 0.0d020 continuesigma(j) = 1.0d0call dqrsl(x, ldx, n, k, qraux, sigma, sigma, dummy,. dummy, dummy, dummy, 10000, info)do 30 i = 1, nhat(i) = hat(i)+sigma(i)*sigma(i)if(hat(i) .ge. 1.0d0 - tol) hat(i) = 1.0d030 continue40 continuecc changes in the estimated coefficientscif(docoef .ne. 0) thendo 70 i = 1,ndo 50 j = 1,nsigma(j) = 0.0d050 continuesigma(i) = resid(i)/(1.0d0 - hat(i))call dqrsl(x, ldx, n, k, qraux, sigma, dummy, sigma,. dummy, dummy, dummy, 1000, info)call dtrsl(x, ldx, k, sigma, 1, info)do 60 j = 1,kcoef(i,j) = sigma(j)60 continue70 continueendifcc estimated residual standard deviationcdenom = (n - k - 1)sum = 0.0d0do 80 i = 1,nsum = sum + resid(i)*resid(i)80 continuedo 90 i = 1,nsigma(i) = sqrt((sum - resid(i)*resid(i)/(1.0d0-hat(i)))/denom)90 continuereturnend