G
G
GreeNadine2014-01-29 19:42:49
R
GreeNadine, 2014-01-29 19:42:49

What is the error in the Genetic Algorithm code in R project?

Hello! Tell me, please, what is the error? Genetic Algorithm Code

panel <- read.dta("D://Diplom.dta")
> s=1
> p=74L #number of variables
> n=975L #number of observation = 13 years*75 region
> maxReg=10L
> X=panel#data
> y=panel[ ,10]#lnInnovOutput
> ###initial data 
> Gmax = 500
> C= 500
> m=1000  
> DATA<-list (X=X, y=y, n=n, p=p, maxk=10, lognn = log(n)/n)
> #BIC
> OF1<-function(x,data)
+ {
+ q<-qr(data$X[,x])
+ e<-qr.resid(q,data$y)
+ (log(crossprod(e))+2*p*data$lognn)
+ }
> ### AIC
> OF2<-function(x,data)
+ {
+ q<-qr(data$X[,x])
+ e<-qr.resid(q,data$y)
+ log(crossprod(e)/data$n)+2*sum(x)/data$n
+ }
> OF2(x0,DATA)
           [,1]
[1,] -0.1909722
> ### HQIC
> OF3<-function(x,data)
+ {
+ q<-qr(data$X[,x])
+ e<-qr.resid(q,data$y)
+ log(crossprod(e)/data$n)+2*sum(x)*log(log(n))/n
+ }
> ###initial solutions
> K<-logical(DATA$p)
> for (i in 1:m)
+ {
+ x0<-logical(DATA$p)
+ temp<-sample.int(DATA$maxk,1L)
+ temp<-sample.int(DATA$p,temp)
+ x0[temp]<-TRUE
+ K<-cbind(K,x0) ###create a matrix from vectors
+ }
> K<-K[,-1]   #K-matrix of initial solutions
> KOF<-numeric(m)#matrix of OF values of K
> for (i in 1:m) {KOF[i]<-OF(K[,i],DATA)}
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Obolonkin, 2014-01-30
@vladob

It hurts my eyes to look at the console output...
Is that all the code?
And what and how does the read.dta function read?
There are still a couple of user-defined functions peeping through, for which definitions are not visible in your console output.
Those. before the beginning of the text you cited, something was already happening there.
For example, some code has already been loaded or entered manually.
Put the R code to the maximum (or printout from the beginning of the session in R) and preferably a data file.
I'll try to help.

G
GreeNadine, 2014-01-30
@GreeNadine

@vladob Good afternoon! Read.dta reads Stata files, for it you need to load the foreign package. There, in the course of the algorithm, NMOF, plm, rbenchmark packages are needed. This is the very beginning of the algorithm. Before that, nothing happened. Unfortunately, I don't know how to post the data file here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question