[R] Variable 'A' is not a factor Error message

ahmed meftah akewander at yahoo.ie
Fri Nov 11 18:51:32 CET 2016


I am running a DOE with the following code   library(Rcmdr)
    library(RcmdrMisc)
    library(RcmdrPlugin.DoE)
# Define plackett burman experiment
    PB.DOE <- pb(nruns= 12 ,n12.taguchi= FALSE ,nfactors= 12 -1, ncenter= 0 ,
                 replications= 1 ,repeat.only= FALSE ,randomize= TRUE ,seed= 27241 , 
                 factor.names=list( A=c(100,1000),B=c(100,200),C=c(1,3),D=c(1,1.7),
                                    E=c(1000,1500),G=c(-2,2) ) )

    as.numeric2 <- function(x) as.numeric(as.character(x))

# Calculate response column
    IP <- with(PB.DOE,(as.numeric2(A)*as.numeric2(B)*(5000-3000))/(141.2*as.numeric2(C)*as.numeric2(D)*(log(as.numeric2(E)/0.25)-(1/2)+as.numeric2(G))))
# Combine response column with exp design table
    final_set <- within(PB.DOE, {
      IP<- ((as.numeric2(A)*as.numeric2(B)*(5000-3000))/(141.2*as.numeric2(C)*as.numeric2(D)*(log(as.numeric2(E)/0.25)-(1/2)+as.numeric2(G))))
    })I then ran a regression as follows:LinearModel.1 <- lm(IP ~ A + B + C + D + E + G, 
                    data=final_set)
summary(LinearModel.1)Following this i wanted to run a predict using specified values as predictors in a Monte Carlo:n = 10000
# Define probability distributions of predictors
A = rnorm(n,450,100)
hist(A,col = "blue",breaks = 50)

B = rnorm(n, 150,10)
hist(B,col = "blue",breaks = 50)

C = rnorm(n, 1.5, 0.5)
hist(C,col = "blue",breaks = 50)

D = runif(n,1.2,1.7)
hist(D,col = "blue",breaks = 50)

E = rnorm(n,1250,50)
hist(E,col = "blue",breaks = 50)

G = rnorm(n,0,0.5)
hist(G,col = "blue",breaks = 50)

MCtable <- data.frame(A=A,B=B,C=C,D=D,E=E,G=G)

for (n in 1:n) {
  N=predict(LinearModel.1,MCtable)
}

hist(N,col = "yellow",breaks = 10)I end up getting this error:"Warning in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
  variable 'A' is not a factor"Using str() to get some info on the LinearModel.1 and from what I understand seems to indicates that since the predictors A,B,C etc are factors with 2 levels I have to convert my data.frame table to factors aswell. Is that correct?Doing this would mean I would also need to specify the number of levels which would mean that since I have set my n to 10000 would mean 10000 levels for each factor. How would I go about doing this? Is there a better solution? Any help would be appreciated.
	[[alternative HTML version deleted]]



More information about the R-help mailing list