[R] g parameter for deltaMethod() as a function
Fox, John
jfox at mcmaster.ca
Mon Jan 30 19:04:38 CET 2017
Dear Marc,
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Marc
> Girondot via R-help
> Sent: Monday, January 30, 2017 12:19 PM
> To: R-help Mailing List <r-help at r-project.org>
> Subject: [R] g parameter for deltaMethod() as a function
>
> Hi everyone,
>
> I try to use the Default S3 method DeltaMethod() from car package, but I
> have some problems when I try to use a function as the "g" parameter. I
> don't know if it is possible anyway. I hope that you could tell me:
I don't see how that would work. From ?deltaMethod: "g [the second argument]: A quoted string that is the function of the parameter estimates to be evaluated; see the details below."
A possible solution would be to write a wrapper function that prepares a proper call to deltaMethod().
I hope this helps,
John
--------------------------------------
John Fox, Professor
McMaster University
Hamilton, Ontario, Canada
Web: socserv.mcmaster.ca/jfox
>
> Here an example from the help of deltaMethod(). It works and I
> understand well (I think at least !).
>
> library(car)
> m1 <- lm(time ~ t1 + t2, data = Transact) deltaMethod(coef(m1), "t1/t2",
> vcov.=vcov(m1))
>
> ###############
>
> I would like do the same with a function instead of "t1/t2":
>
> try_g <- function(...) {
> par <- list(...)
> return(par$t1/par$t2)
> }
>
> try_g(t1=1, t2=2)
> deltaMethod(coef(m1), "try_g", vcov.=vcov(m1))
>
> But I get an error:
>
> Error in as.data.frame.default(x[[i]], optional = TRUE) :
> cannot coerce class ""function"" to a data.frame
>
> If someone could give me the solution... or tell me if it is impossible
> !
>
> Thanks
>
> Marc
>
> PS. In fine I would like using deltaMethod() to produce a confidence
> interval after fitting a model using ML with optim.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list