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

Problem with [car::Boot()] in predict_curves() #50

Open
dario-ssm opened this issue Jul 30, 2024 · 5 comments
Open

Problem with [car::Boot()] in predict_curves() #50

dario-ssm opened this issue Jul 30, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@dario-ssm
Copy link
Collaborator

I've just carefully checked what happened to the function. This allowed to fix some problems in the previous functions due to missing dependencies, so the example runs way better (more than 8 models were succesfully fitted rather than previously three).

However, there is a problem with predict_curves() function. It must be some kind of issue with car::Boot(). By loading the package, no bootstrapps are succesfully accomplished. In contrast, if I manually load the car package in my current session with library(car), then it works fine.

I don't really know how to solve this, since this Boot function is difficult to deal with (e.g., not saving in your function environment but requiring parent environment data).

@dario-ssm dario-ssm added the bug Something isn't working label Jul 30, 2024
@dario-ssm dario-ssm self-assigned this Jul 30, 2024
@dario-ssm
Copy link
Collaborator Author

I have partially solved it by setting a require(car, silent = TRUE) within the function predict_curves() .

Until we get a better approach, this may solve the workflow problems.

@Pakillo
Copy link
Member

Pakillo commented Aug 12, 2024

Ok, but I think it should be requireNamespace instead.
Anyway, let's try to revise and refactor this function

@dario-ssm
Copy link
Collaborator Author

dario-ssm commented Sep 2, 2024

I have been testing this function and it does not work with requireNamespace() but does with require(). I still don't know what's happening with the car package.

About refactoring this function, it has four clear steps:

  1. Build predictions based on the model.
  2. Perform the bootstrap
  3. Extract the estimates of the bootstrap
  4. Calculate one predicted value for each temperature and bootstrapped estimate.

The bottleneck is the step 4, which is used to predict the curves that work as confidence intervals.
Anyway, we should find a way to refactor the function, I'm changing the label to enhance

@dario-ssm dario-ssm added enhancement New feature or request bug Something isn't working and removed bug Something isn't working enhancement New feature or request labels Sep 2, 2024
@dario-ssm
Copy link
Collaborator Author

dario-ssm commented Sep 4, 2024

Automated testing failed consistently with this function. I have solved it with the following workaround:

  1. Assign objects within the function to the global environment: as the car package authors suggest for some functions to work within other functions (see this documentation of the car package. Changing parent.frame() to .GlobEnv in the assign function solved the problem, as I misunderstood that parent.frame() would work similarly in testing environment.

  2. load and attach car package within the predict_curves() function: As warned incar::Boot() function documentation, using this function with residual resampling, i.e., car::Boot(x, n_samples, "residual") requires the user to previously run library(car) . Note that this requirement does not apply for the more common case resampling (typical boostrap); i.e., car::Boot(x, n_samples, "case"). However, and following indications of Daniel Padfield in this rTPC vignette, the experimental designs originating typical data for TPC fitting, as in our case, allow to perform bootstrap with residual resampling, leading to narrower variation when there is only one repetition for each independent variable value (i.e., temperature treatment). Consequently, I have carefully read the chapter 10 of R Packages book, and I tried requireNamespace() and loadNamespace("car") but none of them work. It seems that the car package must be attached, so the only option (following the recommendation to avoid require("car") is to manually run library(car) within the function. This solves the complete problem.

Refactoring the function is still a task to do.

@dario-ssm dario-ssm added enhancement New feature or request and removed bug Something isn't working labels Sep 4, 2024
@Pakillo
Copy link
Member

Pakillo commented Sep 4, 2024

Thanks Dario. I'll try to have a look

@Pakillo Pakillo self-assigned this Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants