R Under development (unstable) (2024-12-03 r87418 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > ## > ## models with missing outcome data > ## > > #devtools::load_all("~/dev/geostan") > library(geostan) This is geostan version 0.8.1 > > iter = 25 > > # CAR Poisson model > data(georgia) > C <- shape2mat(georgia, "B", quiet = TRUE) > cars <- prep_car_data(C, quiet = TRUE) > N = nrow(georgia) > georgia$deaths.female[sample.int(N, size = 12)] <- NA > georgia$deaths.female[sample.int(N, size = 3)] <- 0 > > fit <- stan_car(deaths.female ~ offset(log(pop.at.risk.female)), + data = georgia, + car_parts = cars, + chains = 1, + family = poisson(), + iter = iter, + quiet = TRUE) |> + suppressWarnings() 15 NA values identified in the outcome variable Found in rows: 6, 18, 20, 41, 46, 52, 55, 58, 91, 126, 134, 136, 141, 151, 157 > > > # Binomial model with missing y > data(georgia) > A = shape2mat(georgia, "B") Contiguity condition: queen Number of neighbors per unit, summary: Min. 1st Qu. Median Mean 3rd Qu. Max. 1.000 4.000 5.000 5.409 6.000 10.000 Spatial weights, summary: Min. 1st Qu. Median Mean 3rd Qu. Max. 1 1 1 1 1 1 > N = nrow(A) > georgia$deaths.female[sample.int(N, size = 25)] <- NA > georgia$y <- round(georgia$deaths.female / 10) > georgia$y[sample.int(N, 5)] <- 0 > georgia$f <- round(4 * georgia$deaths.female / 10) > > > # glm > fit <- stan_glm(cbind(y, f) ~ 1, + data = georgia, + chains = 1, + family = binomial(), + iter = iter, + quiet = TRUE) |> + suppressWarnings() 28 NA values identified in the outcome variable Found in rows: 3, 10, 30, 35, 38, 49, 53, 55, 60, 64, 78, 79, 83, 85, 90, 92, 93, 95, 112, 115, 121, 123, 126, 132, 134, 146, 156, 157 > > # icar > fit <- stan_icar(cbind(deaths.female, pop.at.risk.female) ~ 1, + data = georgia, + type = 'bym', + C = A, + chains = 1, + family = binomial(), + iter = iter, + quiet = TRUE) |> + suppressWarnings() 28 NA values identified in the outcome variable Found in rows: 3, 10, 30, 35, 38, 49, 53, 55, 60, 64, 78, 79, 83, 85, 90, 92, 93, 95, 112, 115, 121, 123, 126, 132, 134, 146, 156, 157 > > # esf > data(georgia) > georgia$deaths.female[1:10] <- NA > georgia$y <- georgia$deaths.female > georgia$f <- round(4 * georgia$deaths.female) > > fit <- stan_esf(cbind(y, f) ~ log(income), + data = georgia, + C = shape2mat(georgia, "B"), + chains = 1, + family = binomial(), + iter = iter, + quiet = TRUE) |> + suppressWarnings() Contiguity condition: queen Number of neighbors per unit, summary: Min. 1st Qu. Median Mean 3rd Qu. Max. 1.000 4.000 5.000 5.409 6.000 10.000 Spatial weights, summary: Min. 1st Qu. Median Mean 3rd Qu. Max. 1 1 1 1 1 1 13 NA values identified in the outcome variable Found in rows: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 55, 126, 157 > > > proc.time() user system elapsed 9.62 0.43 10.00