Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R参数化事件的解算_R - Fatal编程技术网

R参数化事件的解算

R参数化事件的解算,r,R,我正在用deSolve软件包为R编写一个SIR模型 该模型描述了感染在社区内的传播,然后允许引入外部事件,这代表了整个社区的大规模治疗 这些被建模为在特定时间发生的事件 对于传输模型本身,我已经能够对其进行编码,以便模型使用基线总体大小和参数的一系列值(plist和initlist)运行大量模拟 我希望能够对外部事件(总体社区治疗)参数进行同样的处理 目前,外部事件对易感人群的影响为: 请测试我的溶液。 我认为它有效 #### Clear currrent lists from memo

我正在用deSolve软件包为R编写一个SIR模型

该模型描述了感染在社区内的传播,然后允许引入外部事件,这代表了整个社区的大规模治疗

这些被建模为在特定时间发生的事件

对于传输模型本身,我已经能够对其进行编码,以便模型使用基线总体大小和参数的一系列值(plist和initlist)运行大量模拟

我希望能够对外部事件(总体社区治疗)参数进行同样的处理

目前,外部事件对易感人群的影响为: 请测试我的溶液。 我认为它有效

    #### Clear currrent lists from memory
    rm(list=ls())
    library(deSolve)

    #generate an empty list for the data to be put into

    simulationlist <- list()

    #define the transmission model

    SI1I2L <- function(t, y, parameters) {
      with(as.list(c(parameters,y)),{
        dS <- - Beta*S*I1 - Beta*S*I2 + treat*I1 + treat*I2 +latenttreat*L
        dI1 <- + Beta*S*I1 + Beta*S*I2 - treat*I1 -second*I1 - latent*I1
                dI2 <- + second*I1 - latent*I2 - treat*I2 + relapse*L
        dL <- +latent*I1 + latent*I2 - relapse*L - latenttreat*L

        der <- c(dS, dI1,dI2, dL)
        list(der)    
      }) 

    } 
    n=10;
    #define Total Community Treatment Parameters
    TCTlist = runif(n,min = 0.88, max = 0.99);
    #eventtct <- function(t, y, parms){
    eventtct <- function(t,y,parameters){
      with (as.list(y,parameters),{
    #    eval(TCT=parameters[7])
        S <- S + TCT*L + TCT*I1 + TCT*I2
        I1 <- I1*(1-TCT)
        I2 <- I2*(1-TCT)
        L <- L*(1-TCT)
        return(c(S,I1,I2,L))
      })
    }

    #Set the time frame for the model
    dt    <- seq(0,100,1)    




    #Define the spectrum of Parameters for transmission with Min/Max values and number of     variations
    plist <- cbind(Beta = runif(n,min = 0.00000167, max = 0.0000043),second = runif(n,min= 0.0278,max = 0.0556),latent = runif(n,min=0.004, max=0.009), treat = runif(n, min=0.01, max =0.03),latenttreat = runif(n,min=0.004,max=0.009),relapse = runif(n,min=0.012,max=0.028))
    for (i in 1:n)
      #Define the spectrum of inital values for population size

      initlist <- cbind(S = runif(n,min = 110681, max = 118636),I1 = runif(n,min=798, max=2926),I2 = runif(n,min=266,max=1463),L=runif(n,min=13300, max=27930))


    for (i in 1:n){
        #run multiple simulations  
      parameters = c(plist[i,],TCT=TCTlist[i]);
      eventsfunction = list(eventtct, time = c(2,12) );
      simulationlist[[i]] <- as.data.frame(ode(initlist[i,], time=dt, func=SI1I2L,         parms=parameters,events =eventsfunction )) 
    }
#####从内存中清除当前列表
rm(list=ls())
图书馆(deSolve)
#为要放入的数据生成空列表

simulationlist最相关的更改出现在“eventtct”代码的这一部分,其中在as.list()中,在“y”之后添加了“parameters”。
library(deSolve)

#generate an empty list for the data to be put into

simulationlist <- list()

#define the transmission model

SI1I2L <- function(t, y, parms) {

  with(as.list(c(parms,y)),{
    dS <- - Beta*S*I1 - Beta*S*I2 + treat*I1 + treat*I2 +latenttreat*L
    dI1 <- + Beta*S*I1 + Beta*S*I2 - treat*I1 -second*I1 - latent*I1
    dI2 <- + second*I1 - latent*I2 - treat*I2 + relapse*L
    dL <- +latent*I1 + latent*I2 - relapse*L - latenttreat*L

    der <- c(dS, dI1,dI2, dL)
    list(der)    
  }) 

} 

#define Total Community Treatment Parameters

eventtct <- function(t, y, parms){
  with (as.list(y),{
    S <- S + 0.95*L + 0.95*I1 + 0.95*I2
    I1 <- I1*0.05
    I2 <- I2*0.05
    L <- L*0.05
    return(c(S,I1,I2,L))
  })
}

#Set the time frame for the model
dt    <- seq(0,100,1)    

#Define the spectrum of Parameters for transmission with Min/Max values and number of variations
plist <- cbind(Beta = runif(100,min = 0.00000167, max = 0.0000043),second = runif(100,min= 0.0278,max = 0.0556),latent = runif(100,min=0.004, max=0.009), treat = runif(100, min=0.01, max =0.03),latenttreat = runif(100,min=0.004,max=0.009),relapse = runif(100,min=0.012,max=0.028))
for (i in 1:nrow(plist))
#Define the spectrum of inital values for population size

initlist <- cbind(S = runif(100,min = 110681, max = 118636),I1 = runif(100,min=798, max=2926),I2 = runif(100,min=266,max=1463),L=runif(100,min=13300, max=27930))
for (i in 1:nrow(initlist))

#run multiple simulations  
simulationlist[[i]] <- as.data.frame(lsoda(initlist[i,], dt, SI1I2L, parms=plist[i,],events = list(func = eventtct, time = c(2,12) ))) 
    #### Clear currrent lists from memory
    rm(list=ls())
    library(deSolve)

    #generate an empty list for the data to be put into

    simulationlist <- list()

    #define the transmission model

    SI1I2L <- function(t, y, parameters) {
      with(as.list(c(parameters,y)),{
        dS <- - Beta*S*I1 - Beta*S*I2 + treat*I1 + treat*I2 +latenttreat*L
        dI1 <- + Beta*S*I1 + Beta*S*I2 - treat*I1 -second*I1 - latent*I1
                dI2 <- + second*I1 - latent*I2 - treat*I2 + relapse*L
        dL <- +latent*I1 + latent*I2 - relapse*L - latenttreat*L

        der <- c(dS, dI1,dI2, dL)
        list(der)    
      }) 

    } 
    n=10;
    #define Total Community Treatment Parameters
    TCTlist = runif(n,min = 0.88, max = 0.99);
    #eventtct <- function(t, y, parms){
    eventtct <- function(t,y,parameters){
      with (as.list(y,parameters),{
    #    eval(TCT=parameters[7])
        S <- S + TCT*L + TCT*I1 + TCT*I2
        I1 <- I1*(1-TCT)
        I2 <- I2*(1-TCT)
        L <- L*(1-TCT)
        return(c(S,I1,I2,L))
      })
    }

    #Set the time frame for the model
    dt    <- seq(0,100,1)    




    #Define the spectrum of Parameters for transmission with Min/Max values and number of     variations
    plist <- cbind(Beta = runif(n,min = 0.00000167, max = 0.0000043),second = runif(n,min= 0.0278,max = 0.0556),latent = runif(n,min=0.004, max=0.009), treat = runif(n, min=0.01, max =0.03),latenttreat = runif(n,min=0.004,max=0.009),relapse = runif(n,min=0.012,max=0.028))
    for (i in 1:n)
      #Define the spectrum of inital values for population size

      initlist <- cbind(S = runif(n,min = 110681, max = 118636),I1 = runif(n,min=798, max=2926),I2 = runif(n,min=266,max=1463),L=runif(n,min=13300, max=27930))


    for (i in 1:n){
        #run multiple simulations  
      parameters = c(plist[i,],TCT=TCTlist[i]);
      eventsfunction = list(eventtct, time = c(2,12) );
      simulationlist[[i]] <- as.data.frame(ode(initlist[i,], time=dt, func=SI1I2L,         parms=parameters,events =eventsfunction )) 
    }