R:从“mle”类对象中提取参数estmates

时间:2016-06-20 01:13:11

标签: r s4

我想知道如何提取存储在类mle-class的R对象中的估计参数。

以下是一个例子:

x <- matrix(rnorm(300), ncol = 3)
x[x > 1] <- 1
require(tmvtnorm)
fit1 <- mle.tmvnorm(X = x, lower = rep(-Inf, 3), upper = rep(1, 3))

现在,fit1是类的对象:

class(fit1)
[1] "mle"
attr(,"package")
[1] "stats4

” fit1本身给了我:

fit1

Call:
mle(minuslogl = function (mu_1 = 0, mu_2 = 0, mu_3 = 0, sigma_1.1 = 1, 
    sigma_1.2 = 0, sigma_1.3 = 0, sigma_2.2 = 1, sigma_2.3 = 0, 
    sigma_3.3 = 1) 
{
    nf <- names(formals())
    theta <- sapply(nf, function(x) {
        eval(parse(text = x))
    })
    mean <- theta[1:n]
    if (cholesky) {
        L <- inv_vech(theta[-(1:n)])
        L[lower.tri(L, diag = FALSE)] <- 0
        sigma <- t(L) %*% L
    }
    else {
        sigma <- inv_vech(theta[-(1:n)])
    }
    if (det(sigma) <= 0 || any(diag(sigma) < 0)) {
        return(.Machine$integer.max)
    }
    f <- -(sum(dmvnorm(X, mean, sigma, log = TRUE)) - nrow(X) * 
        log(pmvnorm(lower = lower, upper = upper, mean = mean, 
            sigma = sigma)))
    if (is.infinite(f) || is.na(f)) {
        return(.Machine$integer.max)
    }
    f
}, start = as.list(c(0, 0, 0, 1, 0, 0, 1, 0, 1)), method = "BFGS", 
    fixed = list())

Coefficients:
       mu_1        mu_2        mu_3   sigma_1.1   sigma_1.2   sigma_1.3 
 0.64218198  1.51720543  0.97047201  1.73395947 -0.03889188  0.14627774 
  sigma_2.2   sigma_2.3   sigma_3.3 
 2.18020597  0.38822509  1.49854600 

我的问题是:如何从fit1对象中提取这些系数?

再次感谢您的时间,感谢您帮助回答这个问题!

2 个答案:

答案 0 :(得分:0)

对不起这个愚蠢的问题:我会保留它以防万一有人最终看。

fit1@coef
       mu_1        mu_2        mu_3   sigma_1.1   sigma_1.2   sigma_1.3 
 0.64218198  1.51720543  0.97047201  1.73395947 -0.03889188  0.14627774 
  sigma_2.2   sigma_2.3   sigma_3.3 
 2.18020597  0.38822509  1.49854600 

解决查询问题。杜!

答案 1 :(得分:0)

coef是一个泛型函数,它从建模函数返回的对象中提取模型coefficientscoefficients别名

<强>用法

coef(object, ...)
coefficients(object, ...)

所以,fit1@coef应该有用。

ruby on rails 2fa nexmo verify tutorial