as.coded.data function won't take variables in place of numerics in R

90 views Asked by At

I am attempting to use a batch file to run the funcion SPLOT to bring in variables to my response surface code. I have confirmed the variables are passing properly and are numeric, however, when it gets to the as.coded.data function, I get the error message that it can not locate the variable. Is this a limitation of this function? It worked when I manually entered the values in place of the these variables.

'''

  SPLOT <-function(workdir, savedir, TREAT1_LABEL, TREAT2_LABEL, TREAT3_LABEL,RESP1_LABEL, RESP2_LABEL, 
               T1LOW, T1HIGH, T1MID, T2LOW, T2HIGH, T2MID,
               T3LOW, T3HIGH,T3MID){
  file_list <- list.files(path=workdir, pattern="*.csv") 

  for (x in 1:NROW(file_list)) {
              PROJ_DATA<-read.csv(file=file_list[x])
              i <- 1  
              while (i <= NROW(file_list)) {  
                name<-regmatches(file_list[x], regexpr("*.*", file_list[x]))     # extract the text from the file-name inorder to name the plot
                mytitle = paste(name,".pdf")
                mytitle1 = paste(name, ".tiff")
            
              PROJ_DATA.adj <- PROJ_DATA
              results <- "savedir"  
              setwd(workdir)

  #### Summarize Data ####
  
  PROJ_DATA1 <- PROJ_DATA.adj %>% group_by(FACTOR) %>%
    summarise(N = length(FACTOR),
              mean.TREAT1 = mean(TREAT1, na.rm=TRUE),
              mean.TREAT2 = mean(TREAT2, na.rm=TRUE), 
              mean.TREAT3 = mean(TREAT3, na.rm=TRUE), 
              mean.RESP1 = mean(RESP1, na.rm=TRUE),
              mean.RESP2 = mean(RESP2, na.rm=TRUE))%>% drop_na()
  PROJ_DATA2 <- na.omit(PROJ_DATA1)
  

  #### Relativize the Dataset - coding ####
  
  PROJ_DATA.coded <- as.coded.data(PROJ_DATA, TREAT1.coded ~ (mean.TREAT - T1MID)/(0.5*(T1HIGH-T1LOW)), 
                                TREAT2.coded ~ (mean.TREAT2 - T2MID)/(0.5*(T2HIGH-T2LOW)),
                                TREAT3.coded ~ (mean.TREAT3 - T3MID)/(0.5*(T2HIGH-T2LOW)))
  PROJ_DATA2.rsm <- rsm(RESP1 ~  FACTOR + SO(TREAT1.coded, TREAT2.coded, TREAT3.coded), data = PROJ_DATA.coded)
  PROJ_DATA2.rsm$studres <- rstudent(PROJ_DATA2.rsm)
  summary(PROJ_DATA2.rsm)
0

There are 0 answers