@@ -101,14 +101,13 @@ compute_weighted_intensity_levels <- function(
101
101
102
102
# The weighted negative loglikelihood function
103
103
nll <- function (par , weighted_observations , family = family ) {
104
- switch (family ,
105
- weibull = - sum(stats :: dweibull(weighted_observations $ observation , shape = exp(par [1 ]), scale = exp(par [2 ]),
106
- log = TRUE ) * weighted_observations $ weight ),
107
- lnorm = - sum(stats :: dlnorm(weighted_observations $ observation , meanlog = par [1 ], sdlog = par [2 ],
108
- log = TRUE ) * weighted_observations $ weight ),
109
- exp = - sum(stats :: dexp(weighted_observations $ observation , rate = exp(par [1 ]),
110
- log = TRUE ) * weighted_observations $ weight )
104
+ log_probability <- switch (family ,
105
+ weibull = stats :: dweibull(weighted_observations $ observation , shape = exp(par [1 ]), scale = exp(par [2 ]), log = TRUE ),
106
+ lnorm = stats :: dlnorm(weighted_observations $ observation , meanlog = par [1 ], sdlog = par [2 ], log = TRUE ),
107
+ exp = stats :: dexp(weighted_observations $ observation , rate = exp(par [1 ]), log = TRUE )
111
108
)
109
+
110
+ return (- sum(log_probability * weighted_observations $ weight ))
112
111
}
113
112
114
113
# Run optimisation for weighted observations
0 commit comments