function [int,point,b,det,corr] = linforc(t,y,timef,sig)

// Linear estimate of future process

// t ... individual times as independent variable x - column vector
// y ... values in column
// timef ... forecasting times in column
// sig ... significance level of interval estimates (default 0.05)

// corr ... value of correlation coefficient
// det ... coefficient of determination
// b ... estimates of regression parameters [b0 b1]
// point ... point estimates of future process in timef
// int ... interval estimates [lower upper]

// Literature: Dowdy, S., Wearden, S. and Chilko, D. (2004). Statistics
// for research, Wiley: New Jersey

// Copyright (C): Lukáš Malec and Hana Tvrdíková; University
// of Business in Prague, Czech Republic
// Date: $2015-12-17$

[lhs,rhs]=argn(0)

if t==[] then corr=%nan, return, end

n = length(t)

stdt = sqrt(n*sum(t.^2)-sum(t)^2)
stdy = sqrt(n*sum(y.^2)-sum(y)^2)
corr = (n*sum(t.*y)-sum(t)*sum(y)) /(stdt*stdy), det = corr^2

tx = n*sum(t.^2)-sum(t)^2
b1 = (n*sum(t.*y)-sum(t)*sum(y))/tx
b0 = mean(y)-b1*mean(t)

b = [b0 b1]

point = b0+b1*timef

s = sqrt((sum(y.^2)-sum((b0+b1*t).^2))/(n-2))

gf = ((timef-repmat(mean(t),length(timef),1)).^2)...
/(sum(t.^2)-n*mean(t)^2)
gforc = sqrt(1+1/n+gf)


if rhs==3
    sig = 0.05

end

int(:,1) = point-cdft("T",n-2,1-sig/2,sig/2)*s*gforc
int(:,2) = point+cdft("T",n-2,1-sig/2,sig/2)*s*gforc

endfunction
