Closed RobinDenz1 closed 2 years ago
You have been caught by the aggressive weirdness of formulas; the coxph function is just an innocent bystander. (You will find exactly the same behavior if you replace coxph by lm in your examples above.)
You are expecting that when you call coxph inside the function, that the variables in the formula will be found first in the data= argument, then in the set of nested evaluation frames (local function, parent of function, parent of parent, ........ base). That's what any sensible person would expect from a functional language. But 1. formulas fix their worldview at the moment they are created and 2. the model.frame() function treats formulas special: it looks first in the data frame, then in the formula's universe, and No Where Else. Since all modeling functions call model.frame() under the covers, you are hosed: in the formula's world, nothing that was not present at it's own creation even exists.
It reminds me of lines from The Big Chill.
Michael : Harold, don't you have any other music , you know, from this century?
Harold : There is no other music, not in my house.
Believe me, I have tried
Thank you very much for the detailed explanation. I am sorry to have bothered you with this since it has nothing to do with your R-Package. It is always very interesting to learn some specific details like this. Thanks!
Dear @therneau,
First of all, thank you very much for all of the work you did on survival analysis and especially for this package.
While conducting a simulation study, I have encountered a bug which I sadly can't seem to fix myself. The problem is as follows: Whenever I pass both weights and a formula to the coxph function inside of another function, I get an error message. I have written a few examples for this.
When I call the coxph function normally, it works fine:
Doing everything inside of a function works fine as well:
However passing both the formula and the weights does not work (resulting in the error message: Error in eval(extras, data, env) : Object 'ps_weights' not found):
Passing only the formula and estimating the weights within the function does not work either (also resulting in the error message: Error in eval(extras, data, env) : Object 'ps_weights' not found):
I am not sure what exactly is going on here. The obvious solution would be to not do it inside a function, but this is sadly not an option for me as I need to use parallel processing to make my study feasible computationally (I am using different formulas and weights in each simulation run).
Here is the output from a call to
sessionInfo()
:Thank you very much for your help.
With kind regards, Robin