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 intest2d

Macro: interact
Description: interact estimates a model with interaction terms. It is using the marginal integration estimator with a local polynomial smoother. For details see Sperlich, Tjostheim, Yang (1997)

Usage: mod = interact(t,y,h,g,loc,incl{,tg})
Input:
t n x p matrix , the observed explanatory variable
y n x 1 vector , the observed response variables
h p x 1 or 1 x 1 matrix , chosen bandwidth for the directions of interest in the estimation step
g p x 1 or 1 x 1 matrix , chosen bandwidth for the directions not of interest in the estimation step
loc scalar in {0,1,2}, the degree of the local polynomial smoother
incl pp x 2 matrix, in the rows have to be all pairs of indices for interactions which shall be included in the model.
tg ng x p matrix , if grid is wished, tg is the grid on which we will estimate. Attention ! If you estimate on a grid, the estimates of the interaction functions are estimated up to a constant shift. Further, if you try to extrapolate, the estimate will be zero minus a centering constant.
Output:
mod.fh n x (p+pp) matrix, estimates for the functions
mod.c scalar, the overall constant

Example:
library("gam")
randomize(12345)
t     = grid(#(-0.9,-0.9),#(0.2,0.2),#(10,10))
n     = rows(t)
t     = t~(uniform(n)*2-1)
g1    = 2*t[,1]
g2    = t[,2]^2 - mean(t[,2]^2)
g3    = sin(3*t[,3])
g12   = t[,1].*t[,2]
y     = g1+g2+g3+g12+normal(n)*sqrt(0.5)
h     = #(0.9, 0.9, 0.9)          
g     = #(1.0, 1.0, 1.0)     
incl  = 1~2 
f     = interact(t,y,h,g,1,incl)
library("graphic")
pic   = createdisplay(2,2)
dat11 = sort(t[,2]~g2~f.fh[,2])
dat12 = sort(t[,3]~g3~f.fh[,3])
show(pic,1,1,dat11[,1:2],dat11[,1]~dat11[,3])
show(pic,1,2,dat12[,1:2],dat12[,1]~dat12[,3])
dat21 = grsurface(t[,1:2]~g12)
dat22 = grsurface(t[,1:2]~f.fh[,4])
gc = grcube( dat21|dat22 )
show(pic,2,1,dat21,gc.box,gc.x,gc.y,gc.z,gc.c)
show(pic,2,2,dat22,gc.box,gc.x,gc.y,gc.z,gc.c)
Result:
function estimates

Library: gam
See also: intest intest2d

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

Author: Sperlich 970721
(C) MD*TECH Method and Data Technologies, 28.6.1999