linfun function problem (unused arguments)

71 Views Asked by At

I'm trying to run this code, but I'm having some problem with the linfun function, and I don't know how to fix it.

The error is:

"Error in linfun(a = x.T, d = -sum(x.T * w)) : unused arguments (a = x.T, d = -sum(x.T * w))"

Does someone know how to correct it?

    for (l in 1:L) {
  x.new <- x[t==1990+l,]
  x.T <- (x.new-xbar)
  lb <- ub <- c()
  
  # define a linear objective fn
  obj <- linfun(a=x.T, d= -sum(x.T * w))
  # boot NEGATIVE support
  for (i in 1:100) {
    zeta    <- rnorm(n)
    gamma.b <- colMeans(gamma * zeta)
    
    # define quadratic constraint
    qcon <- quadcon(Q=Gram, a=-2*gamma.b-2*c(t(w)%*%Gram), 
                    d=2*sum(gamma.b*w)+sum(w*(Gram %*% w)), val=eta.l)
    # define optimization; min
    co <- cop(f=obj, max=F, lb=lbcon(rep(0,p)), 
              lc=lincon(A=t(rep(1, p)), val=sum(w), name="eq"), qc=qcon)
    result <- solvecop(co, solver="cccp", quiet=T)
    ub[i] <- -validate(co, result, quiet=T)$obj.fun
    
    # define optimization; max
    co <- cop(f=obj, max=T, lb=lbcon(rep(0,p)), 
              lc=lincon(A=t(rep(1, p)), val=sum(w), name="eq"), qc=qcon)
    result <- solvecop(co, solver="cccp", quiet=T)
    lb[i] <- -validate(co, result, quiet=T)$obj.fun
  }
  sc0[l]   <- sum(x.T * w.hat) + ybar
  sc0.l[l] <- sc0[l] + quantile(lb, alpha)
  sc0.u[l] <- sc0[l] + quantile(ub, 1-alpha)
  
  # Adjust error u.T
  # 3rd approach: conditional mean and variance
  u.T.mean <- sum(c(1, x.new[index]) * ufit$coeff)
  u.T.sig  <- sqrt(exp(sum(c(1,x.new[index])*u2fit$coeff)))
  sc0.ll.3[l] <- sc0.l[l] + u.T.mean + u.T.sig*quantile(res.st, alpha)
  sc0.uu.3[l] <- sc0.u[l] + u.T.mean + u.T.sig*quantile(res.st, 1-alpha)
  
  # 4th approach: quantile reg
  sc0.ll.4[l] <- sc0.l[l] + sum(qfit$coefficients[,1]*c(1, x.new[index]))
  sc0.uu.4[l] <- sc0.u[l] + sum(qfit$coefficients[,2]*c(1, x.new[index]))
}
1

There are 1 best solutions below

0
On

There are functions named linfun in the packages optiSolve and spatstat (I didn't know that until now!)

It appears that you wanted to use optiSolve::linfun but the system executed spatstat::linfun, which did not recognise the arguments a and d.

Presumably you loaded spatstat after loading optiSolve, so when the system looked for a function named linfun, it searched spatstat first.

You can avoid this by specifically calling optiSolve::linfun in your code, or by ensuring that optiSolve is loaded more recently than spatstat when you run the code.