Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
Re-write log-likelihood.
  • Loading branch information
Jaimemosg committed May 27, 2023
1 parent 534a006 commit fcbc184
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions R/maxlogLreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -717,23 +717,43 @@ minus_lL_LinReg <- function(param, mat, distr, dist_args, over, link, npar,
}
}
}
cdf <- paste0('p', substring(distr, 2))
y <- mat$y
delta <- mat$status
cdf <- paste0('p', substring(distr, 2))

logf <- do.call( what = distr, args = c(list(x = y), param,
log = TRUE, fixed) )
logS <- do.call( what = cdf, args = c(list(q = y), param,
lower.tail = FALSE,
log.p = TRUE, fixed) )
logF <- do.call( what = cdf, args = c(list(q = y), param,
lower.tail = TRUE,
log.p = TRUE, fixed) )
ll <- -sum(
logf*delta[, 1] +
( if ( all(delta[, 2] > 0) ) logF*delta[, 2] else 0 ) +
( if ( all(delta[, 3] > 0) ) logS*delta[, 3] else 0 )
)

ll <- logf*delta[, 1]

if ( any(delta[, 2] > 0) ){
logF <- do.call(
what = cdf,
args = c(
list(q = y),
param,
lower.tail = TRUE,
log.p = TRUE,
fixed = fixed
)
)
ll <- ll + logF*delta[, 2]
}

if ( any(delta[, 3] > 0) ) {
logS <- do.call(
what = cdf,
args = c(
list(q = y),
param,
lower.tail = FALSE,
log.p = TRUE, fixed
)
)
ll <- ll + logS*delta[, 3]
}

ll <- -sum(ll)

if ( !is.null(ineqs) ){
# Non-linear constrain body
Expand All @@ -747,12 +767,11 @@ minus_lL_LinReg <- function(param, mat, distr, dist_args, over, link, npar,

eval_g_ineqs <- do.call(
what = "g_ineqs",

args = original_scale_param
)

if ( any(!eval_g_ineqs) ){
ll <- 1e10
ll <- ll + 1e10
}
}

Expand Down

0 comments on commit fcbc184

Please sign in to comment.