'start'
'#Copyright (c) 2009, 2010 Sebastien Bihorel'
'#All rights reserved.'
'#'
'#This file is part of scaRabee.'
'#'
'#    scaRabee is free software: you can redistribute it and/or modify'
'#    it under the terms of the GNU General Public License as published by'
'#    the Free Software Foundation, either version 3 of the License, or'
'#    (at your option) any later version.'
'#'
'#    scaRabee is distributed in the hope that it will be useful,'
'#    but WITHOUT ANY WARRANTY; without even the implied warranty of'
'#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the'
'#    GNU General Public License for more details.'
'#'
'#    You should have received a copy of the GNU General Public License'
'#    along with scaRabee.  If not, see <http://www.gnu.org/licenses/>.'
'#'
'@newline@'
'weighting <- function(x=NULL,f=NULL,xdata=NULL){'
'@newline@'
'  ntime <- size(f,2)'
'@newline@'
'  # Extracts primary parameters'
'  parms <- get.param.data(x=x,which=\'value\',type=\'V\')'
'  names(parms) <- get.param.data(x=x,which=\'names\',type=\'V\')'
'@newline@'
'  tmp <- try({'
'    tmp <- with(as.list(parms),{'
'  #########################################################################'
'  #                        USER CODE STARTS HERE'
'  #########################################################################'
'  # Residual variability model templates'
'  #'
'  # additive error with variance 1'
'  # v <- c(ones(size(f)))'
'  #'
'  # additive error with fixed or estimated variance'
'  # v <- c((SD^2)*ones(1,ntime))'
'  #'
'  # proportional error'
'  # v <- c((CV^2)*(f[1,]^2))'
'  #'
'  # additive and proportional error'
'  # v <- c((SD^2)*ones(1,ntime) + (CV^2)*(f[1,]^2))'
'@newline@'
'  v <- c()'
'@newline@'
'  #########################################################################'
'  #                         USER CODE ENDS HERE'
'  #########################################################################'
'      return(v)}'
'    )'
'  },silent=T)'
'@newline@'
'  if (class(tmp)==\'try-error\'){'
'    stop(paste(\'weighting: The residuals cannot be computed. The index used for one or\n\','
'               \'more parameters might be out of bounds. Please, check your code.\'),'
'         call.=FALSE)'
'  } else {'
'    v <- tmp'
'  }'
'@newline@'
'  if (sum(size(v)==size(f))!=2)'
'    stop(paste(\'The dimensions of the variance matrix should not differ from\n\','
'               \'the dimensions of the predictions matrix. Please, check your code.\'),'
'         call.=FALSE)'
'@newline@'
'  return(v)'
'@newline@'
'}'