[R] Help with a simple subroutine

Andrew Simmons @kw@|mmo @end|ng |rom gm@||@com
Fri Sep 9 10:57:50 CEST 2022


I think you must've written your formula incorrectly. t can be simplified
like this:

t
gamma/sgamma
gamma/sqrt(vgamma)
gamma/sqrt(gamma^2 * v[2, 2])
gamma/sqrt(gamma^2)/sqrt(v[2, 2])
gamma/gamma              /sqrt(v[2, 2])
rep(1, length(gamma))   /sqrt(v[2, 2])

so I'm not surprised that both values of t are equal.

On Fri., Sep. 9, 2022, 04:46 Steven T. Yen, <styen using ntu.edu.tw> wrote:

> Can someone help me with this simple replicable subroutine?
> I am expecting the line  t<-gamma/sgamma to produce two different
> values. But I confirm that it is doing
> tt<-gamma[1]/sgamma[1]
> Thanks.
>
>  > b<-v$est[j]; b
> log.gamma1 log.gamma2
>    -1.82378   -1.11313
>  > v<-v$stat$vb[j,j]; v
>             log.gamma1 log.gamma2
> log.gamma1  0.0842252  0.0138778
> log.gamma2  0.0138778  0.0793592
>  > delta <- function(b,v){
> + # ***********************************************
> + # Delta method for exponential transformation
> + # ***********************************************
> +   df<-5140; #df<-nrow(mydata)
> +   gamma<-exp(b)
> +   vgamma<-gamma^2*v[2,2]
> +   sgamma<-sqrt(vgamma)
> +   t<-gamma/sgamma
> +   tt<-gamma[1]/sgamma[1]
> +   p<-2*(1-pt(abs(t),df))
> + list(gamma=gamma,sgamma=sgamma,b=b,t=t,p=p,tt=tt)
> + }
>  > options(digits=6)
>  > delta(b,v)$b
> log.gamma1 log.gamma2
>    -1.82378   -1.11313
>  > delta(b,v)$gamma
> log.gamma1 log.gamma2
>    0.161414   0.328529
>  > delta(b,v)$sgamma
> log.gamma1 log.gamma2
>   0.0454716  0.0925490
>  > delta(b,v)$t
> log.gamma1 log.gamma2
>     3.54978    3.54978
>  > delta(b,v)$tt
> log.gamma1
>     3.54978
>  > delta(b,v)$p
>   log.gamma1  log.gamma2
> 0.000389002 0.000389002
>
> ______________________________________________
> R-help using 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list