diff --git a/incidenceMapR/R/latentFieldModel.R b/incidenceMapR/R/latentFieldModel.R index 22c789e..6736e84 100644 --- a/incidenceMapR/R/latentFieldModel.R +++ b/incidenceMapR/R/latentFieldModel.R @@ -40,7 +40,7 @@ latentFieldModel <- function(db , shp, family = NULL, neighborGraph = NULL){ hyper=list() hyper$global <- list(prec = list( prior = "pc.prec", param = 1/10, alpha = 0.01)) hyper$local <- list(prec = list( prior = "pc.prec", param = 1/100, alpha = 0.01)) - hyper$age <- list(prec = list( prior = "pc.prec", param = 1/100, alpha = 0.01)) + hyper$age <- list(prec = list( prior = "pc.prec", param = 1, alpha = 0.01)) hyper$time <- list(prec = list( prior = "pc.prec", param = 1/50, alpha = 0.01)) diff --git a/incidenceMapR/R/smoothModel.R b/incidenceMapR/R/smoothModel.R index 4051211..ebf14e5 100644 --- a/incidenceMapR/R/smoothModel.R +++ b/incidenceMapR/R/smoothModel.R @@ -42,7 +42,7 @@ smoothModel <- function(db, shp, family = NULL, neighborGraph = NULL){ hyper=list() hyper$global <- list(prec = list( prior = "pc.prec", param = 1/10, alpha = 0.01)) hyper$local <- list(prec = list( prior = "pc.prec", param = 1/100, alpha = 0.01)) - hyper$age <- list(prec = list( prior = "pc.prec", param = 1/100, alpha = 0.01)) + hyper$age <- list(prec = list( prior = "pc.prec", param = 1, alpha = 0.01)) # we smooth across factor levels with random effects replicates: http://www.r-inla.org/models/tools#TOC-Models-with-more-than-one-type-of-likelihood diff --git a/incidenceMapR/buildModelsForDeployment.R b/incidenceMapR/buildModelsForDeployment.R index 2d3d6c2..98a39d1 100644 --- a/incidenceMapR/buildModelsForDeployment.R +++ b/incidenceMapR/buildModelsForDeployment.R @@ -57,9 +57,10 @@ for (SOURCE in names(geoLevels)){ saveModel(model) + dir.create('/home/rstudio/seattle_flu/plots/', showWarnings = FALSE) for(k in unique(model$modeledData[[FACTOR]])){ tmp<-list(modeledData = model$modeledData[model$modeledData[[FACTOR]]==k,]) - fname <- paste('/home/rstudio/seattle_flu/data/plots/',paste(PATHOGEN,SOURCE,GEO,FACTOR,k,sep='-'),'.png',sep='') + fname <- paste('/home/rstudio/seattle_flu/plots/',paste(PATHOGEN,SOURCE,GEO,FACTOR,k,sep='-'),'.png',sep='') png(filename = fname,width = 6, height = 5, units = "in", res = 300) print(ggplotSmoothMap(tmp,shp,title=k,shape_level = GEO)) dev.off() @@ -68,7 +69,6 @@ for (SOURCE in names(geoLevels)){ }, error=function(e){cat("ERROR :",conditionMessage(e), "\n")} ) - } } } diff --git a/modelServR/.gitignore b/modelServR/.gitignore new file mode 100644 index 0000000..757ca33 --- /dev/null +++ b/modelServR/.gitignore @@ -0,0 +1 @@ +plots diff --git a/modelServR/DESCRIPTION b/modelServR/DESCRIPTION index 92c51d5..9afffa0 100644 --- a/modelServR/DESCRIPTION +++ b/modelServR/DESCRIPTION @@ -11,10 +11,3 @@ License: What license it uses Encoding: UTF-8 LazyData: true RoxygenNote: 6.1.1 -Suggest: - testthat - dbViewR -Imports: - digest, - jsonlite, - logging \ No newline at end of file diff --git a/modelServR/NAMESPACE b/modelServR/NAMESPACE index e8e4bf1..f2e5174 100644 --- a/modelServR/NAMESPACE +++ b/modelServR/NAMESPACE @@ -13,4 +13,5 @@ export(returnModel) export(saveModel) import(digest) import(jsonlite) +import(logging) importFrom(jsonlite,toJSON) diff --git a/modelServR/R/returnModel.R b/modelServR/R/returnModel.R index 1dcd067..82f556f 100644 --- a/modelServR/R/returnModel.R +++ b/modelServR/R/returnModel.R @@ -1,6 +1,3 @@ -library(logging) -basicConfig() - #' loadModelFileById function for getting modeled data #' #' This function will load a model from the model_store_dir by Id @@ -39,29 +36,23 @@ loadModelFileById <- function (filename, model_store_dir = Sys.getenv('MODEL_STO #' @return model in requested format #' #' @import jsonlite +#' @import logging #' @export #' @examples #' returnModel <- function(queryIn = jsonlite::toJSON( list( - SELECT =list(COLUMN=c('sampling_location','residence_census_tract')), - WHERE =list(COLUMN='sampling_location', IN = c('kiosk')), - GROUP_BY =list(COLUMN=c('sampling_location','residence_census_tract')), - SUMMARIZE=list(COLUMN='sampling_location', IN= c('kiosk')) + SELECT =list(COLUMN=c('site_type','residence_census_tract')), + WHERE =list(COLUMN='site_type', IN = c('kiosk')), + GROUP_BY =list(COLUMN=c('site_type','residence_census_tract')), + SUMMARIZE=list(COLUMN='site_type', IN= c('kiosk')) )), type = 'smooth', version = 'latest', cloudDir = Sys.getenv('MODEL_STORE', '/home/rstudio/seattle_flu/test_model_store')){ - # https://www.dropbox.com/sh/5loj4x6j4tar17i/AABy5kP70IlYtSwrePg4m44Ca?dl=0 - - # need to solve paths problem for intalled packages! - # ideally this would point to a web-based repository of models so that anyone can get to it. - # THIS DOES NOT WORK because of authentication. Need to explore rdrop2 package! - - # NEED TO Pull multiple formats of data once saving latent fields is implemented in incidenceMapR - # ACTUALLY, current plan is to have csv obey format for each model type - + basicConfig() + if(class(queryIn)== 'list'){ queryList <- queryIn queryIn <- jsonlite::toJSON(queryIn) diff --git a/modelServR/R/saveModel.R b/modelServR/R/saveModel.R index 9f80737..33aee37 100644 --- a/modelServR/R/saveModel.R +++ b/modelServR/R/saveModel.R @@ -1,7 +1,3 @@ -library(logging) -basicConfig() -setLevel("FINEST") - #' getHumanReadableModelIdFromModel: return human readable verion of model from query #' #' @param model INLA model object that will generatie id from @@ -58,10 +54,15 @@ getModelQueryObjectFromModel<- function(model, model_type = 'inla', latent = FAL #' #' @param query query object container the observed and the model_type attributes #' +#' @import logging +#' #' @return An object containing the observed and the model_type fields #' @export #' getModelQueryObjectFromQuery <- function(query) { + basicConfig() + setLevel("FINEST") + logdebug("getModelQueryObjectFromQuery Src:", str(query)) logdebug("$observed", attr(query, "observed")) result <- newEmptyObject() @@ -86,11 +87,15 @@ getModelIdFromModel <- function(model) { #' @param query query object container the observed and the model_type attributes #' #' @import digest +#' @import logging #' @importFrom jsonlite toJSON #' #' @export #' getModelIdFromQuery <- function(query) { + basicConfig() + setLevel("FINEST") + #props <- getModelQueryObjectFromQuery(query) modelId <- as.character(jsonlite::toJSON(query, simplifyDataFrame=)) logdebug("Model ID JSON:", jsonlite::toJSON(query, simplifyDataFrame=)) diff --git a/modelServR/man/getModelQueryObjectFromModel.Rd b/modelServR/man/getModelQueryObjectFromModel.Rd index 0d76e19..3f01050 100644 --- a/modelServR/man/getModelQueryObjectFromModel.Rd +++ b/modelServR/man/getModelQueryObjectFromModel.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/saveModel.R \name{getModelQueryObjectFromModel} \alias{getModelQueryObjectFromModel} -\title{getModelQueryObjectFromModel: return query object from a model. +\title{getModelQueryObjectFromModel: return query object from a model. This is the object we use to generate our unique ids.} \usage{ getModelQueryObjectFromModel(model, model_type = "inla", @@ -19,6 +19,6 @@ getModelQueryObjectFromModel(model, model_type = "inla", An object containing the observed and the model_type fields } \description{ -getModelQueryObjectFromModel: return query object from a model. +getModelQueryObjectFromModel: return query object from a model. This is the object we use to generate our unique ids. } diff --git a/modelServR/man/loadModelFileById.Rd b/modelServR/man/loadModelFileById.Rd index 58af57f..531d5e7 100644 --- a/modelServR/man/loadModelFileById.Rd +++ b/modelServR/man/loadModelFileById.Rd @@ -8,7 +8,7 @@ loadModelFileById(filename, model_store_dir = Sys.getenv("MODEL_STORE", "/home/rstudio/seattle_flu"), type = "csv") } \arguments{ -\item{filename}{= At moment we expect full filename in format ID.extension. +\item{filename}{= At moment we expect full filename in format ID.extension. This is so in future we can more easily support different model save formats} \item{model_store_dir}{= directory where models are stored} diff --git a/modelServR/man/returnModel.Rd b/modelServR/man/returnModel.Rd index 9457bea..3353ce3 100644 --- a/modelServR/man/returnModel.Rd +++ b/modelServR/man/returnModel.Rd @@ -5,10 +5,10 @@ \title{returnModel function for getting modeled data} \usage{ returnModel(queryIn = jsonlite::toJSON(list(SELECT = list(COLUMN = - c("sampling_location", "GEOID")), WHERE = list(COLUMN = + c("sampling_location", "residence_census_tract")), WHERE = list(COLUMN = "sampling_location", IN = c("kiosk")), GROUP_BY = list(COLUMN = - c("sampling_location", "GEOID")), SUMMARIZE = list(COLUMN = - "sampling_location", IN = c("kiosk")))), type = "smooth", + c("sampling_location", "residence_census_tract")), SUMMARIZE = + list(COLUMN = "sampling_location", IN = c("kiosk")))), type = "smooth", version = "latest", cloudDir = Sys.getenv("MODEL_STORE", "/home/rstudio/seattle_flu/test_model_store")) }