[過去ログ]
臨床統計もおもしろいですよ、その2 (1002レス)
臨床統計もおもしろいですよ、その2 http://egg.5ch.net/test/read.cgi/hosp/1540905566/
上
下
前
次
1-
新
通常表示
512バイト分割
レス栞
このスレッドは過去ログ倉庫に格納されています。
次スレ検索
歴削→次スレ
栞削→次スレ
過去ログメニュー
885: 卵の名無しさん [sage] 2020/01/30(木) 23:51:43 ID:m/EdOA9B #Reed-Frost Model ReedFrost=function( p=0.04, N=100, T=40) { q=1-p I=numeric(T) S=numeric(T) I[1]=1 S[1]=N-I[1] for(t in 1:(T-1)){ I[t+1]=S[t]*(1-q^I[t]) S[t+1]=S[t]-I[t+1] } plot(1:T,I,type="l",lwd=2, ylim=c(0,N),xlab="time",ylab="persons",main=paste("Reed-Frost Model p= ",p)) lines(S,lty=2,col=2,lwd=2) lines(N-S,lty=3,col=3,lwd=2) legend("topright",bty="n",legend=c("Infected","Susceptible","Immunized"),lty=1:3,col=1:3,lwd=2) } par(mfrow=c(1,2)) ReedFrost(0.04) ReedFrost(0.015) ReedFrost(0.30) ReedFrost(0.03) ReedFrost(0.003) http://egg.5ch.net/test/read.cgi/hosp/1540905566/885
886: 卵の名無しさん [sage] 2020/01/30(木) 23:53:06 ID:m/EdOA9B こっちは、モンテカルロによるシミュレーション # Reed-Frost and Greenwood epidemic models # written by Dennis Chao (1/2009) # reedfrost - the Reed-Frost epidemic model # p = probability of transmission # I0 = initial number of infecteds # S0 = initial number of susceptibles # n = number of trials # greenwood = set to TRUE for the Greenwood model, otherwise run Reed-Frost # outputs the number of infected and susceptibles over time (as I and S) reedfrost <- function(p, I0, S0, n, greenwood=FALSE) { S <- St <- rep(S0, n) I <- It <- rep(I0, n) q <- 1-p time <- 0 while (sum(It)>0) { if (greenwood) It <- rbinom(n, St, ifelse(It>0, p, 0)) else It <- rbinom(n, St, 1-(q^It)) St <- St-It I <- rbind(I, It) S <- rbind(S, St) time <- time+1 } I <- as.matrix(I) S <- as.matrix(S) list(I0=I0,S0=S0,p=p,n=n,I=I,S=S) } http://egg.5ch.net/test/read.cgi/hosp/1540905566/886
887: 卵の名無しさん [sage] 2020/01/31(金) 00:59:52 ID:24QiZJ0Y f <- function(n,prec=1000){ # Σ 1/kを既約分数表示する if(n==1){ cat(1,'\n') invisible(1) }else{ GCD <- function(a,b){ # ユークリッドの互除法 r = a%%b # a=bq+r ⇒ a%%b=b%%rで最大公約数表示 while(r!=0){a = b ; b = r ; r = a%%b} b } library(Rmpfr) one = mpfr(1, prec) # 1(one)を1000桁精度に設定 nn = 1:n # nn : 1 2 3 ... n nume=numeric(n) # 分子の容器 for(i in nn) nume[i] = prod(nn[-i])*one # nnからi番目の要素を除いて乗算し精度アップ nume = mpfr2array(nume, dim = length(nume)) # mpfr2arrayで加算を可能にする Nume = sum(nume) # numeの総和を計算して分子に Deno=factorialZ(n) # 分母 n! = factorial(n*one) gcd = GCD(Nume,Deno) # Numerator/Denominator約分するため最大公約数を計算 res=list(nume = Nume/gcd,deno=Deno/gcd,ratio=as.numeric(Nume/Deno)) # 最大公約数で除算して # 分数表示 give.head=FALSEでheader除去,digits.dで桁数を指定 # capture.outputで変数に取り込み nm = capture.output(str(res$nume, give.head=FALSE,digits.d = prec)) dn = capture.output(str(res$deno, give.head=FALSE,digits.d = prec)) cat(paste0(nm,'/',dn,'\n')) invisible(res) }} for(i in 1:30) f(i) http://egg.5ch.net/test/read.cgi/hosp/1540905566/887
888: 卵の名無しさん [sage] 2020/01/31(金) 01:00:30 ID:24QiZJ0Y > for(i in 1:30) f(i) 1 3 / 2 11 / 6 25 / 12 137 / 60 49 / 20 363 / 140 761 / 280 7129 / 2520 7381 / 2520 83711 / 27720 86021 / 27720 1145993 / 360360 1171733 / 360360 1195757 / 360360 2436559 / 720720 42142223 / 12252240 14274301 / 4084080 275295799 / 77597520 55835135 / 15519504 18858053 / 5173168 19093197 / 5173168 122755644038509457 / 32872539188238750 186187999757029099 / 49308808782358125 14112026408124257248 / 3698160658676859375 185305423634953775872 / 48076088562799171875 5051322526706550956032 / 1298054391195577640625 11894590428248250515456 / 3028793579456347828125 1043915747995966839455744 / 263505041412702261046875 2255784105806550548873216 / 564653660170076273671875 http://egg.5ch.net/test/read.cgi/hosp/1540905566/888
889: 卵の名無しさん [sage] 2020/01/31(金) 01:12:13 ID:24QiZJ0Y >>884 H(n) = Σ[k=1,2,...,n] 1/k とする。H(n)を既約分数で表したときの分子の整数をf(n)と表す。 f(77)を求めよ。 > f(77) 17610982920730618962802441030965952272844514966520010106103127939813509744122599441432576 / 3574019481870823559764745233429885438685864430565417716720215849457565210956573486328125 http://egg.5ch.net/test/read.cgi/hosp/1540905566/889
890: 卵の名無しさん [sage] 2020/01/31(金) 07:13:25 ID:24QiZJ0Y >>884 n=100と大きいとNAが混ざるな http://egg.5ch.net/test/read.cgi/hosp/1540905566/890
891: 卵の名無しさん [sage] 2020/01/31(金) 07:15:08 ID:24QiZJ0Y f <− function(n,prec=10000){ # Σ 1/kを既約分数表示する if(n==1){ cat(? ?,1,?\n?) invisible(1) }else{ GCD <− function(a,b){ # ユークリッドの互除法 r = a%%b # a=bq+r ⇒ a%%b=b%%rで最大公約数表示 while(r!=0){a = b ; b = r ; r = a%%b} b } http://egg.5ch.net/test/read.cgi/hosp/1540905566/891
892: 卵の名無しさん [sage] 2020/01/31(金) 07:15:14 ID:24QiZJ0Y library(Rmpfr) one = mpfr(1, prec) # 1(one)を10000桁精度に設定 nn = 1:n # nn : 1 2 3 ... n nume=numeric(n) # 分子の容器 for(i in nn) nume[i] = prod(nn[−i])*one # nnからi番目の要素を除いて乗算し精度アップ nume = mpfr2array(nume, dim = length(nume)) # mpfr2arrayで加算を可能にする Nume = sum(nume) # numeの総和を計算して分子に Deno=factorialZ(n) # 分母 n! = factorial(n*one) gcd = GCD(Nume,Deno) # Numerator/Denominator約分するため最大公約数を計算 res=list(nume = Nume/gcd,deno=Deno/gcd,ratio=as.numeric(Nume/Deno)) # 最大公約数で除算して # 分数表示 give.head=FALSEでheader除去,digits.dで桁数を指定 # capture.outputで切り取りsubstrで[1]を除去 # nm = capture.output(str(res$nume, give.head=FALSE,digits.d = prec)) NAが混ざるバグあり nm =substr(capture.output(res$nume)[2],5,nchar(res$nume)) # ?[1] 1234..? 文字列の5文字目から最後まで dn =substr(capture.output(res$deno)[2],5,nchar(res$deno)) cat(paste0(nm,?/?,dn,?\n?)) invisible(res) }} http://egg.5ch.net/test/read.cgi/hosp/1540905566/892
893: 卵の名無しさん [sage] 2020/01/31(金) 07:15:42 ID:24QiZJ0Y > f(100) 3055216077446868329553816926933899676639525195878807877583434152044192757431459126874725081455196840519615954410565802448075620352 / 588971222367687651371627846346807888288472382883312574253249804256440585603406374176100610302040933304083276457607746124267578125 http://egg.5ch.net/test/read.cgi/hosp/1540905566/893
894: 卵の名無しさん [sage] 2020/01/31(金) 07:45:49 ID:24QiZJ0Y Reed-Frost モデル (1) 集団内の感染者と感受性のあるものとの接触はランダムに起こる (2) 感染者と感受性のあるものが接触して伝播する確率は一定である (3) 感染のあと必ず免疫が起こる(再感染はしない) (4) その集団は他の集団から隔離されている (5) 上記の条件は各時間経過中一定である ReedFrost=function( p=0.04, # 1期間内での伝播確率 N=100, # 集団の人数 T=40) # 全期間 { q=1-p # 伝播させない確率 I=numeric(T) # 感染者数 Infecteds S=numeric(T) # 感受性のある人数 Susceptibles I[1]=1 #一人から始まったとする S[1]=N-I[1] for(t in 1:(T-1)){ I[t+1]=S[t]*(1-q^I[t]) # Reed-Frost Model S[t+1]=S[t]-I[t+1] } return(list(I,T)) } http://egg.5ch.net/test/read.cgi/hosp/1540905566/894
895: 卵の名無しさん [sage] 2020/01/31(金) 11:25:54 ID:24QiZJ0Y # simulation model using binominal random number rm(list=ls()) reedfrost <- function(p, I0, S0, n, greenwood=FALSE) { S <- St <- rep(S0, n) # St : Suscepibles @ time t, S: I <- It <- rep(I0, n) # It : Infected @ time t q <- 1-p # probability of non-transmission time <- 0 while (sum(It)>0) { # until no new transmission if (greenwood) It <- rbinom(n, St, ifelse(It>0, p, 0)) else It <- rbinom(n, St, 1-(q^It)) # how many ppl newly trannsmitted among St St <- St-It # how many ppl left non-infected I <- rbind(I, It) S <- rbind(S, St) time <- time+1 } Inames=NULL for(i in 0:(nrow(I)-1)) Inames[i+1]=paste0('I',i) rownames(I)=Inames Snames=NULL for(i in 0:(nrow(I)-1)) Snames[i+1]=paste0('S',i) rownames(S)=Snames list(I0=I0,S0=S0,p=p,n=n,I=I,S=S) } re=reedfrost(0.05,1,99,100) nr=nrow(re$I) plot(0:(nr-1),re$I[,1],bty='l',type='l',lwd=2, ylim=c(0,max(re$I)),xlab='time',ylab='Infecteds') for(i in 2:n) lines(0:(nr-1),re$I[,i],lwd=2,col=sample(colours())) http://egg.5ch.net/test/read.cgi/hosp/1540905566/895
896: 卵の名無しさん [sage] 2020/01/31(金) 15:00:17 ID:24QiZJ0Y # SEIR MODEL " dS(t)/dt=-bS(t)I(t), dE(t)/dt=bS(t)I(t)-aE(t) , dI(t)/dt=aE(t)-gI(t) , dR(t)/dt=gI(t) a:発症率,b:感染率,g:回復率 " remove (list = objects() ) graphics.off() SEIR <- function( # Parameters contact_rate = 10, # number of contacts per day transmission_probability = 0.07, # transmission probability infectious_period = 5, # infectious period latent_period = 2, # latent period # Initial values for sub-populations. s = 9990, # susceptible hosts e = 9, # exposed hosts i = 1, # infectious hosts r = 0, # recovered hosts # Output timepoints. timepoints = seq (0, 100, by=0.5) ){ http://egg.5ch.net/test/read.cgi/hosp/1540905566/896
897: 卵の名無しさん [sage] 2020/01/31(金) 15:00:39 ID:24QiZJ0Y library(deSolve) # Function to compute derivatives of the differential equations. seir_model = function (current_timepoint, state_values, parameters) { # create state variables (local variables) S = state_values [1] # susceptibles E = state_values [2] # exposed I = state_values [3] # infectious R = state_values [4] # recovered with ( as.list (parameters), # variable names within parameters can be used { # compute derivatives dS = (-beta * S * I) dE = (beta * S * I) - (delta * E) dI = (delta * E) - (gamma * I) dR = (gamma * I) # combine results results = c (dS, dE, dI, dR) list (results) } ) } # Compute values of beta (tranmission rate) and gamma (recovery rate). beta_value = contact_rate * transmission_probability gamma_value = 1 / infectious_period delta_value = 1 / latent_period http://egg.5ch.net/test/read.cgi/hosp/1540905566/897
898: 卵の名無しさん [sage] 2020/01/31(金) 15:00:45 ID:24QiZJ0Y # Compute Ro - Reproductive number. Ro = beta_value / gamma_value # Disease dynamics parameters. parameter_list = c (beta = beta_value, gamma = gamma_value, delta = delta_value) # Compute total population. N = s + i + r + e # Initial state values for the differential equations. initial_values = c (S = s/N, E = e/N, I = i/N, R = r/N) # Simulate the SEIR epidemic. # ?lsoda # Solver for Ordinary Differential Equations (ODE), Switching Automatically Between Stiff and Non-stiff Methods output = lsoda (initial_values, timepoints, seir_model, parameter_list) # Plot dynamics of Susceptibles sub-population. plot (S ~ time, data = output, pch='S', type='b', col = 'blue', bty='l', cex=0.75, ylab='SEIR') points(E ~ time, data = output, pch='E', type='b', col = 'yellow', cex=0.75) points(I ~ time, data = output, pch='I', type='b', col = 'red', cex=0.75) points(R ~ time, data = output, pch='R', type='b', col = 'green', cex=0.75) } SEIR() args(SEIR) SEIR(contact_rate=0.5,transmission_probability=0.05,infectious_period=365,latent_period=7,s=99,e=0,i=1,r=0,timepoints = 0:365*6) http://egg.5ch.net/test/read.cgi/hosp/1540905566/898
899: 卵の名無しさん [sage] 2020/01/31(金) 17:42:44 ID:24QiZJ0Y エンデミックな定常状態を(S?, I?)とおけば、S?N=1R0,I?N=μμ+γ(1?1R0)(15)である。すなわちエンデミックな状態における感受性人口比率と基本再生産数は逆数関係にあり、有病率(prevalence)I?/Nは1?1/R0に比例していて、その比例係数は、感染状態における平均滞在時間1/(μ+γ)とホストの寿命1/μの比である。これらの式はエンデミックな感染症におけるR0の推定式ともみなせる http://egg.5ch.net/test/read.cgi/hosp/1540905566/899
900: 卵の名無しさん [sage] 2020/01/31(金) 17:45:07 ID:24QiZJ0Y Rv?1という条件はワクチン接種率の条件として書き直せばv?1?1R0=H http://egg.5ch.net/test/read.cgi/hosp/1540905566/900
901: 卵の名無しさん [sage] 2020/02/01(土) 15:12:17 ID:hIisy8jC H(n) = Σ[k=1,2,...,n] 1/k とする。H(n)を既約分数で表したときの分子の整数をf(n)と表す。 (1)lim[n→∞] H(n) を求めよ、答えのみで良い。 (2)n=1,2,...に対して、f(n)に現れる1桁の整数を全て求めよ " H <- function(n) sum(1/(1:n)) plot(sapply(1:1000,H),bty='l') f <- function(n,prec=10000){ # Σ 1/kを既約分数表示する n>>=23で誤計算 if(n==1){ cat(n, ':' ,1,'\n') invisible(1) }else{ GCD <- function(a,b){ # ユークリッドの互除法 r = a%%b # a=bq+r ⇒ a%%b=b%%rで最大公約数表示 while(r!=0){a = b ; b = r ; r = a%%b} b } nn = 1:n # nn : 1 2 3 ... n nume=list() # 分子の容器 length(nume)=n Nume=0 library(gmp) for(i in nn) Nume = Nume + prod.bigz(nn[-i]) # nnからi番目の要素を除いて乗算して総和を分子に Deno=factorialZ(n) # 分母 gcd = GCD(Nume,Deno) # Numerator/Denominator約分するため最大公約数を計算 NUME=Nume/gcd DENO=Deno/gcd ratio=as.numeric(Nume/Deno) RE=list(NUME,DENO,ratio) # 最大公約数で除算して約分 cat(n, ':' ,as.character(NUME),'/',as.character(DENO),'\n') invisible(RE) }} http://egg.5ch.net/test/read.cgi/hosp/1540905566/901
902: 卵の名無しさん [sage] 2020/02/01(土) 22:05:31 ID:hIisy8jC H(n) = Σ[k=1,2,...,n] 1/k とする。H(n)を既約分数で表したときの分子の整数をf(n)と表す。 f <- function(n){ # Σ 1/kを既約分数表示する if(n==1){ cat(n, ':' ,1,'\n') invisible(1) }else{ GCD <- function(a,b){ # ユークリッドの互除法 r = a%%b # a=bq+r ⇒ a%%b=b%%rで最大公約数表示 while(r!=0){a = b ; b = r ; r = a%%b} b } nn = 1:n # nn : 1 2 3 ... n nume=list() # 分子の容器となるlist length(nume)=n # を設定 Nume=0 library(gmp) for(i in nn) Nume = Nume + prod.bigz(nn[-i]) # nnからi番目の要素を除いて乗算して総和を分子に Deno=factorialZ(n) # 分母 gcd = GCD(Nume,Deno) # 約分するため最大公約数を計算 NUME=Nume/gcd DENO=Deno/gcd ratio=as.numeric(Nume/Deno) RE=list(NUME,DENO,ratio) cat(n, ':' ,as.character(NUME),'/',as.character(DENO),'\n') invisible(RE) }} http://egg.5ch.net/test/read.cgi/hosp/1540905566/902
903: 卵の名無しさん [sage] 2020/02/02(日) 13:53:23 ID:+5dNqMpE tbl <- function(x,v){ # vの要素がxにいくつあるか集計する n=length(v) hme=numeric(n) # how many entries? for(i in 1:n) hme[i]=sum(x==v[i]) rbind(v,hme) } tbl(sample(10,rep=T),1:10) http://egg.5ch.net/test/read.cgi/hosp/1540905566/903
904: 卵の名無しさん [sage] 2020/02/04(火) 16:35:57 ID:b64IHQrg "https://this.kiji.is/597220008571339873?c=39550187727945729 中国湖北省武漢市からチャーター機で日本へ帰国した邦人の新型コロナウイルス感染率が高いと、 中国で驚きの声が上がっている。中国当局が発表した同市の感染者の割合に比べ「39倍も高い」というのだ。 現地は医療現場が混乱しているため、実際には発表よりかなり多くの感染者がいる可能性がある。 日本政府はチャーター機計3便を武漢市に派遣し、邦人565人が帰国した。厚生労働省によると、 チャーター機に乗っていた感染者は、症状のない人も含め計8人。感染率は1.416%だ。 一方、1月31日現在、武漢市の感染者数は3215人で、感染率は0.036%にとどまった。" r1=8 r2=3215 n1=565 n2=round(3215/(0.036/100)) poisson.test(c(r1,r2),c(n1,n2)) prop.test(c(r1,r2),c(n1,n2)) library(BayesFactor) mat=cbind(c(r1,r2),c(n1,n2)-c(r1,r2)) fisher.test(mat) chisq.test(mat)$p.value bf=BayesFactor::contingencyTableBF(mat,sampleType = 'poisson',posterior = TRUE,iteration=1e5) rbf=round(bf) (r1/n1)/(r2/n2) frp <- function(x) (x[1]/(x[1]+x[2]))/ (x[3]/(x[3]+x[4])) rrp=apply(rbf,1,frp) hist(rrp) BEST::plotPost(rrp) (r1/(n1-r1))/(r2/(n2-r2)) fop <- function(x) (x[1]/x[2])/ (x[3]/x[4]) orp=apply(rbf,1,fop) BEST::plotPost(orp) quantile(orp,c(0.005,0.025,0.5,0.975,0.995)) library(exact2x2) exact2x2::fisher.exact(mat) fisher.test(mat) http://egg.5ch.net/test/read.cgi/hosp/1540905566/904
上
下
前
次
1-
新
書
関
写
板
覧
索
設
栞
歴
あと 98 レスあります
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.151s*