1 C Output from Public domain Ratfor, version 1.0
2 subroutine sslvrg(penalt,dofoff,x,y,w,ssw, n, knot,nk,coef,
3 * sz,lev, crit,icrit, lambda, xwy, hs0,hs1,hs2,hs3,
4 * sg0,sg1,sg2,sg3, abd,p1ip,p2ip,ld4,ldnk,info)
7 C Compute smoothing spline for smoothing parameter lambda
8 C and compute one of three `criteria' (OCV , GCV , "df match").
9 C See comments in ./sbart.f from which this is called
11 integer n,nk,icrit,ld4,ldnk,info
12 DOUBLE precision penalt,dofoff,x(n),y(n),w(n),ssw,
13 & knot(nk+4), coef(nk),sz(n),lev(n), crit, lambda,
14 * xwy(nk), hs0(nk),hs1(nk),hs2(nk),hs3(nk),
15 * sg0(nk),sg1(nk),sg2(nk),sg3(nk), abd(ld4,nk),
16 & p1ip(ld4,nk),p2ip(ldnk,nk)
19 double precision bvalue
21 double precision vnikx(4,1),work(16)
22 integer i,ileft,j,mflag, lenkno, ilo
23 double precision b0,b1,b2,b3,eps, xv,rss,df, sumw
33 C compute the coefficients coef() of estimated smooth
37 abd(4,i) = hs0(i)+lambda*sg0(i)
41 abd(3,i+1) = hs1(i)+lambda*sg1(i)
45 6 abd(2,i+2) = hs2(i)+lambda*sg2(i)
48 8 abd(1,i+3) = hs3(i)+lambda*sg3(i)
50 c factorize banded matrix abd:
51 call dpbfa(abd,ld4,nk,3,info)
53 C matrix could not be factorized -> ier := info
56 c solve linear system (from factorize abd):
57 call dpbsl(abd,ld4,nk,3,coef)
59 C Value of smooth at the data points
62 12 sz(i) = bvalue(knot,coef,nk,4,xv,0)
64 C Compute the criterion function if requested
69 C --- Ordinary or Generalized CV or "df match" ---
72 call sinerp(abd,ld4,nk,p1ip,p2ip,ldnk,0)
75 call interv(knot(1), nk+1, xv, ileft, mflag)
76 if(mflag .eq. -1) then
79 else if(mflag .eq. 1) then
84 C call bspvd(knot,4,1,xv,ileft,4,vnikx,work)
85 call bsplvd(knot,lenkno,4,xv,ileft,work,vnikx,1)
91 & p1ip(4,j)*b0**2 + 2.d0*p1ip(3,j)*b0*b1 +
92 * 2.d0*p1ip(2,j)*b0*b2 + 2.d0*p1ip(1,j)*b0*b3 +
93 * p1ip(4,j+1)*b1**2 + 2.d0*p1ip(3,j+1)*b1*b2 +
94 * 2.d0*p1ip(2,j+1)*b1*b3 + p1ip(4,j+2)*b2**2 +
95 & 2.d0*p1ip(3,j+2)*b2*b3 + p1ip(4,j+3)*b3**2
106 c w(i) are sqrt( wt[i] ) weights scaled in ../R/smspline.R such
107 c that sumw = number of observations with w(i) > 0
109 rss = rss + ((y(i)-sz(i))*w(i))**2
111 sumw = sumw + w(i)**2
114 crit = (rss/sumw)/((1d0-(dofoff + penalt*df)/sumw)**2)
115 c call dblepr("spar", 4, spar, 1)
116 c call dblepr("crit", 4, crit, 1)
118 else if(icrit .eq. 2) then
122 30 crit = crit + (((y(i)-sz(i))*w(i))/(1-lev(i)))**2
124 c call dblepr("spar", 4, spar, 1)
125 c call dblepr("crit", 4, crit, 1)
130 32 crit = crit+lev(i)
131 crit = 3 + (dofoff-crit)**2
135 C Criterion evaluation