###### generate the data set #####################################
set.seed(2013)
n.sub <- 100 # number of subjects
n.tim <- 80 # number of timepoints
# true population-level functions (mean, standard deviation and shape)
true.fun <- function(par){
if (par == "mean") f =function(x,y) sin(pi*x)* cos(pi*y)
if (par == "logvar"){
f=function(x,y) 2*dnorm(x, mean=0.5, sd = 0.2, log=TRUE) +
2*dnorm(y, mean=0.5, sd = 0.2, log =TRUE) - 8
}
if (par == "shape") f=function(x,y) 10*sin(2*pi*y)
return(f)
}
# covriate: Sort at the very beginning
point.cov <- sort(runif(n.sub));
# timepoints
point.tim <- seq(from=0, to=1, length=n.tim);
# calculate and collect all the true population-level parameters
col.true <- list(mean = outer(point.cov, point.tim, true.fun("mean")),
logvar = outer(point.cov, point.tim, true.fun("logvar")),
shape = outer(point.cov, point.tim, true.fun("shape")))
# generate data
my.data <- data.generator.y.F(n.subject = n.sub, n.timepoints = n.tim,
s = col.true$mean, D = col.true$logvar,
csi=col.true$shape,
lambdas = c(1/2, 1/4, 1/8),
basis.system = legendre.polynomials,
var.noise = 0.10)
# here shape is covariate independent
# so it's sufficient to keep 1st row of shape to use csi = col.true$shape[1,]
######################Visualize the data #####################################
par(mfrow = c(2,2))
# plot the data surface
persp(point.cov, point.tim, my.data$data, theta=60, phi=15,
ticktype = "detailed", col="lightblue",
xlab = "covariate", ylab = "time",
zlab="data", main="data surface")
# plot the mean surface
persp(point.cov, point.tim, col.true$mean, theta=45, phi=15,
ticktype = "detailed", col="lightblue",
xlab = "covariate", ylab = "time",
zlab="mean", main="mean surface")
# the logvar surface
persp(point.cov, point.tim, col.true$logvar, theta=45, phi=15,
ticktype = "detailed", col="lightblue",
xlab = "covariate", ylab = "time",
zlab="logvar", main="logvar surface")
# the shape surface
persp(point.cov, point.tim, col.true$shape, theta=45, phi=15,
ticktype = "detailed", col="lightblue",
xlab = "covariate", ylab = "time",
zlab="shape", main="shape surface")
Run the code above in your browser using DataLab