R/Brandi/R-code-for-functional-tree/Regression/gen_data_REG.R

Defines functions gen_data_reg

gen_data_reg  <- function(y_mean, y_sd, size, P, n.var, alpha, beta,
                      a, b){
  
  
  if(dim(alpha)[2]!=n.var | dim(beta)[2]!=n.var) stop("Dimensions Error")
  if(dim(alpha)[1]!=length(size) | dim(beta)[1]!=length(size)) stop("Dimensions Error")
  if(dim(a)[2]!=n.var | dim(b)[2]!=n.var) stop("Dimensions Error")
  if(dim(a)[1]!=length(size) | dim(b)[1]!=length(size)) stop("Dimensions Error")
  
  nclass <- length(class)
  y1 <- rnorm(size[1], y_mean[1], y_sd[1])
  y2 <- rnorm(size[2], y_mean[2], y_sd[2])
  y3 <- rnorm(size[3], y_mean[3], y_sd[3])
  
  y=c(y1,y2,y3)
  data <- list("Y"=y)
  for( i in 1:n.var){
    
    
    grid <- seq(0, 1, length.out = P)
    Cov <- exp_cov_function(grid, alpha = alpha[1,i], beta = beta[1,i])
    Data <- generate_gauss_fdata(size[1], 
                                 centerline = cos(a[1,i]+b[1,i]*pi*grid), Cov = Cov)
    fD1 <- fData( grid, Data )
    
    Cov <- exp_cov_function(grid, alpha=alpha[2,i], beta=beta[2,i])
    Data <- generate_gauss_fdata(size[2], 
                                 centerline = sin(a[2,i]+b[2,i]*pi*grid), Cov = Cov)
    fD2 <- fData( grid, Data )
    
    Cov <- exp_cov_function(grid, alpha=alpha[3,i], beta=beta[3,i])
    Data <- generate_gauss_fdata(size[3], 
                                 centerline = cos(a[3,i]+b[3,i]*pi*grid)*sin(a[3,i]+b[3,i]*pi*grid), Cov = Cov)
    fD3 <- fData( grid, Data )
    
    k1 <- fD1$values
    k2 <- fD2$values
    k3 <- fD3$values
    k <- rbind(k1,k2,k3)
    
    data[[paste("V",i,sep="")]] <- fdata(k)
    
  }
  
  return(data)
  
  
}
tulliapadellini/energytree documentation built on May 14, 2020, 8:06 p.m.