function bB = boot_cdfls(t,xw,yw,knt,ord,lmb,NB) %bB = boot_cdfls(t,xw,yw,knt,ord,lmb,NB) % Conditional bootstrap of CDFLS estimators (i.e. warping functions held fixed) % % INPUT % t (1 x m) Time grid (same input as for CDFLS) % xw (n x m) Warped X's (output of CDFLS) % yw (n x m) Warped Y's (output of CDFLS) % knt (1 x K) Spline knots for regression slope (same input as for CDFLS) % ord (scalar) Spline order (same input as for CDFLS) % lmb (scalar) Smoothing parameter (same input as for CDFLS) % NB (scalar) Number of bootstrap samples to compute % % OUTPUT % bB (p x NB) Bootstrapped regression basis coefficients % % External functions called: trbasis B = trbasis(t,ord,knt,ord,knt); p = size(B,3); [n,m] = size(xw); h = [t(2)-t(1),(t(3:m)-t(1:m-2))/2,t(m)-t(m-1)]; Omega = zeros(p,p); for j = 1:p for k = 1:p Omega(j,k) = h*(B(:,:,j).*B(:,:,k))*h'; end end BB = zeros(m,m*p); for k = 1:p BB(:,(k-1)*m+1:k*m) = B(:,:,k); end clear B bB = zeros(p,NB); for rep = 1:NB I = randi(n,[n,1]); xb = xw(I,:); yb = yw(I,:); A = zeros(p,p); c = zeros(p,1); mux = mean(xb); muy = mean(yb); for i = 1:n aux = ((xb(i,:)-mux).*h)*BB; gi = reshape(aux',[m p])'; A = A + gi*diag(h)*gi'; c = c + gi*diag(h)*(yb(i,:)-muy)'; end bB(:,rep) = (A+n*lmb*Omega)\c; end