In many applications two or more dependent variables are observed at several values of independent variables such as at multiple time points. Often observations from different variables are contemporaneously correlated. Observations from the same variable may also be correlated. The statistical problems are (i) to estimate functions that model their dependences on the independent variables and (ii) to investigate relationships between these functions. Wang et al. (2000) proved that the joint estimates have smaller posterior variances than those of function-by-function estimates and are therefore more efficient. In this section we show how to use ssr and nnr to fit functions jointly.
Consider the following model
Denote , , , , , , and . Assume that , where depends on some parameters .
We estimate all functions 's jointly as the minimizer of the
following penalized weighted least squares
We now show how to trick ssr to fit model ().
For the simplicity of notations, we consider the case of .
Situations with can be fitted similarly. Note that the domains
of may be different for different . For most
applications they are the same, which is assumed in
the remaining of this section. Denote the common domain as .
Rewrite as , which is now considered as
a function of both and variables on the tensor product domain
. Then we can represent the original
functions as
We may reparametrize as
For (), let and
.
Let in () be the model space of . Then
For (), denote
and
.
Let in () be the model space of . Then
Often we are interested in possible relationships, if any,
between and . For example, one may want to check
if they are equal or parallel. Let be a probability measure
on . Consider the following SS ANOVA decomposition
For illustration, we generate a data set from the following model
Suppose we want to use cubic splines to model and in (), and in (), and and in (). Then , , , , and and are the RK of a cubic spline. In the following we first fit and using marginal data as bisp.fit1 and bisp.fit2 respectively. Then we fit jointly using the formulation () as bisp.fit3 the formulation () as bisp.fit4, and the formulation (), or equivalently the formulation (), as bisp.fit5.
> options(contrasts=rep("contr.treatment", 2)) > n <- 100 > s1 <- .5 > s2 <- 1 > r <- .5 > A <- diag(c(s1,s2))%*%matrix(c(sqrt(1-r**2),0,r,1),2,2) > e <- NULL > for (i in 1:n) e <- c(e,A%*%rnorm(2)) > t <- 1:n/n > y1 <- sin(2*pi*t) + e[seq(1,2*n,by=2)] > y2 <- sin(2*pi*t) + 2*t + e[seq(2,2*n,by=2)] > bisp.dat <- data.frame(y=c(y1,y2),t=rep(t,2),id=rep(c(0,1),rep(n,2)), pair=rep(1:n,2)) # fit separately > bisp.fit1 <- ssr(y~I(t-.5),rk=cubic(t),spar="m", data=bisp.dat[bisp.dat$id==0,]) > p.bisp.fit1 <- predict(bisp.fit1) > bisp.fit2 <- ssr(y~I(t-.5),rk=cubic(t),spar="m", data=bisp.dat[bisp.dat$id==1,]) > p.bisp.fit2 <- predict(bisp.fit2) # fit jointly > bisp.fit3 <- ssr(y~id*I(t-.5), rk=list(rk.prod(cubic(t),kron(id==0)), rk.prod(cubic(t),kron(id==1))), spar="m", weights=varIdent(form=~1|id), cor=corSymm(form=~1|pair), data=bisp.dat) > bisp.fit3 ... GML estimate(s) of smoothing parameter(s) : 0.2793703 0.3788567 Equivalent Degrees of Freedom (DF): 11.84544 Estimate of sigma: 0.4616973 Correlation structure of class corSymm representing Correlation: 1 2 0.523 Variance function structure of class varIdent representing 0 1 1 2.270982 > p.bisp.fit3.1 <- predict(bisp.fit3,newdata=bisp.dat[bisp.dat$id==0,], terms=c(1,0,1,0,1,0)) > p.bisp.fit3.2 <- predict(bisp.fit3,newdata=bisp.dat[bisp.dat$id==1,], terms=c(1,1,1,1,0,1)) > p.bisp.fit3.1$pstd <- p.bisp.fit3.1$pstd*sqrt((2*n-bisp.fit3$df) /(2*n-bisp.fit3$df-1)) > p.bisp.fit3.2$pstd <- p.bisp.fit3.2$pstd*sqrt((2*n-bisp.fit3$df) /(2*n-bisp.fit3$df-1)) > bisp.fit4 <- ssr(y~id*I(t-.5), rk=list(cubic(t), rk.prod(cubic(t),kron(id==1))), spar="m", weights=varIdent(form=~1|id), cor=corSymm(form=~1|pair), data=bisp.dat) > p.bisp.fit4.1 <- predict(bisp.fit4,newdata=bisp.dat[bisp.dat$id==0,], terms=c(1,0,1,0,1,0)) > p.bisp.fit4.2 <- predict(bisp.fit4,newdata=bisp.dat[bisp.dat$id==1,], terms=c(1,1,1,1,1,1)) > p.bisp.fit4.3 <- predict(bisp.fit4,newdata=bisp.dat[bisp.dat$id==1,], terms=c(0,1,0,1,0,1)) > p.bisp.fit4.4 <- predict(bisp.fit4,newdata=bisp.dat[bisp.dat$id==1,], terms=c(0,0,0,1,0,1)) > p.bisp.fit4.1$pstd <- p.bisp.fit4.1$pstd*sqrt((2*n-bisp.fit4$df) /(2*n-bisp.fit4$df-1)) > p.bisp.fit4.2$pstd <- p.bisp.fit4.2$pstd*sqrt((2*n-bisp.fit4$df) /(2*n-bisp.fit4$df-1)) > p.bisp.fit4.3$pstd <- p.bisp.fit4.3$pstd*sqrt((2*n-bisp.fit4$df) /(2*n-bisp.fit4$df-1)) > p.bisp.fit4.4$pstd <- p.bisp.fit4.4$pstd*sqrt((2*n-bisp.fit4$df) /(2*n-bisp.fit4$df-1)) > bisp.fit5 <- ssr(y~id*I(t-.5), rk=list(cubic(t),rk.prod(cubic(t),kron((id==0)-(id==1)))), spar="m", weights=varIdent(form=~1|id), cor=corSymm(form=~1|pair), data=bisp.dat) > p.bisp.fit5.1 <- predict(bisp.fit5,newdata=bisp.dat[bisp.dat$id==0,], terms=c(1,0,1,0,1,1)) > p.bisp.fit5.2 <- predict(bisp.fit5,newdata=bisp.dat[bisp.dat$id==1,], terms=c(1,1,1,1,1,1)) > p.bisp.fit5.3 <- predict(bisp.fit5,newdata=bisp.dat[bisp.dat$id==1,], terms=c(0,1,0,1,0,1)) > p.bisp.fit5.4 <- predict(bisp.fit5,newdata=bisp.dat[bisp.dat$id==1,], terms=c(0,0,0,1,0,1)) > p.bisp.fit5.1$pstd <- p.bisp.fit5.1$pstd*sqrt((2*n-bisp.fit5$df) /(2*n-bisp.fit5$df-1)) > p.bisp.fit5.2$pstd <- p.bisp.fit5.2$pstd*sqrt((2*n-bisp.fit5$df) /(2*n-bisp.fit5$df-1)) > p.bisp.fit5.3$pstd <- p.bisp.fit5.3$pstd*sqrt((2*n-bisp.fit5$df) /(2*n-bisp.fit5$df-1)) > p.bisp.fit5.4$pstd <- p.bisp.fit5.4$pstd*sqrt((2*n-bisp.fit5$df) /(2*n-bisp.fit5$df-1))
For each fit, we calculate the estimated functions and posterior variances. For fits bisp.fit4 and bisp.fit5, we also calculate the estimates and posterior variances of and in (). They are used to check if and if they are parallel respectively. Note that we inflate the posterior variances by one more degree of freedom used for estimating the correlation parameter. These estimates are shown in Figures , and . Even though not obvious in Figure , the Bayesian confidence intervals of the joint estimates are uniformly narrower than those of the function-by-function estimates. Obviously from Figures and that these two functions are not equal, nor parallel.