Andrew Davies
Andrew Davies

Reputation: 1

Anesrake in R: error "no variables are off by 5pc"

I'm trying to apply the anesrake to a data dataset, but am getting the error message "No variables are off by more than 5 percent using the method you have chosen, either weighting is unnecessary or a smaller pre-raking limit should be chosen".

I have made sure I have no empty levels, my names match, made sure my variables are factors but nothing has worked and I'm not sure what else to try.

n.b. there is additional code at the beginning to mutate the weight variable from Pack and Age (these will be interlocking weights).

The targets are 5.5555556 just as an example.

#LoadDataSet
NPSSurvey_df <- read.csv('C:/Users/andavies/Desktop/Maru_NPS_CSAT_RAWDATA_13_12_2022_F1/Test.csv')
NPSSurvey_df <- as.data.frame(NPSSurvey_df)



new_data <- NPSSurvey_df %>%
  mutate(AgePack = case_when(Age == '18-24' & CustomerType =='In-Life' ~ '18-24 & In-Life',
                            Age == '25-34' & CustomerType =='In-Life' ~ '25-34 & In-Life',
                            Age == '35-44' & CustomerType =='In-Life' ~ '35-44 & In-Life',
                            Age == '45-54' & CustomerType =='In-Life' ~ '45-54 & In-Life',
                            Age == '55-64' & CustomerType =='In-Life' ~ '55-64 & In-Life',
                            Age == '65 years or more' & CustomerType =='In-Life' ~ '65+ & In-Life',
                           
                            Age == '18-24' & CustomerType =='Lapsed' ~ '18-24 & Lapsed',
                            Age == '25-34' & CustomerType =='Lapsed' ~ '25-34 & Lapsed',
                            Age == '35-44' & CustomerType =='Lapsed' ~ '35-44 & Lapsed',
                            Age == '45-54' & CustomerType =='Lapsed' ~ '45-54 & Lapsed',
                            Age == '55-64' & CustomerType =='Lapsed' ~ '55-64 & Lapsed',
                            Age == '65 years or more' & CustomerType =='Lapsed' ~ '65+ & Lapsed',
                            
                            Age == '18-24' & CustomerType =='New' ~ '18-24 & New',
                            Age == '25-34' & CustomerType =='New' ~ '25-34 & New',
                            Age == '35-44' & CustomerType =='New' ~ '35-44 & New',
                            Age == '45-54' & CustomerType =='New' ~ '45-54 & New',
                            Age == '55-64' & CustomerType =='New' ~ '55-64 & New',
                            Age == '65 years or more' & CustomerType =='New' ~ '65+ & New'))


new_data$AgePack <- as.factor(new_data$AgePack)
levels(new_data$AgePack) <- c('18-24 & In-Life','25-34 & In-Life', '35-44 & In-Life', '45-54 & In-Life', '55-64 & In-Life', '65+ & In-Life',
                              '18-24 & Lapsed','25-34 & Lapsed', '35-44 & Lapsed', '45-54 & Lapsed', '55-64 & Lapsed', '65+ & Lapsed',
                              '18-24 & New','25-34 & New', '35-44 & New', '45-54 & New', '55-64 & New', '65+ & New')
                          
AgePack <- c(5.555555555555556,5.555555555555556,5.555555555555556,5.555555555555556,5.555555555555556,5.555555555555556,
             5.555555555555556,5.555555555555556,5.555555555555556,5.555555555555556,5.555555555555556,5.555555555555556,
             5.555555555555556,5.555555555555556,5.555555555555556,5.555555555555556,5.555555555555556,5.555555555555556)

names(AgePack) <- c('18-24 & In-Life','25-34 & In-Life', '35-44 & In-Life', '45-54 & In-Life', '55-64 & In-Life', '65+ & In-Life',
                    '18-24 & Lapsed','25-34 & Lapsed', '35-44 & Lapsed', '45-54 & Lapsed', '55-64 & Lapsed', '65+ & Lapsed',
                    '18-24 & New','25-34 & New', '35-44 & New', '45-54 & New', '55-64 & New', '65+ & New')

target <- list(AgePack)

names(target) <- c("AgePack")

outsave <- anesrake(target, new_data, caseid = new_data$Response_ID,
                    verbose= TRUE, cap = 5, choosemethod = "total",
                    type = "pctlim", pctlim = .05 , nlim = 5,
                    iterate = TRUE , force1 = TRUE)

summary(outsave)

new_data$weightvec <- unlist(outsave[1])

Upvotes: 0

Views: 110

Answers (1)

madeleineg33
madeleineg33

Reputation: 1

I believe your survey data and reference data do not exhibit large differences- i.e. the age pack breakdown of your survey data is less than 5% off from the proportions you want. You might want to consider if weighting then is truly necessary, or if you are set on weighting, then try changing your limit. Right now, you have "pctlim = 0.05" which corresponds to a lower limit of 5% discrepancy. You could, for example, try 3% or even 1% depending on your needs.

Upvotes: 0

Related Questions