FredHasselman / casnet

An R toolbox for studying Complex Adaptive Systems and NETworks
https://fredhasselman.github.io/casnet/
GNU General Public License v3.0
27 stars 7 forks source link

est_parameters() fails for some series but not others: "object 'fnnSeries' not found" #3

Closed heinonmatti closed 4 years ago

heinonmatti commented 5 years ago

Had this earlier with real data, but now also with the logistic map:

r <- 2.5
x <- 0.2
N <- 500
M <- 100

LogisticMap <- function(r, x, N, M){
  # r: bifurcation parameter
  # x: initial value
  # N: Number of iteration
  # M: Number of iteration points to be returned
  z <- 1:N
  z[1] <- x
  for(i in c(1:(N-1))){
    z[i+1] <- r *z[i]  * (1 - z[i])
    }
  # Return the last M iterations 
  z[c((N-M):N)]
  }

series <- LogisticMap(r = 3.9, x = 0.5, N = 400, M = 400) * 100

So far, so good. For 103 (or more) values it works:

series <- series[1:103]

params <- casnet::crqa_parameters(series)

For 102 (or less) it doesn't any more:

series <- series[1:102]

params <- casnet::crqa_parameters(series)

Error in data.frame(Nn.pct = as.numeric(fnnSeries[1, ]), Nsize = nnSizes[N], : object 'fnnSeries' not found

In real data, I have some variables of length 67 for which it works, and others for which it doesn't.

This works: casnet::crqa_parameters(c(46, 42.66667, 41, 42.75, 42.6, 43.33333, 39.5, 44, 41.25, 40.33333, 30.5, 35, 38.66667, 40.75, 40.75, 38.66667, 38.5, 42, 30, 38.5, 39.5, 35.33333, 36.5, 42.5, 29.5, 34.8, 42, 45.33333, 34.66667, 41.66667, 42.5, 42, 45.5, 43.6, 37.5, 44, 44.25, 41, 37.25, 43, 45, 41.4, 43, 44, 41, 41.25, 43.66667, 43.8, 43.8, 44.8, 42, 44, 44.25, 43.5, 6.5, 44, 39.75, 37.66667, 34.5, 35.66667, 44.25, 42.75, 44, 28.33333, 43, 42, 45))

This doesn't: casnet::crqa_parameters(c(47.8, 45, 43, 43, 39, 45, 35.66667, 24, 19.5, 47.33333, 48, 45, 40, 33.25, 33.25, 29.33333, 45.75, 48, 32.5, 44, 39.5, 39.33333, 42.25, 48.5, 48.5, 45.2, 41.5, 48.33333, 47.83333, 41, 48, 15, 48, 48.4, 47.33333, 39, 37, 49, 48.5, 49, 47.75, 41, 48, 28.5, 21, 45, 48.33333, 48.6, 45, 46, 47.2, 48.5, 48.75, 21, 44.5, 47, 47.25, 48, 42.25, 48.66667, 48.5, 48, 40.33333, 43.33333, 48.25, 48.33333, 48))

heinonmatti commented 5 years ago

Update: in some use cases, I managed to circumvent the error by setting maxDim to a small number, such as maxDim = 5

heinonmatti commented 5 years ago

Oops sorry, accidentally closed....

heinonmatti commented 4 years ago

Update:

In version 0.1.5, casnet::est_parameters automatically adjusts the maxDim for short series.

E.g. this works; it adjusts dimension to 2.

testData <- c(35, 42, 26, 44, 41, 15, 31, 24, 41, 11, 26, 
              38, 41, 32, 49, 43, 39, 39, 41, 32, 49, 25, 
              41, 33, 49, 39, 26, 44, 49, 42, 36, 26, 34, 
              42, 26, 25, 29, 30, 30, 31, 28, 20, 21, 28, 11)

casnet::est_parameters(y = testData,  maxDim = 3)

Changed value of maxDim to 2

But when original maxDim is 9-14, it somehow doesn't:

casnet::est_parameters(y = testData, maxDim = 9)

Error in data.frame(Nn.pct = as.numeric(fnnSeries[1, ]), Nsize = nnSizes[N], : object 'fnnSeries' not found

For 15, it works again:

casnet::est_parameters(y = testData, maxDim = 15)

Changed value of maxDim to 12 Only 2 lags to evaluate, setting 'first.minimum' to 1