Skip to content

Instantly share code, notes, and snippets.

@Jfortin1
Last active August 29, 2015 14:10
Show Gist options
  • Save Jfortin1/f3e5c3a0e029fcb4b539 to your computer and use it in GitHub Desktop.
Save Jfortin1/f3e5c3a0e029fcb4b539 to your computer and use it in GitHub Desktop.
Beta to M
BetaToM <- function(beta){
matrix <- log2(beta) - log2(1-beta)
impute.matrix(matrix)
}
MToBeta <- function(mmatrix){
matrix <- 2^mmatrix/(2^mmatrix+1)
impute.matrix(matrix)
}
impute.matrix <- function (matrix) {
missing <- which(is.na(matrix) | !is.finite(matrix), arr.ind=TRUE)
if (nrow(missing)!=0){
for (j in 1:nrow(missing)){
mean <- mean(matrix[missing[j,1],][is.finite(matrix[missing[j,1],])], na.rm=TRUE)
matrix[missing[j,1],missing[j,2]] <- mean
}
}
matrix
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment