I am working on a multiple linear regression problem where I would like to constrain only some of the parameters to non-negative values. There have been discussions of how to solve for the parameters posted on SE here and on another site. Both solutions used optim() or constrOptim() to minimize the residual sum of squares, which worked very well for me and gives the same values as lm() for the unconstrained version of the problem.
But I would like now to take this a step further and estimate standard errors of those parameters, similar to what I'd get if I used lm(). However, there is nothing in the optim() object that would suggest a route to estimating errors, and I haven't found anything in the control settings that would suggest a route either. So I'm a little bit at a loss as to how to proceed. My hunch is that this approach - an optimization problem that assumes the data values are fixed and the parameter solutions represent a global minimum - does not allow for error. Is there any validity to that, or am I just missing something basic?
This is a small reproducible example, adapted from the example provided in the first link to work with the optim() function, rather than constrOptim().
min.RSS <- function(data, par){
with(data, sum((par[1]*x1 + par[2]*x2 - y)^2))
}
dat = data.frame(x1=c(1,2), x2=c(2,3), y=c(5,6))
result = optim(par=c(0,1), min.RSS, data=dat, method="L-BFGS-B",
lower=c(-Inf,0), upper=c(0,Inf))
result$convergence
result$par