[R-pkg-devel] import with except(ion)
Just a final observation: This can happen to anybody
-------------------------------------------------
> lm(weight ~ feed, data = chickwts)
Call:
lm(formula = weight ~ feed, data = chickwts)
Coefficients:
(Intercept) feedhorsebean feedlinseed feedmeatmeal
feedsoybean feedsunflower
323.583 -163.383 -104.833 -46.674
-77.155 5.333
> lm(weight ~ frailty(feed), data = chickwts)
Error in frailty(feed) : could not find function "frailty"
> library(survival)
> lm(weight ~ frailty(feed), data = chickwts)
Call:
lm(formula = weight ~ frailty(feed), data = chickwts)
Coefficients:
(Intercept) frailty(feed)
232.165 8.147
-------------------------------------------------------
G,
On 2020-11-02 11:15, G?ran Brostr?m wrote:
Thanks! G?ran On 2020-11-02 11:09, Sebastian Meyer wrote:
No need to reinvent the wheel. G?ran, you already use the "specials" feature of terms.formula to find strata():
specials: which functions in the formula should be marked as special in ?????????? the 'terms' object?? A character vector or 'NULL'.
I think you can do the same for frailty(), for example:
formula <- Surv(time, status) ~ age + frailty(inst)
Terms <- terms(formula, specials = "frailty")
frailties <- attr(Terms, "specials")$frailty
if (length(frailties)) warning("frailty() is not supported by coxreg")
Best regards, ????Sebastian Am 31.10.20 um 14:30 schrieb Gabor Grothendieck:
coxreg could search for frailty and issue a warning or error if
found.? This
returns TRUE if frailty is used in the formula argument as a function
but
not otherwise.? That would allow implementation of a nicer message than
if it were just reported as a missing function.
find_frailty <- function(e) {
???? if (is.logical(e)) return(e)
???? if (length(e) > 1) {
???????? if (identical(e[[1]], as.name("frailty"))) return(TRUE)
???????? for (i in 1:length(e)) if (isTRUE(Recall(e[[i]]))) return(TRUE)
???? }
???? FALSE
}
find_frailty(frailty ~ frailty)
## [1] FALSE
fo <- Surv(time, status) ~ age + frailty(inst)
find_frailty(fo)
## [1] TRUE
On Fri, Oct 30, 2020 at 2:46 PM G?ran Brostr?m
<goran.brostrom at umu.se> wrote:
My CRAN package eha depends on the survival package, and that creates problems with innocent users: It is about the 'frailty' function (mainly). While (after 'library(eha)') f1 <- coxph(Surv(time, status) ~ age + frailty(inst), data = lung) produces what you would expect (a frailty survival analysis), the use of the coxreg function from eha f2 <- coxreg(Surv(time, status) ~ age + frailty(inst), data = lung) produces (almost) nonsense. That's because the survival::frailty function essentially returns its input and coxreg is happy with that, treats it as an ordinary numeric (or factor) covariate, and nonsense is produced, but some users think otherwise. (Maybe it would be better to introduce frailty in a separate argument?) I want to prevent this to happen, but I do not understand how to do it in the best way. I tried to move survival from Depends: to Imports: and adding import(survival, except = c(frailty, cluster)) to NAMESPACE. This had the side effect that a user must qualify the Surv function by survival::Surv, not satisfactory (similarly for other popular functions in survival). Another option I thought of was to define my own Surv function as Surv <- survival::Surv in my package, but it doesn't feel right. It seems to work, though. As you may understand from this, I am not very familiar with these issues. I have used Depends: survival for a long time and been happy with that. Any help on this is highly appreciated. G?ran
______________________________________________ R-package-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
______________________________________________ R-package-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
______________________________________________ R-package-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel