0

Following is the code that I am using to recode the data:

results$Taxis<-as.factor(results$Taxis)
results$ShiftType<-as.factor(results$ShiftType)
results$Sharing<-as.factor(results$Sharing)
results$Mode<-as.factor(results$Mode)
plot(results) 
anova<-aov(Service.Level~Taxis+ShiftType+Sharing+Mode,data = results)
summary(anova)
results.coded<-coded.data(results,x1~(Taxis-4500)/3000,x3~(Sharing-50)/50,x4~(Mode-0.5)/0.5)
results.coded

It gives me serial numbers as codes (1,2,3,4,5..) These codes do not change if I change the formula. They remain as they are. Looks like some default coding. Please help me with this!

1 Answers1

1

Data coding is used with continuous predictors, not factors. If interpretation requires those predictors to be factors, don’t try to code them. If they are on a numerical scale and you want to interpret them as such, then you may code them. Take away those as.factor() calls and it will work.

The advantage of coding is to scale all the variables so are treated more equitably in such methods as steepest ascent. If you’re just trying to fit an equation to the data and don’t plan to do additional experimentation to find an optimum, it really isn’t necessary to code the data.

Russ Lenth
  • 5,922
  • 2
  • 13
  • 21
  • Looking at your variable names but not knowing the context, I’d guess that `Mode` and `ShiftType` have nominal levels so should remain as factors (and not coded). The other two seem more suitable for coding. – Russ Lenth Mar 09 '18 at 19:19
  • I commented out the as.factor codes and not i am not getting the error anymore. Thanks a lot for your help. – Rahul Baranwal Mar 09 '18 at 19:38
  • However, I am doing RSM analysis which require value of variables to be factors, also since the value of these factors are going to change multiple times as per results, I want them to be coded. This will keep them at the same numeric scale to ease the interpretation. Am I missing something here? – Rahul Baranwal Mar 09 '18 at 19:44
  • Nope that’s fine. Interpret the factors as factors, and think of it as a separate response surface for each factor combination. – Russ Lenth Mar 09 '18 at 20:10
  • PS Note: Don’t include the factors in `SO()` calls and the like. Put them in as separate terms. – Russ Lenth Mar 09 '18 at 20:12
  • Ok, so while coding these variables, I should treat them as numeric (to facilitate coding) but interpret them as factors right? – Rahul Baranwal Mar 09 '18 at 20:29
  • No. I think you need to look up the meaning of the word “factor” and think about each one of your variables separately. Perhaps you need consulting help; that’s beyond what I can do here. – Russ Lenth Mar 09 '18 at 21:49