Skip to content

FLMCI only calculates CI for first scalar covariate in the matrix (also, optnsListX is erronously set to optnsListY) #64

@Ulversl

Description

@Ulversl

For the case of scalar Y, and an X of 1 or more functional predictors with 2 or more scalar covariates, I have encountered some issues with FLMCI().
Below are my suggestions for corrections (that seem to have fixed the issues for my case).

Otherwise, keep up the great work!

Line 20: Wrong options are set for X.
Change
flm_est <- FLM(Y = Y, X = X, optnsListY = optnsListY, optnsListX = optnsListY)
to
flm_est <- FLM(Y = Y, X = X, optnsListY = optnsListY, optnsListX = optnsListX)

Line 127-131: Indices only extract first covariate from matrix.
Change

for (j in 1:p) {
      if (is.list(X_ind[[j]])) {
        X_ind[[j]]$Lt <- X[[j]]$Lt[ind]
        X_ind[[j]]$Ly <- X[[j]]$Ly[ind]
      }
      else {
        X_ind[[j]] <- X[[j]][ind]
      }

to

for (j in 1:p) {
      if (is.list(X_ind[[j]])) {
        X_ind[[j]]$Lt <- X[[j]]$Lt[ind]
        X_ind[[j]]$Ly <- X[[j]]$Ly[ind]
      }
      else {
        X_ind[[j]] <- X[[j]][ind, , drop = FALSE]
      }

Line 204-211: Output from bootstrap is vector, masking CIs from scalar covariates, except the first.
Change

else {
  ci_beta_df <- stats::quantile(sapply(1:R, function(b) betaMat[[b]]$beta[[j]]), 
                                c((1 - level)/2, 1 - (1 - level)/2))
  names(ci_beta_df) <- c("CI_lower", "CI_upper")
  ci_beta_df <- c(Est = flm_est$betaList[[j]], 
                  ci_beta_df)
  return(ci_beta_df)
}

to

else {
  beta_array <- simplify2array(lapply(1:R, function(b) betaMat[[b]]$beta[[j]]))
  
  if (is.vector(beta_array)) {
    beta_array <- matrix(beta_array, nrow = 1)
  }

  ci_beta_df <- data.frame(
    Est = flm_est$betaList[[j]],
    CI_lower = apply(beta_array, 1, function(x) quantile(x, (1 - level) / 2)),
    CI_upper = apply(beta_array, 1, function(x) quantile(x, 1 - (1 - level) / 2))
  )
  
  return(ci_beta_df)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions