# Homework assignment 2, CROPS545 Statistical Genomics by Ryan Oliveira #Before anything we set the working directory (for my computer) setwd("~/R/RyanDirectory") #Part 1: Imputing missing values with stochastic imputation #First, we create a formula for stochastic imputation StochasticImpute = function(X){ n=nrow(X) m=ncol(X) fn=colSums(X, na.rm=T) #Sum of genotypes for all individuals fc=colSums(floor(X/3+1),na.rm=T) #count number of non missing individuals fa=fn/(2*fc) #Frequency of allele "2" for(i in 1:m){ index.a=runif(n)