R Under development (unstable) (2024-11-15 r87338 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.0 > > 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() 14 NA values identified in the outcome variable Found in rows: 37, 41, 52, 55, 89, 96, 106, 108, 126, 132, 150, 157, 158, 159 > > > # 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: 18, 35, 42, 47, 49, 55, 61, 70, 73, 75, 80, 82, 91, 92, 97, 115, 117, 124, 126, 129, 135, 136, 137, 145, 146, 148, 153, 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: 18, 35, 42, 47, 49, 55, 61, 70, 73, 75, 80, 82, 91, 92, 97, 115, 117, 124, 126, 129, 135, 136, 137, 145, 146, 148, 153, 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.65 0.42 10.06