[過去ログ]
臨床統計もおもしろいですよ、その2 (1002レス)
臨床統計もおもしろいですよ、その2 http://egg.5ch.net/test/read.cgi/hosp/1540905566/
上
下
前
次
1-
新
通常表示
512バイト分割
レス栞
このスレッドは過去ログ倉庫に格納されています。
次スレ検索
歴削→次スレ
栞削→次スレ
過去ログメニュー
879: 卵の名無しさん [sage] 2020/01/30(木) 05:17:39 ID:m/EdOA9B >>878 イナカも東京も国立なら学費は同じだぞ。 http://egg.5ch.net/test/read.cgi/hosp/1540905566/879
880: 卵の名無しさん [] 2020/01/30(木) 08:20:09 ID:b9qEKmQr >>879 イナカモノにしてみれば 地元以外のところに大学が存在しているという時点で 学費以外にもアパート代や食費などの参入障壁があるんだな http://egg.5ch.net/test/read.cgi/hosp/1540905566/880
881: 卵の名無しさん [sage] 2020/01/30(木) 08:31:17 ID:17lSJR5q >>880 シリツ医大専門受験予備校のバイトは一コマ90分で手取り2万円だったな。大学の授業料が年間14万4千円の頃の話。 地方にはそんな割のいいバイトはない。 http://egg.5ch.net/test/read.cgi/hosp/1540905566/881
882: 卵の名無しさん [sage] 2020/01/30(木) 20:25:51 ID:m/EdOA9B Rで困ったらstackoveflow.comだな。 library(Rmpfr) vect = rep(0, 5) for(i in 1:5){ vect[i] = mpfr(x=10^-(10*i), precBits=100) } # My vector has just turned to a list vect # Sum of list is an error sum(vect) # Turn it to a vector converted_vect = Rmpfr::mpfr2array(vect, dim = length(vect)) converted_vect # Now my sum and prod work fine and the precision is not lost sum(converted_vect) prod(converted_vect) http://egg.5ch.net/test/read.cgi/hosp/1540905566/882
883: 卵の名無しさん [sage] 2020/01/30(木) 21:10:39 ID:m/EdOA9B パッケージの内部関数を使って解決してくれた。 The function mpfr2array is not suposed to be called by the user, it is an internal tool for the package. However it's one way to solve the problem. http://egg.5ch.net/test/read.cgi/hosp/1540905566/883
884: 卵の名無しさん [sage] 2020/01/30(木) 21:21:54 ID:m/EdOA9B Rはデフォルトでは不定長さ整数を扱えないので工夫がいる。 その点はpythonやHaskellの方が有利。 " H(n) = Σ[k=1,2,...,n] 1/k とする。H(n)を既約分数で表したときの分子の整数をf(n)と表す。 (1)lim[n→∞] H(n) を求めよ、答えのみで良い。 (2)n=1,2,...に対して、f(n)に現れる1桁の整数を全て求めよ " rm(list=ls()) H <- function(n,prec=1000){ # Σ 1/kを既約分数表示する 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 = factorial(n)*one # 分母のn!を精度アップ gcd = GCD(Nume,Deno) # Numerator/Denominator約分するため最大公約数を計算 res=list(nume = Nume/gcd,deno=Deno/gcd,ratio=as.numeric(Nume/Deno)) # 最大公約数で除算して cat(as.numeric(res$nume),'/',as.numeric(res$deno),'\n') # 数値化して分数表示 invisible(res) } http://egg.5ch.net/test/read.cgi/hosp/1540905566/884
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
上
下
前
次
1-
新
書
関
写
板
覧
索
設
栞
歴
あと 104 レスあります
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.007s