Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ellipsis to FUNouter #1226

Merged

Conversation

reikookamoto
Copy link
Contributor

@reikookamoto reikookamoto commented Oct 4, 2024

This is a follow-up to #1224

Part 1: Resolving the error message

This is the full traceback that I get when calling hypotheses(m, "b1 = b2"), as shown in the minimum reproducible example in the original issue.

9. do.call("FUN", args) at get_se_delta.R#102
8. func(x) at get_jacobian.R#29
7. (function (func, x, eps = NULL)
   {
   baseline <- func(x)
   inner_loop <- function(chunk, ...) { ...
   }
6. do.call(get_jacobian_fdforward, numderiv) at get_jacobian.R#11
5. get_jacobian(func = function (x)
   {
   names(x) <- names(coefs)
   model_tmp <- set_coef(model, x, ...) ...
   }
4. do.call("get_jacobian", args) at get_se_delta.R#112
3. get_se_delta(model = structure(list(obj = list(par = c(beta = 1, beta = 1, beta = 1, beta = 1, betadisp = 0, theta = 0), fn = function (x = last.par[lfixed()],
   ...
   }
2. do.call("get_se_delta", args) at hypotheses.R#344
1. hypotheses(m, "b1 = b2")
  • My understanding:
    • At 8, the function func() refers to inner() defined in get_delta_se.R
    • func() adds an element called newparams to the argument list args
    • At 9, "FUN" refers to FUNouter() defined in hypotheses.R
    • FUNouter() only expects the arguments model and hypothesis, but the additional newparams argument is passed, leading to the error
  • Possible resolution:
    • To fix this, I updated the definition of FUNouter() by adding an ... to allow for additional arguments
    • After making this change, I ran devtools::check() and it passed with no errors, warnings, or notes

Part 2: Standard error returned is NA

When I call hypotheses(m, "b1 = b2") after updating FUNouter(), I get the following output:

Estimate Std. Error  z Pr(>|z|)  S  2.5 %  97.5 %
    0.634         NA NA       NA NA    NA     NA

The returned data frame gives a sensible estimate, but the remaining columns are all NA.

  • My understanding:
    • "J" matrix returned on line 112 of get_se_delta.R is a matrix where all entries are 0
    • The se calculated on line 136 is also 0, which gets overwritten by NA_real_ in the following line
    • Consequently, the computation of the z-statistic, p-value, and confidence interval in get_ci() all return NA
  • Hypothesis (no pun intended):
    • Could this be related to precision and floating-point arithmetic issues (i.e., subtractions involving very small differences) happening in the inner_loop() function defined in get_jacobian_fdforward() within get_jacobian.R?

This is pushing my limited knowledge of matrices and the delta method, so I'm not sure if the NA values are expected behaviour or if they indicate a deeper issue.

Thanks for your help!

@vincentarelbundock vincentarelbundock merged commit 6061942 into vincentarelbundock:main Oct 4, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants