MUIA DOMINIC MUTISO
MUIA DOMINIC MUTISO

Reputation: 1

How do I handle this error "Error in par[1] : object of type 'closure' is not subsettable"

I keep encountering error "Error in par[1] : object of type 'closure' is not subsettable" when I try integrating Aa. This happens after calling Aa(par,m)-code provided. I am trying to develop EM algorithm to obtain estimates of parameters but I cannot proceed with the above error. Any suggestions will be highly appreciated.

#The PDF of IPLE distribution
f<-function(alpha,beta,lambda,x){
      y=alpha*beta*lambda*(x)^(-beta-1)*exp((lambda/(x)^beta))*(exp((lambda/(x)^beta))-1)^(alpha-1)*     ((exp(lambda/(x)^beta)-1)^alpha +1)^(-2)
      return(y)
    }
#The CDF OF IPLE DISTRIBUTION
    F<-function(alpha,beta,lambda,x){
    y=1/((exp(lambda/(x)^beta)-1)^alpha +1)
    return(y)
    }
#GENERATING PROGRESSIVE TYPE II CENSORED SAMPLE
bl<-function(n,m,par){
alpha=par[[1]]
beta=par[[2]]
lambda=par[[3]]
  regw<-function(x,aalpha=alpha,bbeta=beta,llambda=lambda){
    q=llambda^(1/bbeta)*(log(((1/x)-1)^(1/aalpha)+1))^(-(1/bbeta))
    return(q)}
  w=runif(m)
  r=c()
  r[1]=rbinom(1,n-m,0.2)
  int=seq(2,m-1)
  s=r[1]
  for(i in int){
    r[i]=rbinom(1,n-m-s,0.2)
    s=s+r[i]}
  if(n-m-s>0)
    r[m]=n-m-s
  else
    r[m]=0
  p=c()
  x=c()
  v=c()
  u=c()
  y=c()
  p=r[m]
  for (i in 1:m){
    v[i]=w[i]^(1/(i+p))
    p=p+r[m-i]
  }
  x=v[m]
  for (i in 1:m){
    u[i]=1-x
    x=x*v[m-i]
    y[i]=regw(u[i],alpha,beta,lambda)
  }
  D=data.frame(y,r)
  return(D)
}

n<-40
m<-10
par<-c(0.5,0.45,0.2)
bl(n,m,par)

#INTERGRATION DEFINED
Aa<-function(par,m){
  alpha<-par[[1]]
  beta<-par[[2]]
  lambda<-par[[3]]
  y=c()
  c=c()
  for(j in 1:m){
    c[j]=1/(1-F(alpha,beta,lambda,frame$y[j]))
    g<-function(x){
      log(x)*f(alpha,beta,lambda,x)
    }
    y[j]=c[j]*integrate(g,lower =frame$y[j],upper=Inf)$value  
  }
  return(y)
}

Aa(par,m)

Upvotes: 0

Views: 45

Answers (0)

Related Questions