Skip to contents

[Maturing]

coef.maxlogL is the specific method for the generic function coef which extracts model coefficients from objects returned by maxlogLreg. coefficients is an alias for coef.

Usage

# S3 method for maxlogL
coef(object, parameter = object$outputs$par_names, ...)

coefMany(object, parameter = NULL, ...)

Arguments

object

an object of maxlogL class generated by maxlogLreg function.

parameter

a character which specifies the parameter is required. In coefMany this argument can be an atomic vector with two or more names of parameters.

...

other arguments.

Value

A named vector with coefficients of the specified distribution parameter.

Author

Jaime Mosquera Gutiérrez, jmosquerag@unal.edu.co

Examples

library(EstimationTools)

#--------------------------------------------------------------------------------
# Example 1: coefficients from a model using a simulated normal distribution
n <- 1000
x <- runif(n = n, -5, 6)
y <- rnorm(n = n, mean = -2 + 3 * x, sd = exp(1 + 0.3* x))
norm_data <- data.frame(y = y, x = x)

# It does not matter the order of distribution parameters
formulas <- list(sd.fo = ~ x, mean.fo = ~ x)

norm_mod <- maxlogLreg(formulas, y_dist = y ~ dnorm, data = norm_data,
                       link = list(over = "sd", fun = "log_link"))
coef(norm_mod)
#> (Intercept)           x 
#>   -1.988339    3.016877 
coef(norm_mod, parameter = 'sd')
#> (Intercept)           x 
#>   0.9915188   0.2980795 
a <- coefMany(norm_mod, parameter = c('mean', 'sd'))
b <- coefMany(norm_mod)
identical(a, b)
#> [1] TRUE


#--------------------------------------------------------------------------------
# Example 2: Parameters in estimation with one fixed parameter
x <- rnorm(n = 10000, mean = 160, sd = 6)
theta_1 <- maxlogL(x = x, dist = 'dnorm', control = list(trace = 1),
                 link = list(over = "sd", fun = "log_link"),
                 fixed = list(mean = 160))
#>   0:     43196.673:  1.00000
#>   1:     32438.418:  2.00000
#>   2:     32192.032:  1.91567
#>   3:     32044.437:  1.75247
#>   4:     32034.170:  1.78879
#>   5:     32033.983:  1.78460
#>   6:     32033.983:  1.78446
#>   7:     32033.983:  1.78446
coef(theta_1)
#>       sd 
#> 5.956361 


#--------------------------------------------------------------------------------