diff --git a/Bayesian regional random coefficients regression.mxd b/Bayesian regional random coefficients regression.mxd deleted file mode 100644 index 0537d8b..0000000 Binary files a/Bayesian regional random coefficients regression.mxd and /dev/null differ diff --git a/Documentation/Cluster Analysis of trees in Bavarian National Park using the MCLUST package.pdf b/Documentation/Cluster Analysis of trees in Bavarian National Park using the MCLUST package.pdf deleted file mode 100644 index 4e193f9..0000000 Binary files a/Documentation/Cluster Analysis of trees in Bavarian National Park using the MCLUST package.pdf and /dev/null differ diff --git a/Documentation/Model Based Cluster Analysis.pdf b/Documentation/Model Based Cluster Analysis.pdf new file mode 100644 index 0000000..0d0b89f Binary files /dev/null and b/Documentation/Model Based Cluster Analysis.pdf differ diff --git a/Documentation/Semiparametric regression.pdf b/Documentation/Semiparametric regression.pdf deleted file mode 100644 index e8a9341..0000000 Binary files a/Documentation/Semiparametric regression.pdf and /dev/null differ diff --git a/ModelBasedClustering.aprx b/ModelBasedClustering.aprx new file mode 100644 index 0000000..5d9203c Binary files /dev/null and b/ModelBasedClustering.aprx differ diff --git a/ModelBasedClustering.mxd b/ModelBasedClustering.mxd new file mode 100644 index 0000000..917e72f Binary files /dev/null and b/ModelBasedClustering.mxd differ diff --git a/R Sample Tools.tbx b/R Sample Tools.tbx new file mode 100644 index 0000000..a842364 Binary files /dev/null and b/R Sample Tools.tbx differ diff --git a/README.txt b/README.txt index 3fe4b55..4b9e9bc 100644 --- a/README.txt +++ b/README.txt @@ -3,9 +3,6 @@ R Example Tools -Dimistry Pavlushko, Mark Janikas, Konstantin Krivoruchko, Shaun Walbridge and Steve Kopp, Esri Inc - - Sample ArcMap MXD and ArcGIS Pro Project Add .tbx files diff --git a/RToolbox.tbx b/RToolbox.tbx deleted file mode 100644 index 5169491..0000000 Binary files a/RToolbox.tbx and /dev/null differ diff --git a/data.gdb/a00000001.TablesByName.atx b/data.gdb/a00000001.TablesByName.atx index 9f513cd..32b8b2f 100644 Binary files a/data.gdb/a00000001.TablesByName.atx and b/data.gdb/a00000001.TablesByName.atx differ diff --git a/data.gdb/a00000001.freelist b/data.gdb/a00000001.freelist index e8d1689..25ca53a 100644 Binary files a/data.gdb/a00000001.freelist and b/data.gdb/a00000001.freelist differ diff --git a/data.gdb/a00000001.gdbtable b/data.gdb/a00000001.gdbtable index 8a50561..40f65f1 100644 Binary files a/data.gdb/a00000001.gdbtable and b/data.gdb/a00000001.gdbtable differ diff --git a/data.gdb/a00000001.gdbtablx b/data.gdb/a00000001.gdbtablx index 2fcde24..b6abf4b 100644 Binary files a/data.gdb/a00000001.gdbtablx and b/data.gdb/a00000001.gdbtablx differ diff --git a/data.gdb/a00000004.CatItemsByPhysicalName.atx b/data.gdb/a00000004.CatItemsByPhysicalName.atx index f8ec76a..8cfcb51 100644 Binary files a/data.gdb/a00000004.CatItemsByPhysicalName.atx and b/data.gdb/a00000004.CatItemsByPhysicalName.atx differ diff --git a/data.gdb/a00000004.CatItemsByType.atx b/data.gdb/a00000004.CatItemsByType.atx index 647fe91..4668b92 100644 Binary files a/data.gdb/a00000004.CatItemsByType.atx and b/data.gdb/a00000004.CatItemsByType.atx differ diff --git a/data.gdb/a00000004.FDO_UUID.atx b/data.gdb/a00000004.FDO_UUID.atx index e10435d..bd1e62a 100644 Binary files a/data.gdb/a00000004.FDO_UUID.atx and b/data.gdb/a00000004.FDO_UUID.atx differ diff --git a/data.gdb/a00000004.freelist b/data.gdb/a00000004.freelist index a58456b..8c537f6 100644 Binary files a/data.gdb/a00000004.freelist and b/data.gdb/a00000004.freelist differ diff --git a/data.gdb/a00000004.gdbtable b/data.gdb/a00000004.gdbtable index 6232fa7..d6d3852 100644 Binary files a/data.gdb/a00000004.gdbtable and b/data.gdb/a00000004.gdbtable differ diff --git a/data.gdb/a00000004.gdbtablx b/data.gdb/a00000004.gdbtablx index 3dbe687..16e7bdb 100644 Binary files a/data.gdb/a00000004.gdbtablx and b/data.gdb/a00000004.gdbtablx differ diff --git a/data.gdb/a00000004.spx b/data.gdb/a00000004.spx index c40eeb5..34b4ba8 100644 Binary files a/data.gdb/a00000004.spx and b/data.gdb/a00000004.spx differ diff --git a/data.gdb/a00000006.CatRelsByDestinationID.atx b/data.gdb/a00000006.CatRelsByDestinationID.atx index 8411871..8867d9f 100644 Binary files a/data.gdb/a00000006.CatRelsByDestinationID.atx and b/data.gdb/a00000006.CatRelsByDestinationID.atx differ diff --git a/data.gdb/a00000006.CatRelsByOriginID.atx b/data.gdb/a00000006.CatRelsByOriginID.atx index 6817938..92abd62 100644 Binary files a/data.gdb/a00000006.CatRelsByOriginID.atx and b/data.gdb/a00000006.CatRelsByOriginID.atx differ diff --git a/data.gdb/a00000006.CatRelsByType.atx b/data.gdb/a00000006.CatRelsByType.atx index bbc8407..b36d270 100644 Binary files a/data.gdb/a00000006.CatRelsByType.atx and b/data.gdb/a00000006.CatRelsByType.atx differ diff --git a/data.gdb/a00000006.FDO_UUID.atx b/data.gdb/a00000006.FDO_UUID.atx index 71f242a..3a018cf 100644 Binary files a/data.gdb/a00000006.FDO_UUID.atx and b/data.gdb/a00000006.FDO_UUID.atx differ diff --git a/data.gdb/a00000006.freelist b/data.gdb/a00000006.freelist index e8d1689..4788f16 100644 Binary files a/data.gdb/a00000006.freelist and b/data.gdb/a00000006.freelist differ diff --git a/data.gdb/a00000006.gdbtable b/data.gdb/a00000006.gdbtable index d197a0f..3bb9e64 100644 Binary files a/data.gdb/a00000006.gdbtable and b/data.gdb/a00000006.gdbtable differ diff --git a/data.gdb/a00000006.gdbtablx b/data.gdb/a00000006.gdbtablx index 851106c..511ee81 100644 Binary files a/data.gdb/a00000006.gdbtablx and b/data.gdb/a00000006.gdbtablx differ diff --git a/data.gdb/a0000000b.gdbtable b/data.gdb/a0000000b.gdbtable deleted file mode 100644 index 7c85d01..0000000 Binary files a/data.gdb/a0000000b.gdbtable and /dev/null differ diff --git a/data.gdb/a0000000b.gdbtablx b/data.gdb/a0000000b.gdbtablx deleted file mode 100644 index 517958e..0000000 Binary files a/data.gdb/a0000000b.gdbtablx and /dev/null differ diff --git a/data.gdb/a0000000b.spx b/data.gdb/a0000000b.spx deleted file mode 100644 index 26df6da..0000000 Binary files a/data.gdb/a0000000b.spx and /dev/null differ diff --git a/data.gdb/a0000000c.gdbindexes b/data.gdb/a0000000c.gdbindexes deleted file mode 100644 index c9d0caa..0000000 Binary files a/data.gdb/a0000000c.gdbindexes and /dev/null differ diff --git a/data.gdb/a0000000c.gdbtable b/data.gdb/a0000000c.gdbtable deleted file mode 100644 index 0ad0a94..0000000 Binary files a/data.gdb/a0000000c.gdbtable and /dev/null differ diff --git a/data.gdb/a0000000c.spx b/data.gdb/a0000000c.spx deleted file mode 100644 index 1679f73..0000000 Binary files a/data.gdb/a0000000c.spx and /dev/null differ diff --git a/data.gdb/a0000000d.freelist b/data.gdb/a0000000d.freelist deleted file mode 100644 index f0509be..0000000 Binary files a/data.gdb/a0000000d.freelist and /dev/null differ diff --git a/data.gdb/a0000000d.gdbindexes b/data.gdb/a0000000d.gdbindexes deleted file mode 100644 index c9d0caa..0000000 Binary files a/data.gdb/a0000000d.gdbindexes and /dev/null differ diff --git a/data.gdb/a0000000d.gdbtable b/data.gdb/a0000000d.gdbtable deleted file mode 100644 index 375ba47..0000000 Binary files a/data.gdb/a0000000d.gdbtable and /dev/null differ diff --git a/data.gdb/a0000000d.gdbtablx b/data.gdb/a0000000d.gdbtablx deleted file mode 100644 index ebcfb47..0000000 Binary files a/data.gdb/a0000000d.gdbtablx and /dev/null differ diff --git a/data.gdb/a0000000d.spx b/data.gdb/a0000000d.spx deleted file mode 100644 index 8295d73..0000000 Binary files a/data.gdb/a0000000d.spx and /dev/null differ diff --git a/data.gdb/a0000000e.gdbindexes b/data.gdb/a0000000e.gdbindexes deleted file mode 100644 index c9d0caa..0000000 Binary files a/data.gdb/a0000000e.gdbindexes and /dev/null differ diff --git a/data.gdb/a0000000e.gdbtable b/data.gdb/a0000000e.gdbtable deleted file mode 100644 index ae81d10..0000000 Binary files a/data.gdb/a0000000e.gdbtable and /dev/null differ diff --git a/data.gdb/a0000000e.gdbtablx b/data.gdb/a0000000e.gdbtablx deleted file mode 100644 index 1027c81..0000000 Binary files a/data.gdb/a0000000e.gdbtablx and /dev/null differ diff --git a/data.gdb/a0000000e.spx b/data.gdb/a0000000e.spx deleted file mode 100644 index 47c84cf..0000000 Binary files a/data.gdb/a0000000e.spx and /dev/null differ diff --git a/data.gdb/a00000010.freelist b/data.gdb/a00000010.freelist deleted file mode 100644 index f70d922..0000000 Binary files a/data.gdb/a00000010.freelist and /dev/null differ diff --git a/data.gdb/a00000010.gdbindexes b/data.gdb/a00000010.gdbindexes deleted file mode 100644 index c9d0caa..0000000 Binary files a/data.gdb/a00000010.gdbindexes and /dev/null differ diff --git a/data.gdb/a00000010.gdbtable b/data.gdb/a00000010.gdbtable deleted file mode 100644 index 6db8e3a..0000000 Binary files a/data.gdb/a00000010.gdbtable and /dev/null differ diff --git a/data.gdb/a00000010.gdbtablx b/data.gdb/a00000010.gdbtablx deleted file mode 100644 index 2c021b9..0000000 Binary files a/data.gdb/a00000010.gdbtablx and /dev/null differ diff --git a/data.gdb/a00000010.spx b/data.gdb/a00000010.spx deleted file mode 100644 index 5178819..0000000 Binary files a/data.gdb/a00000010.spx and /dev/null differ diff --git a/data.gdb/a0000000b.gdbindexes b/data.gdb/a00000011.gdbindexes similarity index 100% rename from data.gdb/a0000000b.gdbindexes rename to data.gdb/a00000011.gdbindexes diff --git a/data.gdb/a00000011.gdbtable b/data.gdb/a00000011.gdbtable new file mode 100644 index 0000000..ef021a2 Binary files /dev/null and b/data.gdb/a00000011.gdbtable differ diff --git a/data.gdb/a0000000c.gdbtablx b/data.gdb/a00000011.gdbtablx similarity index 80% rename from data.gdb/a0000000c.gdbtablx rename to data.gdb/a00000011.gdbtablx index a25f22a..e1d8da8 100644 Binary files a/data.gdb/a0000000c.gdbtablx and b/data.gdb/a00000011.gdbtablx differ diff --git a/data.gdb/a00000011.spx b/data.gdb/a00000011.spx new file mode 100644 index 0000000..c314442 Binary files /dev/null and b/data.gdb/a00000011.spx differ diff --git a/data.gdb/timestamps b/data.gdb/timestamps index 16a0518..24be7b8 100644 Binary files a/data.gdb/timestamps and b/data.gdb/timestamps differ diff --git a/gambia.mxd b/gambia.mxd deleted file mode 100644 index 8adb8ff..0000000 Binary files a/gambia.mxd and /dev/null differ diff --git a/scripts/brcm.R b/scripts/brcm.R deleted file mode 100644 index dd0b9e6..0000000 --- a/scripts/brcm.R +++ /dev/null @@ -1,160 +0,0 @@ -# -# Belarus thyroid cancer in children case study -# - -tool_exec <- function(in_params, out_params) -{ -### handle input gp tool paramaters - dataset_path <- in_params[[1]] - case_field <- in_params[[2]] - pop_field <- in_params[[3]] - covar1_field <- in_params[[4]] - covar2_field <- in_params[[5]] - - df = regional_bayesian(dataset_path, case_field, pop_field, covar1_field, covar2_field) - -### handle gp tool outputs - output_dataset_name = out_params[[1]] - arc.write(output_dataset_name, df) - return(out_params) -} - -#stat analysis with WINBUGS -regional_bayesian <- function(dataset_path, case_field, pop_field, covar1_field, covar2_field) -{ - if (!requireNamespace("sp", quietly = TRUE)) - install.packages("sp") - if (!requireNamespace("spdep", quietly = TRUE)) - install.packages("spdep") - if (!requireNamespace("R2WinBUGS", quietly = TRUE)) - install.packages("R2WinBUGS") - if (!requireNamespace("rgeos", quietly = TRUE)) - install.packages("rgeos") - require(sp) - require(spdep) - - message("Loading dataset...") - ds <- arc.open(dataset_path) - df <- arc.select(ds, fields = list(case_field, pop_field, covar1_field, covar2_field)) - sp.df <- arc.data2sp(df) - - # convert shapefile data to a list of polygons and a data frame - centroids <- rgeos::gCentroid(sp.df, byid = TRUE) - centroids <- centroids@coords - - kk <- nrow(sp.df) - - # calculate the expected counts - pmap <- probmap(df[[case_field]], df[[pop_field]]) - - # make neighbours list - message("Making Neighbours...") - five.nn <- knn2nb(knearneigh(centroids, k=5), sym=TRUE) - - #plotpolys(th_polys, bbs, border="grey") - #plot(five.nn, centroids, add=TRUE) - -#####4 "GWR" - - ## data preparation - dlist <- nbdists(five.nn, centroids) - num <- sapply(five.nn, length) - - ll <- sum(num) - # equal Weights: - weights <- rep(1, ll) - - adj <- rep(0, ll) - mm <- 1 - for (i in 1:kk) - { - for (j in 1:num[i]) - { - adj[mm] <- five.nn[[i]][j] - mm <- mm + 1 - } - } - - input.data <- list(n=kk, - cases = df[[case_field]], - expected = pmap$expCount, - weights=weights, - a1 = df[[covar1_field]], - a2 = df[[covar2_field]]/min(df[[covar2_field]]), - num=num, - adj=adj) - - ### inits - b_init <- rep(0.0, kk) - model.inits <- function() {list(alpha = 0, tau.v = 1, tau.u = 1, b1 = b_init, b2 = b_init)} - # output parameters - model.parameters <- c("theta", "mu", "v", "u", "alpha", "PP", "b1", "b2", "RR_exp", "RR_het", "RR_clust") - - model_file <- tempfile("BRCM-model", fileext='.bug') - R2WinBUGS::write.model(BRCM.model, model_file) - - ### run BUGS - message("Running WinBUGS model...") - result.4 <- R2WinBUGS::bugs(input.data, model.inits, model.parameters, model_file, n.chains=1, n.iter=100000, debug=F, working.directory=tempdir()) - - unlink(model_file) - -#append results columns - df$expected <- pmap$expCount - df$rel_risk <- result.4$mean$theta - df$rel_risk_se <- result.4$sd$theta - df$extra_risk <- result.4$mean$PP - df$extra_risk_se <- result.4$sd$PP - df$mean <- result.4$mean$mu - df$mean_se <- result.4$sd$mu - df$u_cor <- result.4$mean$u - df$u_cor_se <- result.4$sd$u - df$u_heter <- result.4$mean$v - df$u_heter_se <- result.4$sd$v - df$covariates <- result.4$mean$RR_exp - df$heterogeneous <- result.4$mean$RR_het - df$residuals <- result.4$mean$RR_clust - df$r1 <- result.4$mean$b1 - df$r1_se <- result.4$sd$b1 - df$r2 <- result.4$mean$b2 - df$r2_se <- result.4$sd$b2 - - return(df) -} - -BRCM.model <- function() -{ - for (i in 1:n) - { - # Poisson likelihood for observed counts - cases[i] ~ dpois(mu[i]) - log(mu[i]) <- log(expected[i]) + alpha + u[i] + v[i] + b1[i]*a1[i] + b2[i]*a2[i] - # Relative Risk - theta[i] <- exp(alpha + u[i] + v[i] + b1[i]*a1[i] + b2[i]*a2[i]) - # Posterior probability of RR[i]>1 - PP[i] <- step(theta[i] - 1 + eps) - # Prior distribution for the uncorrelated heterogeneity - v[i] ~ dnorm(0,tau.v) - # Relative Risk decomposition - RR_exp[i]<-exp(b1[i]*a1[i] + b2[i]*a2[i]) - RR_het[i]<-exp(v[i]) - RR_clust[i]<-exp(u[i]) - } - - eps <- 1.0E-6 - - # CAR prior distribution for spatial correlated heterogeneity - u[1:n] ~ car.normal(adj[], weights[], num[], tau.u) - b1[1:n] ~ car.normal(adj[], weights[], num[], tau.b1) - b2[1:n] ~ car.normal(adj[], weights[], num[], tau.b2) - - # Improper prior distribution for the mean relative risk in the study region - alpha ~ dflat() - mean <- exp(alpha) - - # Hyperprior distributions on inverse variance parameter of random effects - tau.u ~ dgamma(0.5,0.0005) - tau.v ~ dgamma(0.5,0.0005) - tau.b1 ~ dgamma(0.5,0.0005) - tau.b2 ~ dgamma(0.5,0.0005) -} diff --git a/scripts/clustering.R b/scripts/clustering.R index 0209064..b5b5472 100644 --- a/scripts/clustering.R +++ b/scripts/clustering.R @@ -1,7 +1,6 @@ # case study using mclust package tool_exec <- function(in_params, out_prams) { - #message(getOption("repos")) if (!requireNamespace("sp", quietly = TRUE)) install.packages("sp") if (!requireNamespace("mclust", quietly = TRUE)) @@ -10,22 +9,24 @@ tool_exec <- function(in_params, out_prams) require(sp) source_dataset = in_params[[1]] - nclust = NULL #in_params[[2]] + #nclust = in_params[[2]] out_table = out_prams[[1]] out_ellipses = out_prams[[2]] out_dens = out_prams[[3]] out_sim = out_prams[[4]] - ### read data arc.progress_label("Loading Dataset") - data <- arc.select(arc.open(source_dataset)) + d <- arc.open(source_dataset) + # read only OID field + data <- arc.select(d, names(d@fields[d@fields == "OID"])) data_shp <- arc.shape(data) data.xy <- cbind(data_shp$x, data_shp$y) # or data.frame(x=data_shp$x, y=data_shp$y) ######### arc.progress_label("Bayesian Information Criterion for Model-Based Clustering...") - patternBIC <- mclustBIC(data.xy, G = nclust) + patternBIC <- mclustBIC(data.xy) # G = nclust) + patternModel <- summary(patternBIC, data.xy) print(patternModel) diff --git a/scripts/semi_par_regression.R b/scripts/semi_par_regression.R deleted file mode 100644 index 476f243..0000000 --- a/scripts/semi_par_regression.R +++ /dev/null @@ -1,90 +0,0 @@ - -make_knots <-function (x1, x2, num.knots) -{ - if (missing(num.knots)) - num.knots <- max(10, min(50, round(length(x1)/4))) - X <- cbind(x1, x2) - dup.inds <- (1:nrow(X))[dup.matrix(X) == T] - if (length(dup.inds) > 0) - X <- X[-dup.inds, ] - knots <- cluster::clara(X, num.knots)$medoids - return(knots) -} - -tool_exec <- function(in_params, out_params) -{ - #### Load Library for Analysis #### - if (!requireNamespace("SemiPar", quietly = TRUE)) - install.packages("SemiPar") - require(SemiPar) - - #### Get Input Parameters #### - input_features = in_params[[1]] - input_predictions = in_params[[2]] - dep_variable = in_params[[3]] - nonlin_variables = in_params[[4]] - lin_variables = in_params[[5]] - input_knots = in_params[[6]] - - #### Import Dataset to Dataframe #### - fc = arc.open(input_features) - df = arc.select(fc, c(dep_variable, nonlin_variables, lin_variables)) - df['x'] = arc.shape(df)$x - df['y'] = arc.shape(df)$y - - #### Import Knots to DataFrame #### - if (is.null(input_knots)) - { - knots.est = make_knots(df$x, df$y) - } - else - { - knots_df = arc.select(arc.open(input_knots)) - knots.est = make_knots(arc.shape(knots_df)$x, arc.shape(knots_df)$y) - } - - #### Create Spatial Effect #### - fxy = "f(x,y,knots=knots.est)" - - #### Create Non-Linear Params #### - nonlin_params = paste(paste0("f(", nonlin_variables, ")"), collapse = "+") - - #### Create Formula and Fit SemiPar #### - e = as.list(df) - e$knots.est = knots.est - all_params = paste0(dep_variable, " ~ ", fxy, "+", nonlin_params) - - #### Create Linear Params #### - if (!is.null(lin_variables)) - all_params = paste0(all_params, "+", paste(lin_variables, collapse = "+")) - -#print(all_params) - tryCatch( - { - attach(e) - form = as.formula(all_params) - fit = spm(form, family="binomial") - },finally = detach(e)) - - #### Prediction #### - pred_fc = arc.open(input_predictions) - pred_df = arc.select(pred_fc, c(nonlin_variables, lin_variables)) - summary(fit) - pred_df_xy <- data.frame( - x = arc.shape(pred_df)$x, - y = arc.shape(pred_df)$y, - pred_df) - - pred = with(pred_df_xy, predict.spm(fit, newdata = pred_df_xy, se = TRUE)) - - #### Write Output #### - pred_df['prediction'] = 1 / (1+exp(-pred$fit)) - pred_df['prediction_se'] = pred$se - pred_df['lower_sign'] = 1 / (1+exp(-pred$fit+1.96*pred$se)) - pred_df['upper_sign'] = 1/(1+exp(-pred$fit-1.96*pred$se)) - - output_features = out_params[[1]] - arc.write(output_features, pred_df) - - return(out_params) -} diff --git a/symbology/DensityPoints_Symbology.lyr b/symbology/DensityPoints_Symbology.lyr new file mode 100644 index 0000000..0fece6d Binary files /dev/null and b/symbology/DensityPoints_Symbology.lyr differ