Skip to content

Commit c47eb70

Browse files
Update R/compute_weighted_intensity_levels.R
Co-authored-by: Rasmus Skytte Randløv <[email protected]>
1 parent 9a02e08 commit c47eb70

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

R/compute_weighted_intensity_levels.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,13 @@ compute_weighted_intensity_levels <- function(
101101

102102
# The weighted negative loglikelihood function
103103
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)
111108
)
109+
110+
return(-sum(log_probability * weighted_observations$weight))
112111
}
113112

114113
# Run optimisation for weighted observations

0 commit comments

Comments
 (0)