I'm running a script to estimate a Neural Network in R using the package neuralnet.
I'm using a Linux OS and the script is the following:
# useful libraries
library("XLConnect")
library("neuralnet")
# data loading;
DATA = loadWorkbook("/home/quant/Desktop/D.xlsx") # loading sheet;
DATASET = readWorksheet(NN_DATA, sheet = "D") # reading sheet;
NN_DATASET # display the directory;
head(NN_DATASET) # show data;
warnings() # error detection & data quality;
#test set detection;
testset <- NN_DATASET[1:101, ]
# building the neural networks;
NNET <- neuralnet(y ~ MKTVALUER + VOLR + DYR + PER + DJR + DAXR + MSCIR + NIKKEIR + CCOR + CPIR + CABCR + EGR + USFFR + USGDPR + GCIR + IGR + IPR + IRR + MCURNR + M2R + NOMANUFACTORINGR + PCER + POPR + PPIR + CBLEIR + DEBTR + UR + C_XAU + C_XAG + BARCLAYSAGG + C_USDJPY + C_EURUSD, NN_DATASET, hidden = 2, lifesign = "minimal", linear.output = FALSE, threshold = 0.1)
Everything goes right till the last line, in which R gives an error output, as follows:
Error in x - y : non-conformable arrays
The dataframe structure, got by using str(NN_DATASET)
is the following:
'data.frame': 201 obs. of 34 variables:
$ DATA : chr "Q4 1964" "Q1 1965" "Q2 1965" "Q3 1965" ...
$ SP500_R : num NA 0.0184 -0.0215 0.0622 0.025 ...
$ MKTVALUER : num NA 0.0257 -0.0206 0.0694 0.0215 ...
$ VOLR : num NA 0.007336 0.000982 0.007239 -0.003561 ...
$ DYR : num NA NA 0.0294 -0.0528 0.0366 ...
$ PER : num NA NA NA NA NA NA NA NA NA NA ...
$ DJR : num NA NA NA NA NA NA NA NA NA NA ...
$ DAXR : num NA NA NA NA NA NA NA NA NA NA ...
$ MSCIR : num NA NA NA NA NA NA NA NA NA NA ...
$ NIKKEIR : num NA NA NA NA NA NA NA NA NA NA ...
$ CCOR : num NA 0.0338 0.0322 0.0247 0.0192 ...
$ CPIR : num NA 0 0.4654 0 0.0565 ...
$ CABCR : num NA -0.2793 0.2268 -0.1893 -0.0123 ...
$ EGR : num NA -0.0895 0.1666 -0.0579 0.0681 ...
$ USFFR : num NA 0.1034 0.02733 -0.00245 0.02427 ...
$ USGDPR : num NA 0.0293 0.0182 0.024 0.0301 ...
$ GCIR : num NA 0.00572 0.01759 0.04266 0.0346 ...
$ IGR : num NA -0.02768 0.10641 0.00942 0.05768 ...
$ IPR : num NA 0.0371 0.0229 0.0207 0.02 ...
$ IRR : num NA 0.00218 0.06536 -0.06318 0.111 ...
$ MCURNR : num NA -0.00201 0.00977 0.01819 0.02592 ...
$ M2R : num NA 0.0166 0.0115 0.0156 0.0186 ...
$ NOMANUFACTORINGR: num NA NA NA NA NA NA NA NA NA NA ...
$ PCER : num NA 0.0252 0.0159 0.0208 0.0309 ...
$ POPR : num NA 0.00255 0.00294 0.00352 0.00296 ...
$ PPIR : num NA 0.00297 0.0118 0.00293 0.00873 ...
$ CBLEIR : num NA 0.0224 0.0172 0.0135 0.0272 ...
$ DEBTR : num NA -0.000955 -0.000637 -0.002553 0.013329 ...
$ UR : num NA -0.0202 -0.0417 -0.066 -0.0706 ...
$ C_XAU : num NA 0.00057 0 0 0 ...
$ C_XAG : num NA 0 0 0 0 0 0 0 0 0 ...
$ BARCLAYSAGG : num NA NA NA NA NA NA NA NA NA NA ...
$ C_USDJPY : num NA NA NA NA NA NA NA NA NA NA ...
$ C_EURUSD : num NA NA NA NA NA NA NA NA NA NA ...
Browsing on the internet I found a lot of answers here in stackoverflow.com, but, in each case, the solution is different, so, O posted a new question. Please, do not mark it as duplicate, because it is not.
The script is based on one found on R-Bloggers
Any help, hint or advice will be appreciated.
I don't see
y
column, that you're referring in your formula, in your data set. Your target variable should exist in your data set. Should it beSP500_R
?Second,
neuralnet
won't work withNAs
in data, filter your data set withna.omit()
first.Also, let me give a side note: if I got right what your data is, you'll got nothing from that kind of analysis.