R/centerVAR1data.r

Defines functions centerVAR1data

Documented in centerVAR1data

centerVAR1data <- function(Y){
	########################################################################
	#
	# DESCRIPTION:
	# within-individual, covariate-wise centering of the data.
	#
	# ARGUMENTS:
	# -> Y             : Three-dimensional array containing the data. The 
	#                    first, second and third dimensions correspond to 
	#                    covariates, time and samples, respectively. The 
	#                    data are assumed to centered covariate-wise.
	#
	# DEPENDENCIES:
	# ...
	#
	# NOTES:
	# ...
	#
	########################################################################

	# input checks
	if (!is(Y, "array")){ 
		stop("Input (Y) is of wrong class.") 
	}
	if (length(dim(Y)) != 3){ 
		stop("Input (Y) is of wrong dimensions: either covariate, time or sample dimension is missing.") 
	}

	# centering
	for (i in 1:dim(Y)[3]){
		Y[1:dim(Y)[1], 1:dim(Y)[2],i] <- 
			sweep(Y[,,i,drop=TRUE], 1,
			      apply(Y[,,i,drop=TRUE], 1, mean, na.rm=TRUE))
	}
	return(Y)
}

Try the ragt2ridges package in your browser

Any scripts or data that you put into this service are public.

ragt2ridges documentation built on Jan. 28, 2020, 5:08 p.m.