Skip to content

Commit

Permalink
nobs import
Browse files Browse the repository at this point in the history
  • Loading branch information
helske committed Oct 21, 2024
1 parent ade058c commit 8183b6c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ importFrom(stats,coef)
importFrom(stats,complete.cases)
importFrom(stats,logLik)
importFrom(stats,model.matrix)
importFrom(stats,nobs)
importFrom(stats,predict)
importFrom(stats,qnorm)
importFrom(stats,quantile)
Expand Down
12 changes: 4 additions & 8 deletions R/bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ bootstrap_coefs.nhmm <- function(model, B = 1000,
if (method == "nonparametric") {
for (i in seq_len(B)) {
mod <- bootstrap_model(model)
fit <- fit_nhmm(mod, init, init_sd = 0, restarts = 0, threads = 1,
...)
fit <- fit_nhmm(mod, init, init_sd = 0, restarts = 0, threads = 1, ...)
fit$gammas <- permute_states(fit$gammas, gammas_mle)
gamma_pi[[i]] <- fit$gammas$pi
gamma_A[[i]] <- fit$gammas$A
Expand All @@ -119,8 +118,7 @@ bootstrap_coefs.nhmm <- function(model, B = 1000,
mod <- simulate_nhmm(
N, T_, M, S, formula_pi, formula_A, formula_B,
data = d, time, id, init)$model
fit <- fit_nhmm(mod, init, init_sd = 0, restarts = 0, threads = 1,
...)
fit <- fit_nhmm(mod, init, init_sd = 0, restarts = 0, threads = 1, ...)
fit$gammas <- permute_states(fit$gammas, gammas_mle)
gamma_pi[[i]] <- fit$gammas$pi
gamma_A[[i]] <- fit$gammas$A
Expand Down Expand Up @@ -154,8 +152,7 @@ bootstrap_coefs.mnhmm <- function(model, B = 1000,
if (method == "nonparametric") {
for (i in seq_len(B)) {
mod <- bootstrap_model(model)
fit <- fit_mnhmm(mod, init, init_sd = 0, restarts = 0, threads = 1,
...)
fit <- fit_mnhmm(mod, init, init_sd = 0, restarts = 0, threads = 1, ...)
fit <- permute_clusters(fit, pcp_mle)
for (j in seq_len(D)) {
out <- permute_states(
Expand Down Expand Up @@ -188,8 +185,7 @@ bootstrap_coefs.mnhmm <- function(model, B = 1000,
mod <- simulate_mnhmm(
N, T_, M, S, D, formula_pi, formula_A, formula_B, formula_omega,
data = d, time, id, init)$model
fit <- fit_mnhmm(mod, init, init_sd = 0, restarts = 0, threads = 1,
...)
fit <- fit_mnhmm(mod, init, init_sd = 0, restarts = 0, threads = 1, ...)
fit <- permute_clusters(fit, pcp_mle)
for (j in seq_len(D)) {
out <- permute_states(
Expand Down
20 changes: 16 additions & 4 deletions R/nobs.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
#'@export
#' Number of Observations in Hidden Markov Model
#'
#' Extract the number of non-missing observations of HMM. When computing nobs
#' for a multichannel model with $C$ channels, each observed value in a single
#' channel amounts to $1/C$ observation, i.e. a fully observed time point for
#' a single sequence amounts to one observation.
#' @param object An object of class `hmm`, `mhmm`, `nhmm`, or `mnhmm`.
#' @param ... Ignored.
#' @rdname nobs
#' @export
nobs.hmm <- function(object, ...) {
attr(object, "nobs")
}
#'@export
#' @rdname nobs
#' @export
nobs.mhmm <- function(object, ...) {
attr(object, "nobs")
}
#'@export
#' @rdname nobs
#' @export
nobs.nhmm <- function(object, ...) {
attr(object, "nobs")
}
#'@export
#' @rdname nobs
#' @export
nobs.mnhmm <- function(object, ...) {
attr(object, "nobs")
}
2 changes: 1 addition & 1 deletion R/seqHMM-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' @import nloptr
#' @import Rcpp
#' @importFrom Rcpp loadModule evalCpp
#' @importFrom stats logLik complete.cases model.matrix BIC rnorm runif vcov predict update coef qnorm quantile
#' @importFrom stats logLik complete.cases model.matrix BIC rnorm runif vcov predict update coef qnorm quantile nobs
#' @importFrom TraMineR alphabet seqstatf seqdef seqlegend
#' @importFrom graphics par plot.new
#' @importFrom methods hasArg
Expand Down
28 changes: 28 additions & 0 deletions man/nobs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8183b6c

Please sign in to comment.