[R] package MICE, squeeze function, calling several variables at once

From: Rita Carreira <ritacarreira_at_hotmail.com>
Date: Fri, 01 Apr 2011 22:49:00 +0000

Hello everyone!I have a data set with missing observations that I am trying to impute. I am using MICE and I would like the imputed values to all be positive. I have two types of variables: prices (P1 to P136) and quantities (Q1 to Q136) and I also want the range of these two types to be different. Besides these variables. I am using the squeeze function but I am unable to set it such that I don't have to write the names of all the variables. Also note that I do not have all the 136 Ps and Qs because since some were completely missing, I had to drop those variables. But my first Q is called Q1 and the last one Q136 and similarly for P. I apologize if I am making a silly little error since I am still learning R. This is the code that I have and the error that I am getting:

#####Program starts here#####Read data into Rdf <- read.table("F:\\testC2S4\\new_C2-S4_head_data.txt", header = TRUE);                        #, stringsAsFactors = TRUEdfPZ <- df[ ,1:3]dfDV <- df[ ,277:311]dfPtemp <- df[ ,seq(4, 275, by = 2)]dfP <- dfPtemp[, sapply(dfPtemp, function(x) !all(is.na(x)))]dfQtemp <- df[ ,seq(5, 275, by = 2)]dfQ <- dfQtemp[, sapply(dfQtemp, function(x) !all(is.na(x)))]remove(dfPtemp, dfQtemp)
NewPrimal <- data.frame(c(dfPZ, dfQ, dfP, dfDV), row.names = NULL, check.rows = F, check.names = F) remove(dfPZ, dfQ, dfP, dfDV)
library(mice)# setting up the default settings for the imputationini <- mice(NewPrimal,             seed = 52275,            imputationMethod = "norm",            maxit=0,            pred = quickpred(NewPrimal,                    mincor = 0.25,                   minpuc = 0.95,                    include = c("blnNewYearsDay", "blnValentinesDay", "blnStPatricksDay",                                "blnEaster", "blnMothersDay", "blnMemorialDay",                                "blnFathersDay", "blnIndependenceDay", "blnLaborDay",                                "blnThanksgiving", "blnChristmas", "Qtr1", "Qtr2", "Qtr3",                               "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",                                "Oct", "Nov", "Dec"),                   exclude = c("ActualWeekEndingDate", "CompanyID", "PriceZoneID", "Date", "Year")),                   print=FALSE)
meth <- ini$meth # naming the default method in inipred <- ini$pred   # naming the matrix of default predictors in inipost <- ini$post    # naming the default post processing method in inipost["Q1":"Q136"] <- "imp[[j]][,i] <- squeeze(imp[[j]][,i],c(0,351000))"  #setting the range for quantitypost["P1":"P136"] <- "imp[[j]][,i] <- squeeze(imp[[j]][,i],c(0,50))"          #setting the range for price
# calling mice to impute given default settings:impNP <- mice(NewPrimal, meth = meth, maxit=5, pred = pred, post = post)

######My error warning####Error in "Q1":"Q136" : NA/NaN argument In addition: Warning messages:
1: In post["Q1":"Q136"] <- "imp[[j]][,i] <- squeeze(imp[[j]][,i],c(0,351000))" :   NAs introduced by coercion
2: In post["Q1":"Q136"] <- "imp[[j]][,i] <- squeeze(imp[[j]][,i],c(0,351000))" :   NAs introduced by coercion
Any ideas?
Thank you and have a great weekend!

Rita ________________________________________ "If you think education is expensive, try ignorance"--Derek Bok


 		 	   		  
	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 01 Apr 2011 - 22:55:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 02 Apr 2011 - 00:20:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive