Quantcast

Error message: object of type 'closure' is not subsettable

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Error message: object of type 'closure' is not subsettable

Newbie
Dear R-users

I need to calibrate kappa, rho, eta, theta, v0 in the following code, see below. However when I run it, I get:

y <- function(kappahat, rhohat, etahat, thetahat, v0hat) {sum(difference(k, t, S0, X, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)}
> nlminb(start=list(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper =ub)
Error in dots[[1L]][[1L]] : object of type 'closure' is not subsettable

And I don't know what this mean and what I am doing wrong. Can anyone help me?
Here is my code and data set.

Best
Rikke

S%26P_500_calls%2C_jan-jun_2010.csv

marketdata <- read.csv(file="S&P 500 calls, jan-jun 2010.csv", header=TRUE, sep=";")
spot <- read.csv(file="S&P 500 spot and return 2010.csv", header=TRUE, sep=";")

#------------------------- Values ----------------------------------
#### Data imported
S0 <- 1136.03
X <- marketdata[1:460,9]
t <- marketdata[1:460,17]/365 #Notice the T is measured in years now
implvol <- marketdata[1:460,12]
k <- log(X/(S0*exp(r-q)*t))

###### Initial values
kappa <- 0.0663227 # Lambda = -kappa
rho <- -0.6678461
eta <- 0.002124704
theta <- 0.0001421415
v0 <- 0.0001421415

q <- 0.02145608
r <- 0.01268737

#-----------------------------------------------------------------------------
#### The price of a Call option (Eq. (5.6) of The Volatility Surface, Gatheral)
# In terms of log moneyness

Price_call <- function(phi, k, t)
{
        integrand <-  function(u) {Re(exp(-1i*u*k)*phi(u - 1i/2, t)/(u^2 + 1/4))}
        res <- S0*exp(-q*t) - exp(k/2)/pi*integrate(integrand,lower=0,upper=Inf)$value
        return(res)
}

Price_callVec <- function(phi, k, t)
{
        mapply(Price_call, phi, k, t)
}

# The characteric formula for the Heston model (Eq. XX)
phiHeston <- function(kappa, rho, eta, theta, v0)
{
        lambda <- - kappa
        function(u, t)
        {
                alpha <- -u*u/2 - 1i*u/2      
                beta <- lambda - rho*eta*1i*u
                gamma <- eta^2/2
                d <- sqrt(beta*beta - 4*alpha*gamma)
                rplus <- (beta + d)/(eta^2)
                rminus <- (beta - d)/(eta^2)
                g <- rminus / rplus
                D <- rminus * (1 - exp(-d*t))/ (1 - g*exp(-d*t))
                C <- lambda* (rminus * t - 2/eta^2 * log( (1 - g*exp(-(d*t)))/(1 - g)) )
                return(exp(C*theta + D*v0))
        }
}

## Calculating the Heston model price with fourier
HestonCall<-function(k,t)
{
res<-Price_callVec(phiHeston(kappa, rho, eta, theta, v0),k,t)
return(res)
}

##### Vectorizing the function to handle vectors of strikes and maturities
HestonCallVec <- function(k,t)
{
mapply (HestonCall, k, t)
}

lb <- c(0, -0.9, 0, 0, 0)
ub <- c(100, 0.9, 0.5, 1, 1)

difference <- function(k, t, S0, X, r, implvol, q, kappa, rho, eta, theta, v0)
{
return(HestonCallVec(k,t) - BS_Call(S0, X, t, r, implvol, q))
}

y <- function(kappahat, rhohat, etahat, thetahat, v0hat) {sum(difference(k, t, S0, X, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)}
nlminb(start=list(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper =ub)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

Berend Hasselman
Newbie wrote
Dear R-users

I need to calibrate kappa, rho, eta, theta, v0 in the following code, see below. However when I run it, I get:

y <- function(kappahat, rhohat, etahat, thetahat, v0hat) {sum(difference(k, t, S0, X, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)}
> nlminb(start=list(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper =ub)
Error in dots[[1L]][[1L]] : object of type 'closure' is not subsettable

And I don't know what this mean and what I am doing wrong. Can anyone help me?
Here is my code and data set.

Best
Rikke

..............

y <- function(kappahat, rhohat, etahat, thetahat, v0hat) {sum(difference(k, t, S0, X, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)}
nlminb(start=list(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper =ub)
You haven't given all your data. Spot csv is missing.

You are using nlminb incorrectly.
It expects the objective function to take a numeric vector as argument as clearly stated in the documentation.
Which should have been clear after your first post.

This would possibly help (NOT tested because of lack of data)

y <- function(par) {kappahat<-par[1]; rhohat<-par[2]; etahat<-par[3]; thetahat<-par[4]; v0hat<-par[5]; sum(difference(k, t, S0, X, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)}

nlminb(start=c(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper =ub)

Berend
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

Newbie
In reply to this post by Newbie
Thank you for your help, even though there was such an obvious mistake, Im sorry for that
I have now tried to incorporate your suggested solution, but just as last time (the other post that you referred to), I get the values of the initial parameters when I run nlminb.
I have changed the code a bit, see below, due to some error messages.
Can anyone see what I am doing wrong?

Thank you in advance!

S%26P_500_calls%2C_jan-jun_2010.csv

setwd("F:/Data til speciale/")

############## Calibration of Heston model parameters


marketdata <- read.csv(file="S&P 500 calls, jan-jun 2010.csv", header=TRUE, sep=";")

BS_Call <- function(S0, K, T, r, sigma, q)
{
        sig <- sigma * sqrt(T)
        d1 <- (log (S0/K) + (r - q + sigma^2/2) * T ) / sig
        d2 <- d1 - sig
        Presentvalue <- exp(-r*T)
        return (S0 * exp(-q*T) * pnorm(d1) - K*Presentvalue*pnorm(d2))
}


#------------------------- Values ----------------------------------
#### Data imported
S0 <- 1136.02
X <- marketdata[1:460,9]
t <- marketdata[1:460,17]/365 #Notice the T is measured in years now
implvol <- marketdata[1:460,12]

k <- log(X/(S0*exp(r-q)*t))

###### Initial values
kappa <- 0.0663227 # Lambda = -kappa
rho <- -0.6678461
eta <- 0.002124704
theta <- 0.0001421415
v0 <- 0.0001421415

q <- 0.02145608
r <- 0.01268737

#-----------------------------------------------------------------------------
#### The price of a Call option (Eq. (5.6) of The Volatility Surface, Gatheral)
# In terms of log moneyness

Price_call <- function(phi, k, t)
{
        integrand <-  function(u) {Re(exp(-1i*u*k)*phi(u - 1i/2, t)/(u^2 + 1/4))}
        res <- S0*exp(-q*t) - exp(k/2)/pi*integrate(Vectorize(integrand),lower=0,upper=Inf, subdivisions=460)$value
        return(res)
}


# The characteric formula for the Heston model (Eq. XX)
phiHeston <- function(kappa, rho, eta, theta, v0)
{
        lambda <- -kappa
        function(u, t)
        {
                alpha <- -u*u/2 - 1i*u/2      
                beta <- lambda - rho*eta*1i*u
                gamma <- eta^2/2
                d <- sqrt(beta*beta - 4*alpha*gamma)
                rplus <- (beta + d)/(eta^2)
                rminus <- (beta - d)/(eta^2)
                g <- rminus / rplus
                D <- rminus * (1 - exp(-d*t))/ (1 - g*exp(-d*t))
                C <- lambda* (rminus * t - 2/eta^2 * log( (1 - g*exp(-(d*t)))/(1 - g)) )
                return(exp(C*theta + D*v0))
        }
}

## Calculating the Heston model price with fourier
HestonCall<-function(k,t)
{
res<-Price_call(phiHeston(kappa, rho, eta, theta, v0),k,t)
return(res)
}


##### Vectorizing the function to handle vectors of strikes and maturities
HestonCallVec <- function(k,t)
{
mapply (HestonCall, k, t)
}

lb <- c(0, -0.9, 0, 0, 0)
ub <- c(100, 0.9, 0.5, 1, 1)
#BS_Call(S0, exp(k), t, r, implvol, q)

difference <- function(k, t, S0, r, implvol, q, kappa, rho, eta, theta, v0)
{
return(HestonCallVec(k,t) - BS_Call(S0, exp(k), t, r, implvol, q))
}
difference(k,t,S0, r, implvol, q, kappa, rho, eta, theta, v0)
y <- function(par) {kappahat<-par[1]; rhohat<-par[2]; etahat<-par[3]; thetahat<-par[4]; v0hat<-par[5]; sum(difference(k, t, S0, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)}
nlminb(start=c(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper =ub)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

Newbie
I think I have found my problem, but I dont know how to correct it. I have found an old post saying that it might be a problem if the starting values are evaluated at Inf (see link here http://r.789695.n4.nabble.com/Help-about-nlminb-function-td3089048.html)

But how can I run nlminb without the starting values being evaluated at Inf.?
What I more specifically want to do, is to set C and D equal to 0 for the starting values, but to have it evaluated for Inf for the rest (C and D equal to what the function says). Does anyone have a suggestion on how to do this? Is the solution to do loops instead of vectorisation? Please help me
Thanks in advance!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

rahul
This post has NOT been accepted by the mailing list yet.
In reply to this post by Newbie
Hi everyone

I am using the wavelet and waveslim package in R to find the wave variance.Here is the code

return.modwt<-modwt(X, filter="la8", n.levels=5, boundary="periodic", fast=TRUE)
return.modwt.var<- wave.variance(return.modwt, type="nongaussian")

I am expecting a matrix with 5 rows(no. of levels) and 3 columns(variance,upper bound,lower bound) but I am getting a message: no method for coercing this S4 class to a vector.
What does this mean?I have installed waveslim 1.6.4 version.
Newbie wrote
Dear R-users

I need to calibrate kappa, rho, eta, theta, v0 in the following code, see below. However when I run it, I get:

y <- function(kappahat, rhohat, etahat, thetahat, v0hat) {sum(difference(k, t, S0, X, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)}
> nlminb(start=list(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper =ub)
Error in dots[[1L]][[1L]] : object of type 'closure' is not subsettable

And I don't know what this mean and what I am doing wrong. Can anyone help me?
Here is my code and data set.

Best
Rikke

S%26P_500_calls%2C_jan-jun_2010.csv

marketdata <- read.csv(file="S&P 500 calls, jan-jun 2010.csv", header=TRUE, sep=";")
spot <- read.csv(file="S&P 500 spot and return 2010.csv", header=TRUE, sep=";")

#------------------------- Values ----------------------------------
#### Data imported
S0 <- 1136.03
X <- marketdata[1:460,9]
t <- marketdata[1:460,17]/365 #Notice the T is measured in years now
implvol <- marketdata[1:460,12]
k <- log(X/(S0*exp(r-q)*t))

###### Initial values
kappa <- 0.0663227 # Lambda = -kappa
rho <- -0.6678461
eta <- 0.002124704
theta <- 0.0001421415
v0 <- 0.0001421415

q <- 0.02145608
r <- 0.01268737

#-----------------------------------------------------------------------------
#### The price of a Call option (Eq. (5.6) of The Volatility Surface, Gatheral)
# In terms of log moneyness

Price_call <- function(phi, k, t)
{
        integrand <-  function(u) {Re(exp(-1i*u*k)*phi(u - 1i/2, t)/(u^2 + 1/4))}
        res <- S0*exp(-q*t) - exp(k/2)/pi*integrate(integrand,lower=0,upper=Inf)$value
        return(res)
}

Price_callVec <- function(phi, k, t)
{
        mapply(Price_call, phi, k, t)
}

# The characteric formula for the Heston model (Eq. XX)
phiHeston <- function(kappa, rho, eta, theta, v0)
{
        lambda <- - kappa
        function(u, t)
        {
                alpha <- -u*u/2 - 1i*u/2      
                beta <- lambda - rho*eta*1i*u
                gamma <- eta^2/2
                d <- sqrt(beta*beta - 4*alpha*gamma)
                rplus <- (beta + d)/(eta^2)
                rminus <- (beta - d)/(eta^2)
                g <- rminus / rplus
                D <- rminus * (1 - exp(-d*t))/ (1 - g*exp(-d*t))
                C <- lambda* (rminus * t - 2/eta^2 * log( (1 - g*exp(-(d*t)))/(1 - g)) )
                return(exp(C*theta + D*v0))
        }
}

## Calculating the Heston model price with fourier
HestonCall<-function(k,t)
{
res<-Price_callVec(phiHeston(kappa, rho, eta, theta, v0),k,t)
return(res)
}

##### Vectorizing the function to handle vectors of strikes and maturities
HestonCallVec <- function(k,t)
{
mapply (HestonCall, k, t)
}

lb <- c(0, -0.9, 0, 0, 0)
ub <- c(100, 0.9, 0.5, 1, 1)

difference <- function(k, t, S0, X, r, implvol, q, kappa, rho, eta, theta, v0)
{
return(HestonCallVec(k,t) - BS_Call(S0, X, t, r, implvol, q))
}

y <- function(kappahat, rhohat, etahat, thetahat, v0hat) {sum(difference(k, t, S0, X, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)}
nlminb(start=list(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper =ub)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

Aparna Sampath
In reply to this post by Newbie
Hi All

I am trying to use the unlist() in R to a list variable.  The following statements are within a function.
{
denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n)
 returnValue <- l2 / (denominator + 11)
  attr(returnValue,"numerator") <- l2
  attr(returnValue,"denominator") <- denominator
  returnValue
}

And when I try to unlist the variable returnValue

 numerators <- unlist(testStatistics["numerator",])
  denominators <- unlist(testStatistics["denominator",])

I get the following error:

>Error in testStatistics["numerator", ] :
  object of type 'closure' is not subsettable

I read some threads in R help on this error and they had asked to check if we are using the right datatype to the right function. But in my case it is pretty straightforward since I just list it in one function and try to unlist it later. Any suggestions?
Thanks for the help :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

Joshua Wiley-2
Hi Aparna,

Can you please post a reproducible example?  It is difficult to
provide much concrete help without having "testStatistics".  One thing
you might try is looking at:

str(testStatistics["numerator",])

is it actually a list?  If it is not (most likely given the error) and
it is supposed to be, you need to figure out what aspect of the
generation of it is going awry.

Cheers,

Josh

On Tue, Feb 28, 2012 at 12:23 AM, Aparna Sampath
<[hidden email]> wrote:

> Hi All
>
> I am trying to use the unlist() in R to a list variable.  The following
> statements are within a function.
> {
> denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n)
>  returnValue <- l2 / (denominator + 11)
>  attr(returnValue,"numerator") <- l2
>  attr(returnValue,"denominator") <- denominator
>  returnValue
> }
>
> And when I try to unlist the variable returnValue
>
>  numerators <- unlist(testStatistics["numerator",])
>  denominators <- unlist(testStatistics["denominator",])
>
> I get the following error:
>
>>Error in testStatistics["numerator", ] :
>  object of type 'closure' is not subsettable
>
> I read some threads in R help on this error and they had asked to check if
> we are using the right datatype to the right function. But in my case it is
> pretty straightforward since I just list it in one function and try to
> unlist it later. Any suggestions?
> Thanks for the help :)
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Error-message-object-of-type-closure-is-not-subsettable-tp3752886p4427399.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

Aparna Sampath
Hi Josh

Kindly find below the code as it is executed:

test.functional.t <- function(res.em1,res.em2,mint,maxt,se.m=0,points=300)
{
  at <- seq(mint,maxt,length.out=points)
  by <- at[2] - at[1]

  mu1 <- spline(x=res.em1$tau,y=res.em1$eta,xout=at,method="natural")$y
l2 <- functional.norm(mu1,mu2,by=by)

  s1 <- mean(sapply(1:res.em1$n,
    function(i)
    {
      v <-
spline(x=res.em1$tau,y=res.em1$vi[[i]],xout=at,method="natural")$y
      functional.norm(v,by=by)^2
    }))
denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n) ### formula for se
  returnValue <- l2 / (denominator + se.m)

  attr(returnValue,"numerator") <- l2
  attr(returnValue,"denominator") <- denominator

  returnValue
}

moderated.functional.t <-
function(testStatistics,alpha.step=0.05,quantile.step=0.01)
{
  numerators <- unlist(testStatistics["numerator",])
  denominators <- unlist(testStatistics["denominator",])
}

I get my error in the function above moderated.functional.t. testStatistics
is shown to be a function(x) when I type it in R console. But there is no
function definition for testStatistics in the code. My R understanding is
still elementary.

Thanks
Aparna




On Tue, Feb 28, 2012 at 5:25 PM, Joshua Wiley <[hidden email]>wrote:

> Hi Aparna,
>
> Can you please post a reproducible example?  It is difficult to
> provide much concrete help without having "testStatistics".  One thing
> you might try is looking at:
>
> str(testStatistics["numerator",])
>
> is it actually a list?  If it is not (most likely given the error) and
> it is supposed to be, you need to figure out what aspect of the
> generation of it is going awry.
>
> Cheers,
>
> Josh
>
> On Tue, Feb 28, 2012 at 12:23 AM, Aparna Sampath
> <[hidden email]> wrote:
> > Hi All
> >
> > I am trying to use the unlist() in R to a list variable.  The following
> > statements are within a function.
> > {
> > denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n)
> >  returnValue <- l2 / (denominator + 11)
> >  attr(returnValue,"numerator") <- l2
> >  attr(returnValue,"denominator") <- denominator
> >  returnValue
> > }
> >
> > And when I try to unlist the variable returnValue
> >
> >  numerators <- unlist(testStatistics["numerator",])
> >  denominators <- unlist(testStatistics["denominator",])
> >
> > I get the following error:
> >
> >>Error in testStatistics["numerator", ] :
> >  object of type 'closure' is not subsettable
> >
> > I read some threads in R help on this error and they had asked to check
> if
> > we are using the right datatype to the right function. But in my case it
> is
> > pretty straightforward since I just list it in one function and try to
> > unlist it later. Any suggestions?
> > Thanks for the help :)
> >
> > --
> > View this message in context:
> http://r.789695.n4.nabble.com/Error-message-object-of-type-closure-is-not-subsettable-tp3752886p4427399.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Joshua Wiley
> Ph.D. Student, Health Psychology
> Programmer Analyst II, Statistical Consulting Group
> University of California, Los Angeles
> https://joshuawiley.com/
>



--
Aparna Sampath
Master of Science (Bioinformatics)
Nanyang Technological University
Mob no : +65 91601854

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

Joshua Wiley-2
Hi Aparna,

If you have not defined testStatistics in your code, but it is a
function, then either you defined it at some earlier point and it was
never removed, or some other package you loaded defines it.

You could try using your code in a clean R session (make sure that an
old workspace is not automatically loaded; one way would be by closing
R, deleting the old workspace, and then starting a new instance).

Cheers,

Josh

On Tue, Feb 28, 2012 at 1:37 AM, Aparna Sampath
<[hidden email]> wrote:

> Hi Josh
>
> Kindly find below the code as it is executed:
>
> test.functional.t <- function(res.em1,res.em2,mint,maxt,se.m=0,points=300)
> {
>   at <- seq(mint,maxt,length.out=points)
>   by <- at[2] - at[1]
>
>   mu1 <- spline(x=res.em1$tau,y=res.em1$eta,xout=at,method="natural")$y
> l2 <- functional.norm(mu1,mu2,by=by)
>
>   s1 <- mean(sapply(1:res.em1$n,
>     function(i)
>     {
>       v <-
> spline(x=res.em1$tau,y=res.em1$vi[[i]],xout=at,method="natural")$y
>       functional.norm(v,by=by)^2
>     }))
> denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n) ### formula for se
>   returnValue <- l2 / (denominator + se.m)
>
>   attr(returnValue,"numerator") <- l2
>   attr(returnValue,"denominator") <- denominator
>
>   returnValue
> }
>
> moderated.functional.t <-
> function(testStatistics,alpha.step=0.05,quantile.step=0.01)
> {
>   numerators <- unlist(testStatistics["numerator",])
>   denominators <- unlist(testStatistics["denominator",])
> }
>
> I get my error in the function above moderated.functional.t. testStatistics
> is shown to be a function(x) when I type it in R console. But there is no
> function definition for testStatistics in the code. My R understanding is
> still elementary.
>
> Thanks
> Aparna
>
>
>
>
> On Tue, Feb 28, 2012 at 5:25 PM, Joshua Wiley <[hidden email]>
> wrote:
>>
>> Hi Aparna,
>>
>> Can you please post a reproducible example?  It is difficult to
>> provide much concrete help without having "testStatistics".  One thing
>> you might try is looking at:
>>
>> str(testStatistics["numerator",])
>>
>> is it actually a list?  If it is not (most likely given the error) and
>> it is supposed to be, you need to figure out what aspect of the
>> generation of it is going awry.
>>
>> Cheers,
>>
>> Josh
>>
>> On Tue, Feb 28, 2012 at 12:23 AM, Aparna Sampath
>> <[hidden email]> wrote:
>> > Hi All
>> >
>> > I am trying to use the unlist() in R to a list variable.  The following
>> > statements are within a function.
>> > {
>> > denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n)
>> >  returnValue <- l2 / (denominator + 11)
>> >  attr(returnValue,"numerator") <- l2
>> >  attr(returnValue,"denominator") <- denominator
>> >  returnValue
>> > }
>> >
>> > And when I try to unlist the variable returnValue
>> >
>> >  numerators <- unlist(testStatistics["numerator",])
>> >  denominators <- unlist(testStatistics["denominator",])
>> >
>> > I get the following error:
>> >
>> >>Error in testStatistics["numerator", ] :
>> >  object of type 'closure' is not subsettable
>> >
>> > I read some threads in R help on this error and they had asked to check
>> > if
>> > we are using the right datatype to the right function. But in my case it
>> > is
>> > pretty straightforward since I just list it in one function and try to
>> > unlist it later. Any suggestions?
>> > Thanks for the help :)
>> >
>> > --
>> > View this message in context:
>> > http://r.789695.n4.nabble.com/Error-message-object-of-type-closure-is-not-subsettable-tp3752886p4427399.html
>> > Sent from the R help mailing list archive at Nabble.com.
>> >
>> > ______________________________________________
>> > [hidden email] mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>> --
>> Joshua Wiley
>> Ph.D. Student, Health Psychology
>> Programmer Analyst II, Statistical Consulting Group
>> University of California, Los Angeles
>> https://joshuawiley.com/
>
>
>
>
> --
> Aparna Sampath
> Master of Science (Bioinformatics)
> Nanyang Technological University
> Mob no : +65 91601854



--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

PIKAL Petr
In reply to this post by Aparna Sampath
Hi

Difficult to without knowing what objects you are operating your
functions.

I get

> test.functional.t(1:10,1:10,3,4)
Error in res.em1$eta : $ operator is invalid for atomic vectors
> moderated.functional.t(1:10)
Error in testStatistics["numerator", ] : incorrect number of dimensions

And without suitable objects for those functions to operate it is
impossible to come with reasonable suggestion.

Anyway there is a function on your system which is called testStatistics
and you can not subset functions, hence your error. I did not find this
function in R pacages but I can not say that it is really not there.

You can get rid of this function by

rm(testStatistics)

Regards
Petr


>
> Kindly find below the code as it is executed:
>
> test.functional.t <-
function(res.em1,res.em2,mint,maxt,se.m=0,points=300)

> {
>   at <- seq(mint,maxt,length.out=points)
>   by <- at[2] - at[1]
>
>   mu1 <- spline(x=res.em1$tau,y=res.em1$eta,xout=at,method="natural")$y
> l2 <- functional.norm(mu1,mu2,by=by)
>
>   s1 <- mean(sapply(1:res.em1$n,
>     function(i)
>     {
>       v <-
> spline(x=res.em1$tau,y=res.em1$vi[[i]],xout=at,method="natural")$y
>       functional.norm(v,by=by)^2
>     }))
> denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n) ### formula for se
>   returnValue <- l2 / (denominator + se.m)
>
>   attr(returnValue,"numerator") <- l2
>   attr(returnValue,"denominator") <- denominator
>
>   returnValue
> }
>
> moderated.functional.t <-
> function(testStatistics,alpha.step=0.05,quantile.step=0.01)
> {
>   numerators <- unlist(testStatistics["numerator",])
>   denominators <- unlist(testStatistics["denominator",])
> }
>
> I get my error in the function above moderated.functional.t.
testStatistics
> is shown to be a function(x) when I type it in R console. But there is
no
> function definition for testStatistics in the code. My R understanding
is
> still elementary.
>
> Thanks
> Aparna
>
>
>
>
> On Tue, Feb 28, 2012 at 5:25 PM, Joshua Wiley
<[hidden email]>wrote:

>
> > Hi Aparna,
> >
> > Can you please post a reproducible example?  It is difficult to
> > provide much concrete help without having "testStatistics".  One thing
> > you might try is looking at:
> >
> > str(testStatistics["numerator",])
> >
> > is it actually a list?  If it is not (most likely given the error) and
> > it is supposed to be, you need to figure out what aspect of the
> > generation of it is going awry.
> >
> > Cheers,
> >
> > Josh
> >
> > On Tue, Feb 28, 2012 at 12:23 AM, Aparna Sampath
> > <[hidden email]> wrote:
> > > Hi All
> > >
> > > I am trying to use the unlist() in R to a list variable.  The
following

> > > statements are within a function.
> > > {
> > > denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n)
> > >  returnValue <- l2 / (denominator + 11)
> > >  attr(returnValue,"numerator") <- l2
> > >  attr(returnValue,"denominator") <- denominator
> > >  returnValue
> > > }
> > >
> > > And when I try to unlist the variable returnValue
> > >
> > >  numerators <- unlist(testStatistics["numerator",])
> > >  denominators <- unlist(testStatistics["denominator",])
> > >
> > > I get the following error:
> > >
> > >>Error in testStatistics["numerator", ] :
> > >  object of type 'closure' is not subsettable
> > >
> > > I read some threads in R help on this error and they had asked to
check
> > if
> > > we are using the right datatype to the right function. But in my
case it
> > is
> > > pretty straightforward since I just list it in one function and try
to

> > > unlist it later. Any suggestions?
> > > Thanks for the help :)
> > >
> > > --
> > > View this message in context:
> > http://r.789695.n4.nabble.com/Error-message-object-of-type-closure-is-
> not-subsettable-tp3752886p4427399.html
> > > Sent from the R help mailing list archive at Nabble.com.
> > >
> > > ______________________________________________
> > > [hidden email] mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> > --
> > Joshua Wiley
> > Ph.D. Student, Health Psychology
> > Programmer Analyst II, Statistical Consulting Group
> > University of California, Los Angeles
> > https://joshuawiley.com/
> >
>
>
>
> --
> Aparna Sampath
> Master of Science (Bioinformatics)
> Nanyang Technological University
> Mob no : +65 91601854
>
>    [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

Aparna Sampath
Hi Josh, Petr

I checked that testStatistics is a function but it is not defined in the
code anywhere else. But if I am able to remove it and give the input by my
own to the function which calls testStatistics, it might work.

The hurdle here for me is that the input is a set* of values and each value
has 2 attributes. Each variable is generated per iteration and has the
numerator, denominator as its attributes and a value. But when I read it in
a loop,  i face two problems: 1. only the last i value is stored and the
rest are NULL. 2. the one stored does not contain the attribute values.
 Each value looks like this:
>t
[1] 3.897434
attr(,"numerator")
[1] 0.0002134457
attr(,"denominator")
[1] 5.47657e-05

Eg:
for (i in 1:5)
{
t<- test.functional.t(res.em1,res.em2,mint,maxt,se.m=0,points=300) ###
function calling
}

>t
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

[[4]]
NULL

[1] 3.897434

Any suggestions. Thanks for all the help. :)

Regards
Aparna






On Tue, Feb 28, 2012 at 11:01 PM, Petr PIKAL <[hidden email]> wrote:

> Hi
>
> Difficult to without knowing what objects you are operating your
> functions.
>
> I get
>
> > test.functional.t(1:10,1:10,3,4)
> Error in res.em1$eta : $ operator is invalid for atomic vectors
> > moderated.functional.t(1:10)
> Error in testStatistics["numerator", ] : incorrect number of dimensions
>
> And without suitable objects for those functions to operate it is
> impossible to come with reasonable suggestion.
>
> Anyway there is a function on your system which is called testStatistics
> and you can not subset functions, hence your error. I did not find this
> function in R pacages but I can not say that it is really not there.
>
> You can get rid of this function by
>
> rm(testStatistics)
>
> Regards
> Petr
>
>
> >
> > Kindly find below the code as it is executed:
> >
> > test.functional.t <-
> function(res.em1,res.em2,mint,maxt,se.m=0,points=300)
> > {
> >   at <- seq(mint,maxt,length.out=points)
> >   by <- at[2] - at[1]
> >
> >   mu1 <- spline(x=res.em1$tau,y=res.em1$eta,xout=at,method="natural")$y
> > l2 <- functional.norm(mu1,mu2,by=by)
> >
> >   s1 <- mean(sapply(1:res.em1$n,
> >     function(i)
> >     {
> >       v <-
> > spline(x=res.em1$tau,y=res.em1$vi[[i]],xout=at,method="natural")$y
> >       functional.norm(v,by=by)^2
> >     }))
> > denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n) ### formula for se
> >   returnValue <- l2 / (denominator + se.m)
> >
> >   attr(returnValue,"numerator") <- l2
> >   attr(returnValue,"denominator") <- denominator
> >
> >   returnValue
> > }
> >
> > moderated.functional.t <-
> > function(testStatistics,alpha.step=0.05,quantile.step=0.01)
> > {
> >   numerators <- unlist(testStatistics["numerator",])
> >   denominators <- unlist(testStatistics["denominator",])
> > }
> >
> > I get my error in the function above moderated.functional.t.
> testStatistics
> > is shown to be a function(x) when I type it in R console. But there is
> no
> > function definition for testStatistics in the code. My R understanding
> is
> > still elementary.
> >
> > Thanks
> > Aparna
> >
> >
> >
> >
> > On Tue, Feb 28, 2012 at 5:25 PM, Joshua Wiley
> <[hidden email]>wrote:
> >
> > > Hi Aparna,
> > >
> > > Can you please post a reproducible example?  It is difficult to
> > > provide much concrete help without having "testStatistics".  One thing
> > > you might try is looking at:
> > >
> > > str(testStatistics["numerator",])
> > >
> > > is it actually a list?  If it is not (most likely given the error) and
> > > it is supposed to be, you need to figure out what aspect of the
> > > generation of it is going awry.
> > >
> > > Cheers,
> > >
> > > Josh
> > >
> > > On Tue, Feb 28, 2012 at 12:23 AM, Aparna Sampath
> > > <[hidden email]> wrote:
> > > > Hi All
> > > >
> > > > I am trying to use the unlist() in R to a list variable.  The
> following
> > > > statements are within a function.
> > > > {
> > > > denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n)
> > > >  returnValue <- l2 / (denominator + 11)
> > > >  attr(returnValue,"numerator") <- l2
> > > >  attr(returnValue,"denominator") <- denominator
> > > >  returnValue
> > > > }
> > > >
> > > > And when I try to unlist the variable returnValue
> > > >
> > > >  numerators <- unlist(testStatistics["numerator",])
> > > >  denominators <- unlist(testStatistics["denominator",])
> > > >
> > > > I get the following error:
> > > >
> > > >>Error in testStatistics["numerator", ] :
> > > >  object of type 'closure' is not subsettable
> > > >
> > > > I read some threads in R help on this error and they had asked to
> check
> > > if
> > > > we are using the right datatype to the right function. But in my
> case it
> > > is
> > > > pretty straightforward since I just list it in one function and try
> to
> > > > unlist it later. Any suggestions?
> > > > Thanks for the help :)
> > > >
> > > > --
> > > > View this message in context:
> > > http://r.789695.n4.nabble.com/Error-message-object-of-type-closure-is-
> > not-subsettable-tp3752886p4427399.html
> > > > Sent from the R help mailing list archive at Nabble.com.
> > > >
> > > > ______________________________________________
> > > > [hidden email] mailing list
> > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > PLEASE do read the posting guide
> > > http://www.R-project.org/posting-guide.html
> > > > and provide commented, minimal, self-contained, reproducible code.
> > >
> > >
> > >
> > > --
> > > Joshua Wiley
> > > Ph.D. Student, Health Psychology
> > > Programmer Analyst II, Statistical Consulting Group
> > > University of California, Los Angeles
> > > https://joshuawiley.com/
> > >
> >
> >
> >
> > --
> > Aparna Sampath
> > Master of Science (Bioinformatics)
> > Nanyang Technological University
> > Mob no : +65 91601854
> >
> >    [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

PIKAL Petr
Hi

If you want sensible response you need to ask sensible question and more
importantly provide working example or at least an example that produces
the error you want get rid of.

with
> test.functional.t(res.em1,res.em2,mint,maxt,se.m=0,points=300)

I get

Error in seq(mint, maxt, length.out = points) : object 'mint' not found

obviously because I do not have any mint on my computer.

Quite surprising is that your "t" (which I recommend you to call
differently as t is function transpose In base R) ends as a list. At the
first glance I do not see any reason for t to be a list from your code.

Regards
Petr

>
> Hi Josh, Petr
>
> I checked that testStatistics is a function but it is not defined in the

> code anywhere else. But if I am able to remove it and give the input by
my
> own to the function which calls testStatistics, it might work.
>
> The hurdle here for me is that the input is a set* of values and each
> value has 2 attributes. Each variable is generated per iteration and has

> the numerator, denominator as its attributes and a value. But when I
read
> it in a loop,  i face two problems: 1. only the last i value is stored
and
> the rest are NULL. 2. the one stored does not contain the attribute
values.

>  Each value looks like this:
> >t
> [1] 3.897434
> attr(,"numerator")
> [1] 0.0002134457
> attr(,"denominator")
> [1] 5.47657e-05
>
> Eg:
> for (i in 1:5)
> {
> t<- test.functional.t(res.em1,res.em2,mint,maxt,se.m=0,points=300) ###
> function calling
> }
>
> >t
> [[1]]
> NULL
>
> [[2]]
> NULL
>
> [[3]]
> NULL
>
> [[4]]
> NULL
>
> [1] 3.897434
>
> Any suggestions. Thanks for all the help. :)
>
> Regards
> Aparna
>
>  
>
>

> On Tue, Feb 28, 2012 at 11:01 PM, Petr PIKAL <[hidden email]>
wrote:

> Hi
>
> Difficult to without knowing what objects you are operating your
> functions.
>
> I get
>
> > test.functional.t(1:10,1:10,3,4)
> Error in res.em1$eta : $ operator is invalid for atomic vectors
> > moderated.functional.t(1:10)
> Error in testStatistics["numerator", ] : incorrect number of dimensions
>
> And without suitable objects for those functions to operate it is
> impossible to come with reasonable suggestion.
>
> Anyway there is a function on your system which is called testStatistics
> and you can not subset functions, hence your error. I did not find this
> function in R pacages but I can not say that it is really not there.
>
> You can get rid of this function by
>
> rm(testStatistics)
>
> Regards
> Petr
>
>
> >
> > Kindly find below the code as it is executed:
> >
> > test.functional.t <-
> function(res.em1,res.em2,mint,maxt,se.m=0,points=300)
> > {
> >   at <- seq(mint,maxt,length.out=points)
> >   by <- at[2] - at[1]
> >
> >   mu1 <-
spline(x=res.em1$tau,y=res.em1$eta,xout=at,method="natural")$y

> > l2 <- functional.norm(mu1,mu2,by=by)
> >
> >   s1 <- mean(sapply(1:res.em1$n,
> >     function(i)
> >     {
> >       v <-
> > spline(x=res.em1$tau,y=res.em1$vi[[i]],xout=at,method="natural")$y
> >       functional.norm(v,by=by)^2
> >     }))
> > denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n) ### formula for
se

> >   returnValue <- l2 / (denominator + se.m)
> >
> >   attr(returnValue,"numerator") <- l2
> >   attr(returnValue,"denominator") <- denominator
> >
> >   returnValue
> > }
> >
> > moderated.functional.t <-
> > function(testStatistics,alpha.step=0.05,quantile.step=0.01)
> > {
> >   numerators <- unlist(testStatistics["numerator",])
> >   denominators <- unlist(testStatistics["denominator",])
> > }
> >
> > I get my error in the function above moderated.functional.t.
> testStatistics
> > is shown to be a function(x) when I type it in R console. But there is
> no
> > function definition for testStatistics in the code. My R understanding
> is
> > still elementary.
> >
> > Thanks
> > Aparna
> >
> >
> >
> >
> > On Tue, Feb 28, 2012 at 5:25 PM, Joshua Wiley
> <[hidden email]>wrote:
> >
> > > Hi Aparna,
> > >
> > > Can you please post a reproducible example?  It is difficult to
> > > provide much concrete help without having "testStatistics".  One
thing
> > > you might try is looking at:
> > >
> > > str(testStatistics["numerator",])
> > >
> > > is it actually a list?  If it is not (most likely given the error)
and

> > > it is supposed to be, you need to figure out what aspect of the
> > > generation of it is going awry.
> > >
> > > Cheers,
> > >
> > > Josh
> > >
> > > On Tue, Feb 28, 2012 at 12:23 AM, Aparna Sampath
> > > <[hidden email]> wrote:
> > > > Hi All
> > > >
> > > > I am trying to use the unlist() in R to a list variable.  The
> following
> > > > statements are within a function.
> > > > {
> > > > denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n)
> > > >  returnValue <- l2 / (denominator + 11)
> > > >  attr(returnValue,"numerator") <- l2
> > > >  attr(returnValue,"denominator") <- denominator
> > > >  returnValue
> > > > }
> > > >
> > > > And when I try to unlist the variable returnValue
> > > >
> > > >  numerators <- unlist(testStatistics["numerator",])
> > > >  denominators <- unlist(testStatistics["denominator",])
> > > >
> > > > I get the following error:
> > > >
> > > >>Error in testStatistics["numerator", ] :
> > > >  object of type 'closure' is not subsettable
> > > >
> > > > I read some threads in R help on this error and they had asked to
> check
> > > if
> > > > we are using the right datatype to the right function. But in my
> case it
> > > is
> > > > pretty straightforward since I just list it in one function and
try
> to
> > > > unlist it later. Any suggestions?
> > > > Thanks for the help :)
> > > >
> > > > --
> > > > View this message in context:
> > >
http://r.789695.n4.nabble.com/Error-message-object-of-type-closure-is-

> > not-subsettable-tp3752886p4427399.html
> > > > Sent from the R help mailing list archive at Nabble.com.
> > > >
> > > > ______________________________________________
> > > > [hidden email] mailing list
> > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > PLEASE do read the posting guide
> > > http://www.R-project.org/posting-guide.html
> > > > and provide commented, minimal, self-contained, reproducible code.
> > >
> > >
> > >
> > > --
> > > Joshua Wiley
> > > Ph.D. Student, Health Psychology
> > > Programmer Analyst II, Statistical Consulting Group
> > > University of California, Los Angeles
> > > https://joshuawiley.com/
> > >
> >
> >
> >
> > --
> > Aparna Sampath
> > Master of Science (Bioinformatics)
> > Nanyang Technological University
> > Mob no : +65 91601854
> >
> >    [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error message: object of type 'closure' is not subsettable

Aparna Sampath
Dear Petr

I am sorry about the code being incomplete. I also take note of not using R
keywords and functions as variable names. I was able to overcome my problem
using unlist(). Thanks.

Regards
Aparna

On Thu, Mar 1, 2012 at 3:57 PM, Petr PIKAL <[hidden email]> wrote:

> Hi
>
> If you want sensible response you need to ask sensible question and more
> importantly provide working example or at least an example that produces
> the error you want get rid of.
>
> with
> > test.functional.t(res.em1,res.em2,mint,maxt,se.m=0,points=300)
>
> I get
>
> Error in seq(mint, maxt, length.out = points) : object 'mint' not found
>
> obviously because I do not have any mint on my computer.
>
> Quite surprising is that your "t" (which I recommend you to call
> differently as t is function transpose In base R) ends as a list. At the
> first glance I do not see any reason for t to be a list from your code.
>
> Regards
> Petr
>
> >
> > Hi Josh, Petr
> >
> > I checked that testStatistics is a function but it is not defined in the
>
> > code anywhere else. But if I am able to remove it and give the input by
> my
> > own to the function which calls testStatistics, it might work.
> >
> > The hurdle here for me is that the input is a set* of values and each
> > value has 2 attributes. Each variable is generated per iteration and has
>
> > the numerator, denominator as its attributes and a value. But when I
> read
> > it in a loop,  i face two problems: 1. only the last i value is stored
> and
> > the rest are NULL. 2. the one stored does not contain the attribute
> values.
> >  Each value looks like this:
> > >t
> > [1] 3.897434
> > attr(,"numerator")
> > [1] 0.0002134457
> > attr(,"denominator")
> > [1] 5.47657e-05
> >
> > Eg:
> > for (i in 1:5)
> > {
> > t<- test.functional.t(res.em1,res.em2,mint,maxt,se.m=0,points=300) ###
> > function calling
> > }
> >
> > >t
> > [[1]]
> > NULL
> >
> > [[2]]
> > NULL
> >
> > [[3]]
> > NULL
> >
> > [[4]]
> > NULL
> >
> > [1] 3.897434
> >
> > Any suggestions. Thanks for all the help. :)
> >
> > Regards
> > Aparna
> >
> >
> >
> >
>
> > On Tue, Feb 28, 2012 at 11:01 PM, Petr PIKAL <[hidden email]>
> wrote:
> > Hi
> >
> > Difficult to without knowing what objects you are operating your
> > functions.
> >
> > I get
> >
> > > test.functional.t(1:10,1:10,3,4)
> > Error in res.em1$eta : $ operator is invalid for atomic vectors
> > > moderated.functional.t(1:10)
> > Error in testStatistics["numerator", ] : incorrect number of dimensions
> >
> > And without suitable objects for those functions to operate it is
> > impossible to come with reasonable suggestion.
> >
> > Anyway there is a function on your system which is called testStatistics
> > and you can not subset functions, hence your error. I did not find this
> > function in R pacages but I can not say that it is really not there.
> >
> > You can get rid of this function by
> >
> > rm(testStatistics)
> >
> > Regards
> > Petr
> >
> >
> > >
> > > Kindly find below the code as it is executed:
> > >
> > > test.functional.t <-
> > function(res.em1,res.em2,mint,maxt,se.m=0,points=300)
> > > {
> > >   at <- seq(mint,maxt,length.out=points)
> > >   by <- at[2] - at[1]
> > >
> > >   mu1 <-
> spline(x=res.em1$tau,y=res.em1$eta,xout=at,method="natural")$y
> > > l2 <- functional.norm(mu1,mu2,by=by)
> > >
> > >   s1 <- mean(sapply(1:res.em1$n,
> > >     function(i)
> > >     {
> > >       v <-
> > > spline(x=res.em1$tau,y=res.em1$vi[[i]],xout=at,method="natural")$y
> > >       functional.norm(v,by=by)^2
> > >     }))
> > > denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n) ### formula for
> se
> > >   returnValue <- l2 / (denominator + se.m)
> > >
> > >   attr(returnValue,"numerator") <- l2
> > >   attr(returnValue,"denominator") <- denominator
> > >
> > >   returnValue
> > > }
> > >
> > > moderated.functional.t <-
> > > function(testStatistics,alpha.step=0.05,quantile.step=0.01)
> > > {
> > >   numerators <- unlist(testStatistics["numerator",])
> > >   denominators <- unlist(testStatistics["denominator",])
> > > }
> > >
> > > I get my error in the function above moderated.functional.t.
> > testStatistics
> > > is shown to be a function(x) when I type it in R console. But there is
> > no
> > > function definition for testStatistics in the code. My R understanding
> > is
> > > still elementary.
> > >
> > > Thanks
> > > Aparna
> > >
> > >
> > >
> > >
> > > On Tue, Feb 28, 2012 at 5:25 PM, Joshua Wiley
> > <[hidden email]>wrote:
> > >
> > > > Hi Aparna,
> > > >
> > > > Can you please post a reproducible example?  It is difficult to
> > > > provide much concrete help without having "testStatistics".  One
> thing
> > > > you might try is looking at:
> > > >
> > > > str(testStatistics["numerator",])
> > > >
> > > > is it actually a list?  If it is not (most likely given the error)
> and
> > > > it is supposed to be, you need to figure out what aspect of the
> > > > generation of it is going awry.
> > > >
> > > > Cheers,
> > > >
> > > > Josh
> > > >
> > > > On Tue, Feb 28, 2012 at 12:23 AM, Aparna Sampath
> > > > <[hidden email]> wrote:
> > > > > Hi All
> > > > >
> > > > > I am trying to use the unlist() in R to a list variable.  The
> > following
> > > > > statements are within a function.
> > > > > {
> > > > > denominator <- sqrt(s1 / res.em1$n + s2 / res.em2$n)
> > > > >  returnValue <- l2 / (denominator + 11)
> > > > >  attr(returnValue,"numerator") <- l2
> > > > >  attr(returnValue,"denominator") <- denominator
> > > > >  returnValue
> > > > > }
> > > > >
> > > > > And when I try to unlist the variable returnValue
> > > > >
> > > > >  numerators <- unlist(testStatistics["numerator",])
> > > > >  denominators <- unlist(testStatistics["denominator",])
> > > > >
> > > > > I get the following error:
> > > > >
> > > > >>Error in testStatistics["numerator", ] :
> > > > >  object of type 'closure' is not subsettable
> > > > >
> > > > > I read some threads in R help on this error and they had asked to
> > check
> > > > if
> > > > > we are using the right datatype to the right function. But in my
> > case it
> > > > is
> > > > > pretty straightforward since I just list it in one function and
> try
> > to
> > > > > unlist it later. Any suggestions?
> > > > > Thanks for the help :)
> > > > >
> > > > > --
> > > > > View this message in context:
> > > >
> http://r.789695.n4.nabble.com/Error-message-object-of-type-closure-is-
> > > not-subsettable-tp3752886p4427399.html
> > > > > Sent from the R help mailing list archive at Nabble.com.
> > > > >
> > > > > ______________________________________________
> > > > > [hidden email] mailing list
> > > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > > PLEASE do read the posting guide
> > > > http://www.R-project.org/posting-guide.html
> > > > > and provide commented, minimal, self-contained, reproducible code.
> > > >
> > > >
> > > >
> > > > --
> > > > Joshua Wiley
> > > > Ph.D. Student, Health Psychology
> > > > Programmer Analyst II, Statistical Consulting Group
> > > > University of California, Los Angeles
> > > > https://joshuawiley.com/
> > > >
> > >
> > >
> > >
> > > --
> > > Aparna Sampath
> > > Master of Science (Bioinformatics)
> > > Nanyang Technological University
> > > Mob no : +65 91601854
> > >
> > >    [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > [hidden email] mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
>
> >
>
>


--
Aparna Sampath
Master of Science (Bioinformatics)
Nanyang Technological University
Mob no : +65 91601854

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...