[R] Help with a simple subroutine
Steven T. Yen
@tyen @end|ng |rom ntu@edu@tw
Fri Sep 9 10:46:00 CEST 2022
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
More information about the R-help
mailing list