Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Library: gam
See also: intest intestpl gamfit knn

Quantlet: backfit
Description: the estimates for the components of an additive (partial linear) model are calculated. If the local linear smoother is applied, the first derivatives are calculated as well, additionally the second derivatives if the local quadratic smoother is chosen.

Usage: {m,b,const} = backfit(t,y,h,loc,kern{,opt})
Input:
t n x p matrix, the observed continuous explanatory variable
y n x 1 matrix, the observed response variable
h p x 1 vector or scalar, the bandwidth if loc>-1, else the second parameter of knn.
loc {-1,0,1,2}, if loc>-1, the degree of the chosen local polynomial smoother else the knn is chosen.
kern string, the kernel to be used. If loc=-1 it has no meaning.
opt.x n x d matrix, optional, the observed discrete explanatory variables (linear part)
opt.miter integer, maximal number of iterations. The default is 50.
opt.cnv integer, convergence criterion. The default is 1.0e-6.
opt.shf integer, (show-how-far) if exists and =1, an output is produced which indicates how the iteration is going on (additive function / point of estimation / number of iteration).
Output:
m n x pp matrix, where pp is p*(loc+1). The estimates of the additive components are given in column 1 to p, the first derivatives in column (p+1) to (2p) and the second derivatives in (2p+1) to (3p).
b d x 1 vector, parameter estimate of the linear part
const scalar, estimate of the constant

Example:
library("gam")
randomize(1)
n   = 100
t   = normal(n,2)             ; explanatory variable
x   = normal(n,2)             ; the linear part
f1  = - sin(2*t[,1])          ; estimated functions
f2  = t[,2]^2
eps = normal(n,1) * sqrt(0.75)
y   = x[,1] - x[,2]/4 + f1 + f2 +eps      ; response variable
h   = 0.5
opt = gamopt("x",x,"shf",1)   ; the linear part is used
;                               and the iterations will be shown
{m,b,const} = backfit(t,y,h,0,"qua",opt)
;
b                             ; coefficients for the linear part([1, -1/4] were used)
const                         ; estimation of the constant
;
pic = createdisplay(1,2)      ; preparing the graphical output
d1  = t[,1]~m[,1]
d2  = t[,2]~m[,2]
setmaskp(d1,4,4,4)
setmaskp(d2,4,4,4)
m1  = mean(f1)
m2  = mean(f2)
yy  = y - x*b - const
x1  = t[,1]~(yy - m[,2])
x2  = t[,2]~(yy - m[,1])
setmaskp(x1,1,11,4)
setmaskp(x2,1,11,4)
setmaskl(d1,(sort(d1~(1:rows(d1)))[,3])',4,1,1)
setmaskl(d2,(sort(d2~(1:rows(d2)))[,3])',4,1,1)
show(pic,1,1,d1,x1,t[,1]~(f1-m1))
show(pic,1,2,d2,x2,t[,2]~(f2-m2))

Result:
estimates of the additive functions using backfitting,
see 'Generalized Additive Models by Hastie and Tibshirani'
(1990)



Author: S. Sperlich, 19980217
(C) MD*TECH Method and Data Technologies, 05.02.2006