Как рассчитать связки с условием - PullRequest
0 голосов
/ 24 февраля 2020

Я закодировал преобразование связок, но хочу создать условие. Это мой код:

b <- -0.33
c <- 0.29
m <- 3
n <-10000
sd <- 1
sigma <- matrix(c(1,a,b, #Covariance matrix 
                  a,1,c,
                  b,c,1),
                nrow=3)
z <- mvrnorm(n,mu=rep(0,m), Sigma = sigma, empirical = T)
u <- pnorm(z,mean = mean, sd = 1, lower.tail = TRUE, log.p = FALSE)

#from the values of the repartition function of variable t1s, I calculate the random 
#variable realizations of t1s
rdist_t1s <- as.data.frame(
  approx(y=repartition_t1s$time_start,x=repartition_t1s$probability_t1s,method="linear",xout=u[,1]))%>% 
  dplyr::rename(start_time=y,probability_T1s=x) 
#from the values of the repartition function of variable t2s, I calculate the random 
#variable realizations of t2s
rdist_t2s <- as.data.frame(
  approx(y=repartition_t2s$end_time,x=repartition_t2s$probability_t2s,method="linear",xout=u[,2]))%>% 
  dplyr::rename(end_time=y,probability_T2s=x) 

#from the values of the repartition function of variable ds, I calculate the random 
#variable realizations of d1
rdist_ds <- as.data.frame(
  approx(y=repartition_ds$distance,x=repartition_ds$probability_Ds,method="linear",xout=u[,3]))%>% 
  dplyr::rename(distance=y,probability_Ds=x) 

И это работает, потому что, когда я строю гистограмму start_time t1s и t2s и расстояния, я получаю то, что хочу, и корреляция сохраняется.

Проблема в том, что я хочу включить условие после выполнения преобразования, которое состоит в том, что t2s должно быть больше, чем t1s, корреляция, очевидно, меняется. Если я отфильтрую:

rdist <- as.data.frame(rdist) %>% dplyr::filter(V2>V1)

Кто-нибудь знает, как я могу это сделать?

Большое спасибо:)

...