This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(ggplot2) | |
| library(patchwork) | |
| get_NHPP <-function(Tmax, lambda, ..., | |
| lambda2=NULL, maxit=10000){ | |
| if(is.null(lambda2)){ | |
| opt <- optimise(lambda, lower = 0, upper = Tmax, maximum = TRUE, | |
| ...) | |
| lambda2 <- opt$objective |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(estatapi) | |
| library(tidyverse) | |
| myappId <- scan("appId.txt", what = character()) #ここには自分のアプリケーションIDを入れる | |
| # list1 <- estat_getStatsList(appId = myappId, searchWord = "人口動態調査") | |
| # view(list1) | |
| dat1 <-estat_getStatsData(appId = myappId, statsDataId = "0003411856") | |
| dat_filt <- dplyr::filter(dat1, `夫の初婚・再婚`=="夫_総数", `妻の初婚・再婚`=="妻_総数") |> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(tidyr) | |
| library(dplyr) | |
| library(deSolve) | |
| sir_ctmc <- function(S0, I0, R0, | |
| beta, gamma, | |
| t_max = 100) { | |
| # 初期状態 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(tidyr) | |
| library(dplyr) | |
| library(deSolve) | |
| sir_ctmc <- function(S0, I0, R0, | |
| beta, gamma, | |
| t_max = 100) { | |
| # 初期状態 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| BirthDeathSim <-function(Ninit, mu, lambda, Tmax){ | |
| N <- rpois(1, Tmax*(mu+lambda)) | |
| CTs <- sort(runif(N, 0, Tmax)) | |
| tmp <-sample(c(1,-1), N, prob=c(lambda/(mu+lambda),mu/(mu+lambda)), replace=TRUE) | |
| CTs <- c(0,CTs) | |
| path <-cumsum(c(Ninit,tmp)) | |
| data.frame(time = c(CTs, Tmax), population = c(path, path[length(path)])) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(dplyr) | |
| simulate_branching_death <- function(alpha, | |
| beta, | |
| Tmax) { | |
| death_time <- rexp(1,beta) | |
| death <- min(Tmax, death_time) | |
| N0 <- rpois(1, death * alpha) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(RHawkes) | |
| simulate_branching_death <- function(mu, | |
| alpha, | |
| beta, | |
| Tmax) { | |
| N0 <- rpois(1, Tmax * mu) | |
| if(N0==0L){ | |
| return( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(ggplot2) | |
| simulate_branching_death <- function(mu, | |
| lambda, | |
| beta, | |
| Tmax) { | |
| N0 <- rpois(1, Tmax * mu) | |
| t0 <- sort(runif(N0, 0, Tmax)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(dplyr) | |
| branching_process <- function(mu, lambda, Tmax, G){ | |
| gen <- vector("list", G) | |
| X <- rpois(1, mu*Tmax) #第1世代 | |
| if(X>0){ | |
| id <- 1L:X | |
| parent <- 0L | |
| birth_time <- sort(runif(X, 0, Tmax)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(ggplot2) | |
| simulate_multitype_gillespie <- function( | |
| R, | |
| Tmax, | |
| initial_type = 1L | |
| ) { | |
| K <- nrow(R) |
NewerOlder