Skip to content

object of type 'closure' is not subsettable

4 messages · Allan Tanaka, Jeff Newmiller, William Dunlap

#
Hi.
I tried to run this R-code but still completely no idea why it still gives error message: Error in forecast[[d + 1]] = paste(index(lEJReturnsOffset[windowLength]), ?: object of type 'closure' is not subsettable
Here is the R-code:
library(rugarch); library(sos); library(forecast);library(lattice)library(quantmod); require(stochvol); require(fBasics);data = read.table("EURJPY.m1440.csv", header=F)names(data)data=ts(data)lEJ=log(data)lret.EJ = 100*diff(lEJ)lret.EJ = ts(lret.EJ)lret.EJ[as.character(head(index(lret.EJ)))]=0windowLength=500foreLength=length(lret.EJ)-windowLengthforecasts<-vector(mode="character", length=foreLength)for (d in 0:foreLength) {? lEJReturnsOffset=lret.EJ[(1+d):(windowLength+d)]? final.aic<-Inf? final.order<-c(0,0,0)? for (p in 0:5) for (q in 0:5) {? ? if(p == 0 && q == 0) {? ? ? next? ? }? ??? ? arimaFit=tryCatch(arima(lEJReturnsOffset, order=c(p,0,q)),? ? ? ? ? ? ? ? ? ? ? error=function(err)FALSE,? ? ? ? ? ? ? ? ? ? ? warning=function(err)FALSE)? ? if(!is.logical(arimaFit)) {? ? ? current.aic<-AIC(arimaFit)? ? ? if(current.aic<final.aic) {? ? ? ? final.aic<-current.aic? ? ? ? final.order<-c(p,0,q)? ? ? ? final.arima<-arima(lEJReturnsOffset, order=final.order)? ? ? }? ? } else {? ? ? next? ? }? }
spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1,1)),? ? ? ? ? ? ? ? ? ? ?mean.model = list(armaOrder = c(final.order[1], final.order[3]), arfima = FALSE, include.mean = TRUE),? ? ? ? ? ? ? ? ? ? ?distribution.model = "sged")fit <- tryCatch(ugarchfit(spec, lEJReturnsOffset, solver='gosolnp'),? error=function(e) e, warning=function(w) w)if(is(fit, "warning")) {? forecast[d+1]=paste(index(lEJReturnsOffset[windowLength]), 1, sep=",")? print(paste(index(lEJReturnsOffset[windowLength]), 1, sep=","))} else {? fore = ugarchforecast(fit, n.ahead=1)? ind = fore at forecast$seriesFor? forecasts[d+1] = paste(colnames(ind), ifelse(ind[1] < 0, -1, 1), sep=",")? print(paste(colnames(ind), ifelse(ind[1] < 0, -1, 1), sep=","))?}}write.csv(forecasts, file="forecasts.csv", row.names=FALSE)
??
#
By failing to send your email in plain text format on this mailing list, we see a damaged version of what you saw when you sent it. 

Also, we would need some some data to test the code with. Google "r reproducible example" to find discussions of how to ask questions online.
#
A 'closure' is a function and you cannot use '[' or '[[' to make a
subset of a function.

You used
   forecast[d+1] <- ...
in one branch of the 'if' statement and
   forecasts[d+1] <- ...
in the other.  Do you see the problem now?

By the way, the code snippet in the error message says '[[d+1]]' but
the code you supplied has '[d+1]'.  Does the html mangling selectively
double brackets or did you not show us the code that generated that
message?

Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Sun, Feb 12, 2017 at 4:34 AM, Allan Tanaka <allantanaka11 at yahoo.com> wrote:
#
Dang, i should notice that forecastS and forecast thingy. Now it works like a charm. ThANKS
On Monday, 13 February 2017, 3:56, William Dunlap <wdunlap at tibco.com> wrote:
> Error in forecast[[d + 1]] = paste(index(lEJReturnsOffset[windowLength]),? : object of type 'closure' is not subsettable

A 'closure' is a function and you cannot use '[' or '[[' to make a
subset of a function.

You used
? forecast[d+1] <- ...
in one branch of the 'if' statement and
? forecasts[d+1] <- ...
in the other.? Do you see the problem now?

By the way, the code snippet in the error message says '[[d+1]]' but
the code you supplied has '[d+1]'.? Does the html mangling selectively
double brackets or did you not show us the code that generated that
message?

Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Sun, Feb 12, 2017 at 4:34 AM, Allan Tanaka <allantanaka11 at yahoo.com> wrote: