```
set.seed(100)
n = 2000
x = rnorm(n, 0, 2)
loglike = function(x, par) -sum(log(dnorm(x,par[1],par[2])))
fit1 = optim(par=c(mean(x), sd(x)), loglike, x=x , hessian = TRUE)
fit1
$par
[1] 0.02095186 2.01174852
$value
[1] 4235.386
$counts
function gradient
35 NA
$convergence
[1] 0
$message
NULL
$hessian
[,1] [,2]
[1,] 494.1771 0.0000
[2,] 0.0000 987.6151
fit2 = optimizing(mystanmodel, hessian = TRUE, data=list(n=n, x=x), init = list(mu = mean(x), sigma = sd(x)))
Initial log joint probability = -2397.51
Optimization terminated normally:
Convergence detected: relative gradient magnitude is below tolerance
fit2
$par
mu sigma
0.02095186 2.01124552
$value
[1] -2397.508
$return_code
[1] 0
$hessian
mu sigma
mu -4.944243e+02 2.247603e-11
sigma 2.247603e-11 -4.000003e+03
```

I’m not a Stan developer. I don’t see very much difference in parameter estimate in mean and sd of fit1 and fit2, the hessian estimate differs in sigma/sigma. Is it that optimization is calculated at the **unconstrained** parameter space?

See: " hessian: ‘TRUE’ or ‘FALSE’ (the default): flag indicating whether to

calculate the Hessian (via numeric differentiation of the

gradient function in the unconstrained parameter space)."