library(norm) x <- read.table("cancer.dat", header = TRUE) y <- as.matrix(x) #convert table to matrix summary(lm(formula = totbpt~Sexp +deptp+anxtp+depts+anxts, x)) #Use original data ############### # Data Augmentation using norm.R s <- prelim.norm(y) #get preliminary statistics for the analysis thetahat <-em.norm(s) #Get MLE for start value rngseed(1234567) theta <- da.norm(s, thetahat, steps=20, showits=TRUE) # GET MLE getparam.norm(s, theta) #Print out those resulst impdata <-imp.norm(s, theta, y) #Impute the data write(t(impdata), file = "impcancer", ncolumns = 9, sep = " ") z <- data.frame(impdata) summary(lm(formula = totbpt~Sexp +deptp+anxtp+depts+anxts,z)) #Use imputed data. ################ ## Imputing data using EM with single imputation # Use results from first few steps above. thetahat <- em.norm(s) #Get MLE getparam.norm(s, thetahat, corr = TRUE) #look at est. correls impdata <-imp.norm(s, theta, y) #Impute the data write(t(impdata), file = "impcancer", ncolumns = 9, sep = " ") z <- data.frame(impdata) summary(lm(formula = totbpt~Sexp +deptp+anxtp+depts+anxts,z)) #Use imputed data. ################ ## Imputing data using MULTIPLE Data Augmentation #Same as first steps above thetahat <- mda.norm(s, theta, steps = 5, showits = TRUE) #Get MLE getparam.norm(s, thetahat, corr = TRUE) #look at est. correls impdata <-imp.norm(s, theta, y) #Impute the data write(t(impdata), file = "impcancer", ncolumns = 9, sep = " ") z <- data.frame(impdata) summary(lm(formula = totbpt~Sexp +deptp+anxtp+depts+anxts,z)) #Use imputed data.