compute_grad {cmpp} | R Documentation |
Compute the Numerical Gradient of the Log-Likelihood
Description
Calculates the gradient of the negative log-likelihood using finite differences.
The function uses a small step size (h
) defined during initialization.
Usage
compute_grad(param)
Arguments
param |
A numeric vector of parameters for which the gradient is calculated. |
Details
This function approximates the gradient using central finite differences.
Ensure that h
is appropriately set to avoid numerical instability.
Value
A numeric vector of the same length as param
, representing the gradient at the specified parameters.
Examples
library(cmpp)
data("fertility_data")
Nam <- names(fertility_data)
fertility_data$Education
datt <- make_Dummy(fertility_data, features = c("Education"))
datt <- datt$New_Data
datt['Primary_Secondary'] <- datt$`Education:2`
datt['Higher_Education'] <- datt$`Education:3`
datt$`Education:2` <- datt$`Education:3` <- NULL
datt2 <- make_Dummy(datt, features = 'Event')$New_Data
d1 <- datt2$`Event:2`
d2 <- datt2$`Event:3`
feat <- datt2[c('age', 'Primary_Secondary', 'Higher_Education')] |>
data.matrix()
timee <- datt2[['time']]
Initialize(feat, timee, d1, d2, 1e-10)
param <- c(0.5, 0.1, 0.6, 0.2)
compute_grad(param)
[Package cmpp version 0.0.2 Index]