I can't reproduce this example: I get
> smalltest <- nnet.formula(formula = Q65 ~ ., data = smallx,
+ size = 2, rang = 1, maxit = 250, subset = jj)
Error in get(ctr)(levels(x), contrasts = contrasts) :
Contrasts not defined for 0 degrees of freedom
And that's correct: what you are doing is nonsense. You've included
one-level factors, and you are fitting a non-linear model to a linearly
over-determined system (there are more X columns than data points).
I don't know how you got this to work, but I would not be surprised
if predict.nnet failed on an over-determined fit: It's not designed for
misuse.
I don't agree this is a bug in my code.
On Mon, 26 Nov 2001 jcs20@po.cwru.edu wrote:
> Full_Name: Jeff Schwarz
> Version: R1.3.1
> OS: Windows 2000
> Submission from: (NULL) (129.22.170.115)
>
>
> Error message (using predict and predict.nnet)
> > predict (smalltest, smallx[-jj,])
> Error in matrix(NA, length(keep), nout, dimnames = list(rn,
> dimnames(object$fitted)[[2]])) :
> length of dimnames[1] not equal to array extent
>
> *** all relevant code and data source is given below ***
>
> I have successfully built an object of type nnet using...
> nnet.formula(formula = Q65 ~ ., data = smallx, size = 2, rang = 1,
> maxit = 250, subset = jj)
>
> where smallx is a data.frame with dimensions 300 by 103 that contains
numerical
> and factor variables. Smallx is a random sample of 300 from the
tab-delimited
> numeric dataset found at
>
http://www.gvu.gatech.edu/user_surveys/survey-1998-10/datasets/num_general.zip.
> The code I used to recode the data is below, also.
>
> I have successfully run the sample code from the predict.nnet help file
without
> any problem.
>
> *********************************************************************
>
> data source:
>
http://www.gvu.gatech.edu/user_surveys/survey-1998-10/datasets/num_general.zip
>
> #***Get the data from the big file
> #***Get rid of the vairiables for survey (all
> #*** observations = general), a unique identifier
> #*** for each respondent and an extra variable X
> #*** (all = NaN)
> #***Make sure that all the asymmetric binary,
> #*** and nominal variables are coded as factor,
> #*** not numeric (daisy has special methods for
> #*** symmetric binary and discrete ordinal)
> #***Recode some of the discrete ordinal variables
> #*** so the Na, didn't know, and didn't say are all
> #*** "NaN", and so that a few of the "never" responses
> #*** are coded as 0 instead of 5
>
> bigx <-
> read.delim (file location,
> header = TRUE, sep = "\t", quote = "\"", dec =
".",
> fill = TRUE)
>
> bigx <- bigx [,c(1:103)]
>
> ii <- bigx[,c(22)] == 5
> bigx[,c(22)] <- replace (bigx[,c(22)], ii, 0)
> ii <- bigx[,c(23)] == 5
> bigx[,c(23)] <- replace (bigx[,c(23)], ii, 0)
> ii <- bigx[,c(24)] == 5
> bigx[,c(24)] <- replace (bigx[,c(24)], ii, 0)
> ii <- bigx[,c(25)] == 5
> bigx[,c(25)] <- replace (bigx[,c(25)], ii, 0)
> ii <- bigx[,c(26)] == 5
> bigx[,c(26)] <- replace (bigx[,c(26)], ii, 0)
> ii <- bigx[,38] == 7
> bigx[,38] <- replace (bigx[,38], ii, NaN)
> ii <- bigx[,38] == 8
> bigx[,38] <- replace (bigx[,38], ii, NaN)
> ii <- bigx[,57] == 1
> bigx[,57] <- replace (bigx[,57], ii, NaN)
> ii <- bigx[,58] == 19
> bigx[,58] <- replace (bigx[,58], ii, NaN)
> ii <- bigx[,60] == 4
> bigx[,60] <- replace (bigx[,60], ii, NaN)
> ii <- bigx[,60] == 1
> bigx[,60] <- replace (bigx[,60], ii, 3)
> ii <- bigx[,60] == 2
> bigx[,60] <- replace (bigx[,60], ii, 1)
> ii <- bigx[,60] == 3
> bigx[,60] <- replace (bigx[,60], ii, 2)
> ii <- bigx[,69] == 1
> bigx[,69] <- replace (bigx[,69], ii, NaN)
> ii <- bigx[,69] == 7
> bigx[,69] <- replace (bigx[,69], ii, NaN)
> bigx[,69] <- bigx[,69] - 1
>
> for (ii in c(1:9,14:21,27:32,34:37,39:49,52:55,
> 59,61:70,72:103)) bigx[,ii] <- as.factor(bigx[,ii])
>
> library (nnet)
>
> set.seed(7261)
> smallx <- bigx[sample(1:5022,300),]
> jj <- sample (1:300, 100)
> smalltest <- nnet.formula(formula = Q65 ~ ., data = smallx,
> size = 2, rang = 1, maxit = 250, subset = jj)
>
> predict.nnet (smalltest, smallx[-jj,])
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-devel mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To:
r-devel-request@stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._