Georg Ruß
2010-Dec-09 08:23 UTC
[R] nnet for regression, mixed factors/numeric in data.frame
Hi there, this is more a comment and a solution rather than a question, but I thought I'd post it since it cost some time to dig down to the issue and maybe someone else could run into this. I'm using the nnet function for a regression task. I'm inputting the following data frame:> 'data.frame': 4970 obs. of 11 variables:$ EC25 : num 67.5 67.6 68 69 69.5 ... $ YIELD07 : num 5.43 5.68 5.88 5.81 6.47 5.96 5.71 5.92 5.92 6.47 $ N3 : num 63 63 55 58 59 57 59 55 54 54 ... $ N2 : num 45 44 41 42 44 43 46 47 46 43 ... $ N1 : num 68 68 69 69 69 69 69 69 69 68 ... $ REIP32 : num 725 725 725 725 725 ... $ REIP49 : num 727 728 728 728 727 ... $ ELEVATION: Factor w/ 1127 levels "67.71","67.73",..: 17 19 23 19 19 16 26 18 33 9 ... using the formula interface:> formula <- YIELD07 ~ N1 + N2 + N3 + EC25 + REIP32 + REIP49 + ELEVATIONHowever, using the above data.frame, R spits out the following message:> Error in nnet.default(x, y, w, ...) : too many (56701) weightsAfter changing the ELEVATION variable to a numeric variable via the following line:> f611$ELEVATION <- as.numeric(levels(f611$ELEVATION)[f611$ELEVATION])the model runs fine. It's funny though that all the other models I've used for regression worked fine with ELEVATION being a factor variable. And it's not mentioned in ?nnet (there, it only says that if the response variable is a factor it's going to be a classification network). Regards, Georg. -- Research Assistant Otto-von-Guericke-Universit?t Magdeburg research at georgruss.de http://research.georgruss.de