[R] instrumental variable as distance
tamergomah
tamer_gomah at hotmail.com
Wed Mar 16 15:29:47 CET 2011
Dear R-help ,
Here I try to explain the problem setting
problem setting:
we have four variables
y: outcome
x:exposure
u:confounder
z:Instrumental Variable
##we have instrumental variable as distance between centers and patients
place, we have many
##centers for exp:three centers c1,c1,c3 and of course n patients.
we aim to find out what would happen if a well defined group of patients
were treated by provider c1 or c2 rather than
provider B.
##Instrumental Variable: distance centers and patients
##i:number of patients
##If we have 3 centers c1,c2,c3
##d1:distance between center c1 and patient (i)
##d2:distance between center c2 and patient (i)
##d3:distance between center c3 and patient (i)
##To generate distance d1,d2,d3 and choice nearest center
n<-10
wcoord<-runif(n, min=0, max=1)
hcoord<-runif(n, min=0, max=1)
## (w1,h1),(w2,h2),(w3,h3) position of the 3 centers
w1<-0.9
h1<-0.3
w2<-0.2
h2<-0.6
w3<-0.7
h3<-0.1
d1<-sqrt((wcoord-w1)^2 +(hcoord-h1)^2)
d2<-sqrt((wcoord-w2)^2 +(hcoord-h2)^2)
d3<-sqrt((wcoord-w3)^2 +(hcoord-h3)^2)
##m:nearest center to patient
m<-pmin(d1,d2,d3)
z<-cbind(d1,d2,d3,m)
d1 d2 d3 m
[1,] 0.87142373 0.2750814 0.89725053 0.27508142
[2,] 0.64285521 0.5237454 0.78950397 0.52374540
[3,] 0.06799528 0.7101305 0.30996833 0.06799528
[4,] 0.41636986 0.7966441 0.67216852 0.41636986
[5,] 0.29930080 0.7204538 0.02085061 0.02085061
###Instrumental Variable as relative distance
R1
R2
R3
R1<-(d1/sum(m))
R2<-(d2/sum(m))
R3<-(d3/sum(m))
z<-cbind(d1,d2,d3,m,R1,R2,R3)
z
d1 d2 d3 m R1 R2
[1,] 0.47371700 0.4791628 0.2733683 0.27336832 0.17374723 0.17574461
[2,] 0.04784215 0.7305729 0.2384407 0.04784215 0.01754727 0.26795537
[3,] 0.06238730 0.8167800 0.2820744 0.06238730 0.02288206 0.29957393
R3
[1,] 0.10026448
[2,] 0.08745394
[3,] 0.10345767
##generate confounders as :
u<-rnorm(n,0,1)
C:center choice
I think we can use multinomial model as rmultinom(n, size, prob).
I want to generate the data like that
i d1 d2 d3 m R1 R2 R3 P1 P2 P3 C U Y1 Y2 Y3 Yi
any one have text or notes about that?
Yours Sincerely,
Tamer
--
View this message in context: http://r.789695.n4.nabble.com/instrumental-variable-as-distance-tp3381900p3381900.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list