我想使用optim函数估计三个参数,但出现了无法在初始参数上求值的错误
library(stats)attach(ambiguity)richard = function(P, A, V, theta){1/(1+exp((5^theta[2]-(P-theta[1]*A/2)*V^theta[2])/theta[3]))}loss=function(P, A, V, Pr, theta){sum(Pr-richard(P, A, V, theta))}theta0 <- c(1000, -3, 3)theta.L <- optim(theta0, loss, P=risk, A=ambiguous, V=value, Pr= choice)