function [next, newprojx, newf_projx, newy] = FCUMPred(family, t_beta, beta, intercept, projx, f_projx, x, t_x, method, betacoef)

if nargin == 8
    method = 'gam';
    betacoef = [];
end

n = length(x);
K = size(beta, 2);
newprojx = zeros(K, n);
newf_projx = zeros(K, n);
minprojx = zeros(1, K);
maxprojx = zeros(1, K);
next = zeros(K, n);

for i = 1:K
    if iscell(t_x) == 1
        for j = 1:n
            tmp = interp1(t_beta, beta(:,i), t_x{j}, 'splines');
            newprojx(i,j) = trapz(t_x{j}, tmp.*x{j});
            clear tmp
        end
    else
        tmp = interp1(t_beta, beta(:,i), t_x, 'splines');
        for j = 1:n
            newprojx(i,j) = trapz(t_x, tmp.*x{j});
        end
        clear tmp
    end
    
    if strcmp(method, 'gam')
        [~, I] = unique(projx(i,:));
        newf_projx(i,:) = interp1(projx(i,I), f_projx(i,I), ...
            newprojx(i,:), 'splines');
        newy = evalLink(sum(newf_projx,1) + intercept, family, -1);
    elseif strcmp(method, 'lm')
        newbeta = [intercept; betacoef];
        newX = [ones(n, 1), newprojx'];
        newy = (newX*newbeta)';
    end
    
    minprojx(i) = min(projx(i,:));
    maxprojx(i) = max(projx(i,:));
    next(i,:) = newprojx(i,:) > minprojx(i) & newprojx(i,:) < maxprojx(i);
    
end



end