From jcs20@po.cwru.edu  Mon Nov 26 21:00:15 2001
From: jcs20@po.cwru.edu (jcs20@po.cwru.edu)
Date: Mon, 26 Nov 2001 22:00:15 +0100 (MET)
Subject: [Rd] predict.nnet (PR#1181)
Message-ID: <200111262100.WAA02054@pubhealth.ku.dk>

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] predict.nnet (PR#1181)
jcs20@po.cwru.edu