R/generate_null_hypothesis.R

Defines functions `generate_null_hypothesis`

`generate_null_hypothesis` <-
function(obs_data, num_iterations){

# Given the bin_size=1 the number of bin is equal to the number of sample + 1 
num_of_bins <- nrow(obs_data)+1;

# Generate and return the null hypothesis
null_hypothesis <- 0*c(1:num_of_bins);
freq <- 0*c(1:ncol(obs_data));

for (p in 1:num_iterations){
	
	# Apply a Row random pwermutation
	obs_data <- t(apply(obs_data, 1, sample));
	# Compute the frequency obtained by the row random permutation
	freq <- apply(obs_data,2,sum);

	# Create the histogram of the array 'freq' 
	uniq_freq <- unique(freq);
	for(i in 1:length(uniq_freq)){
		null_hypothesis[uniq_freq[i]+1] <- null_hypothesis[uniq_freq[i]+1]+sum(freq==uniq_freq[i]);
	}
}

null_hypothesis <- null_hypothesis/sum(null_hypothesis);
return(null_hypothesis);

}

Try the gaia package in your browser

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

gaia documentation built on Nov. 8, 2020, 8:02 p.m.