Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How can I impute the values of a variable in an XDF file?


View products that this article applies to.

One way to accomplish this is to use 'rxDataStep' and the 'impute' function from the R package 'Hmisc'.

 

Here is some sample R code to impute the average cost per claim:

car.insurance.df <- data.frame(AgeLevel=factor(c(rep("17-20",4), 
     rep("21-24",4),rep("25-29",4),rep("30-34",4), 
     rep("35-39",4),rep("40-49",4),rep("50-59",4), 
     rep("60+",4))), Car.group = factor(rep(c("A","B","C","D"),8)), 
     Veh.Age=factor(rep(c(rep("0-3",4),rep("4-7",4),rep("8-9",4), 
     rep("10+",4)),2)), 
     AvgCost.claim = c(289,372,189,763,282,249,288,850,133,288,179, 
             NA,160,11,NA,NA,302,420,268,407,194,243,343,320,135,196,293,205,166,135,104,NA), 
  claims.weights = c(8,10,9,3,8,28,13,2,4,1,1,0,1,1,0,0,18,59,44,24,31,96,39,18,10,13,7,2,4,3,2,0))

 

rxDataFrameToXdf(data = car.insurance.df, outFile = "car.insurance.xdf") 
 install.packages("Hmisc")
 library(Hmisc) 
 rxDataStep(inData = "car.insurance.xdf", outFile = "car.insurance-imputed.xdf", transforms = list(AvgCost.claim.New = impute(AvgCost.claim)), 
 transformPackages = "Hmisc") 
 rxSummary(~Car.group + AvgCost.claim, data = "car.insurance-imputed.xdf", fweights ="claims.weights")

↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 3104218
Revision : 1
Created on : 1/7/2017
Published on : 10/29/2015
Exists online : False
Views : 57