## The following code will result in exactly the same output
## as the one obtained from the original data set
data(bushmiss)
bf <- bushmiss[bushmiss$MPROB==0,1:5]
plot(bf)
covMcd(bf)
if (FALSE) {
## This is the code with which the missing data were created:
##
## Creates a data set with missing values (for testing purposes)
## from a complete data set 'x'. The probability of
## each item being missing is 'pr' (Bernoulli trials).
##
getmiss <- function(x, pr=0.1)
{
n <- nrow(x)
p <- ncol(x)
done <- FALSE
iter <- 0
while(iter <= 50){
bt <- rbinom(n*p, 1, pr)
btmat <- matrix(bt, nrow=n)
btmiss <- ifelse(btmat==1, NA, 0)
y <- x+btmiss
if(length(which(rowSums(nanmap(y)) == p)) == 0)
return (y)
iter <- iter + 1
}
y
}
}
Run the code above in your browser using DataLab