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

Allow for NA values in the dependent variable throughout #147

Open
dwwolfson opened this issue Mar 15, 2022 · 8 comments
Open

Allow for NA values in the dependent variable throughout #147

dwwolfson opened this issue Mar 15, 2022 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@dwwolfson
Copy link

dwwolfson commented Mar 15, 2022

mcp Version 0.3.2
dplyr Version 1.0.8

When trying to plot a large fitted mcpfit object, I'm running into this error:
Error in dplyr::mutate():
! Problem while computing fitted = rlang::exec(...).
Caused by error in if (any(x < lower) || any(x > upper)) ...:
! missing value where TRUE/FALSE needed`

I also get the same error if calling fitted(model)

@dwwolfson dwwolfson changed the title error with plot() function problems extracting data from mcpfit object Mar 15, 2022
@lindeloev
Copy link
Owner

lindeloev commented Mar 16, 2022

Thanks for reporting. Can you post code that reproduces this error? And can you post the stack trace? (use traceback() if it isn't returned automatically)

@dwwolfson
Copy link
Author

The full traceback is pretty enormous. Here is the backtrace, hopefully that is helpful. I'll try to reproduce the error either by simulating data or posting data to a gist.


Backtrace:
x

  1. +-base::plot(f1)
  2. +-mcp:::plot.mcpfit(f1)
  3. | -mcp local_pp_eval("fitted")
  4. | +-... %>% dplyr::rename(!!yvar := !!type)
  5. | -mcp:::pp_eval(...)
  6. | -... %>% ...
  7. +-dplyr::rename(., :=(!!yvar, !!type))
  8. +-dplyr::mutate(...)
  9. +-dplyr:::mutate.data.frame(...)
  10. | -dplyr:::mutate_cols(.data, dplyr_quosures(...), caller_env = caller_env())
  11. | +-base::withCallingHandlers(...)
  12. | -mask$eval_all_mutate(quo)
  13. +-rlang::exec(...)
  14. +-mcp <fn>(...)
  15. | -mcp:::assert_numeric(per)
  16. -base::.handleSimpleError(...)
  17. -dplyr h(simpleError(msg, call))
  18. \-rlang::abort(...)
    

@dwwolfson
Copy link
Author

Here is the dataframe:
`> str(df)
track_xyt [200 x 8] (S3: track_xyt/track_xy/tbl_df/tbl/data.frame)
$ x_ : num [1:200] 23.7 26.7 13.3 28.5 96.8 ...
$ y_ : num [1:200] -9.06 -11.33 2.95 26.63 121.78 ...
$ t_ : Date[1:200], format: "2000-01-01" "2000-01-01" "2000-01-01" ...
$ nsd : num [1:200] 0 14.1 254.4 1296.6 22454.4 ...
$ speed : num [1:200] 0.001087 0.000437 0.002327 0.002607 0.002199 ...
$ time : num [1:200] 0.18 0.22 0.74 0.88 1.4 1.41 1.48 2 2.15 2.16 ...
$ per : num [1:200] NA -0.001071 0.000105 0.002324 0.002607 ...
$ turning: num [1:200] NA 0.0001808 -0.0004243 -0.0001208 0.0000503 ...

  • attr(*, "crs_")= chr NA`

And here is the mcp code:
m1<-list( per~1+ar(1), ~1+sigma(1)+ar(1), ~1+sigma(1)+ar(1), ~1+sigma(1)+ar(1), ~1+sigma(1)+ar(1) ) options(mc.cores=3) f1<-mcp(m1, data = df[,c("time", "per")], par_x = "time", adapt=20000, chains=4, cores=4, inits=list(cp_1=13, cp_2=19, cp_3=31, cp_4=47), prior=list(cp_1="dunif(5,15)", cp_2="dunif(15,25)", cp_3="dunif(25,35)", cp_4="dunif(45,55)") )

@dwwolfson
Copy link
Author

Not able to reproduce with the example data. Here is a gist for the csv:
https://gist.github.com/dwwolfson/3291e124879029b52fe1c7412b01b56a

@lindeloev lindeloev self-assigned this Mar 16, 2022
@lindeloev lindeloev added the bug Something isn't working label Mar 16, 2022
@lindeloev lindeloev changed the title problems extracting data from mcpfit object Allow for NA values in the dependent variable throughout Mar 16, 2022
@lindeloev
Copy link
Owner

Thanks! This is definitely a bug. The post-processing functions should allow for NA values in the dependent variable and they don't. As a temporary workaround, use a dataset without NA in per. E.g., removing these rows or imputing values.

@dwwolfson
Copy link
Author

Sounds good, thanks for your help!

@lindeloev lindeloev reopened this Mar 16, 2022
@lindeloev
Copy link
Owner

Reopening to remember to fix this bug in the next release.

@lindeloev
Copy link
Owner

BTW, just looking at your data, perhaps remove the ar() terms in segment 2+. This will fit a single ar() parameter that apply to all segments. No ar() is implicitly ar(N, 0) where N is the order of the previous segment and "0" means "no change in intercept of the autocorrelation coefficient".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants