Title: | Interface to GompitZ Tool for Modelling the Degradation of Sewer Pipelines |
---|---|
Description: | Functions enabling the writing of GompitZ input files, running of GompitZ Tools (gompcal.exe, gompred.exe) and reading of GompitZ output files. |
Authors: | Hauke Sonnenberg [aut, cre] , Michael Rustler [ctb] , SEMA [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
Maintainer: | Hauke Sonnenberg <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.8.0 |
Built: | 2024-11-10 03:29:43 UTC |
Source: | https://github.com/KWB-R/kwbGompitz |
Check for Convergence in Calibration
.calibrationAvailable(calibration, strata = NULL, param = NULL)
.calibrationAvailable(calibration, strata = NULL, param = NULL)
calibration |
result of Gompitz calibration as provided by
|
strata |
vector of strata for which convergence is checked |
param |
if not NULL, this structure, representing the content of the
"param.txt" file, is used instead of |
named logical vector with as many elements as there are in strata each of which indicates if convergence was achieved for the corresponding stratum
Content for Strategy File 0
.fileContentStrategy0(range.years, condition.labels)
.fileContentStrategy0(range.years, condition.labels)
range.years |
vector of two integer numbers: first and last year of simulation |
condition.labels |
vector of condition labels |
Content for Strategy File 1
.fileContentStrategy1(rehabilitation.costs, annual.total.length)
.fileContentStrategy1(rehabilitation.costs, annual.total.length)
rehabilitation.costs |
list of rehabilitation costs per condition. The names of the list elements are the condition labels and the values of the list elements are the corresponding rehabilitation costs. Example: list(C4 = 200, C3 = 300, C2 = 400, C1 = 500) |
annual.total.length |
list of annual total lengths to be rehabilitated. The names of the list elements are the year numbers and the values of the list elements are the lenghts to be rehabilitated in the corresponding year. Example: list("2005" = 100, "2006" = 110, "2007" = 120) |
File Content for Strategy 1 or 2
.fileContentStrategy1or2(rehabilitation.costs, annual.total.length.or.budget)
.fileContentStrategy1or2(rehabilitation.costs, annual.total.length.or.budget)
rehabilitation.costs |
list of rehabilitation costs per condition. The names of the list elements are the condition labels and the values of the list elements are the corresponding rehabilitation costs. Example: list(C4=200, C3=300, C2=400, C1=500) |
annual.total.length.or.budget |
list of annual total lengths to be rehabilitated or annual total budgets. |
Content for Strategy File 2
.fileContentStrategy2(rehabilitation.costs, annual.total.budget)
.fileContentStrategy2(rehabilitation.costs, annual.total.budget)
rehabilitation.costs |
list of rehabilitation costs per condition. The names of the list elements are the condition labels and the values of the list elements are the corresponding rehabilitation costs. Example: list(C4=200, C3=300, C2=400, C1=500) |
annual.total.budget |
list of annual total budget of rehabilitation operations. The names of the list elements are the year numbers and the values of the list elements are the annual total budgets for the corresponding year. Example: list("2005"=100000, "2006"=110000, "2007"=120000) |
Content for Strategy File 3
.fileContentStrategy3( condition.labels, rehabilitation.costs, max.tol.prop.of.length, range.years, target.year )
.fileContentStrategy3( condition.labels, rehabilitation.costs, max.tol.prop.of.length, range.years, target.year )
condition.labels |
vector of condition labels Example: c("C4", "C3", "C2", "C1") |
rehabilitation.costs |
vector of rehabilitation costs per condition in the order of the corresponding condition labels in condition.labels Example: c(200, 300, 400, 500) |
max.tol.prop.of.length |
vector of maximum tolerated proportion of network length in each condition in the order of the corresponding condition labels in condition.labels. Example: c(1.0, 0.7, 0.4, 0.05) |
range.years |
two element vector containing the first and last year of simulation |
target.year |
year at which the proportions of the network length in each condition must have been brought just below their maximum tolerated value |
Extract number of observations from calibration result
.getObservationByCondition(calibration)
.getObservationByCondition(calibration)
calibration |
calibration result as retrieved by
|
order by weighted probabilities
.orderByWeightedProbabilities( probabilities, weight = seq_len(ncol(probabilities)) )
.orderByWeightedProbabilities( probabilities, weight = seq_len(ncol(probabilities)) )
probabilities |
matrix of probabilities |
weight |
vector of weights with as many elements as there are columns in probabilities |
.runModuleInDirectory
.runModuleInDirectory( module, target.dir, input.file, sep, ..., verbose = 1, show.error = TRUE )
.runModuleInDirectory( module, target.dir, input.file, sep, ..., verbose = 1, show.error = TRUE )
module |
module |
target.dir |
target.dir |
input.file |
input.file |
sep |
sep |
... |
additional arguments passed to kwb.utils::runInDirectory |
verbose |
verbose (default: 1 ) |
show.error |
show.error (default: TRUE) |
???
Append assignment "a=b"
addAssignment(main = "", a, b)
addAssignment(main = "", a, b)
main |
current assignment string |
a |
key of the assignment |
b |
value of the assignment |
main
with a = b
appended with a comma as separator if
main
is not empty
Print an underlined Header
catHeader(x, char)
catHeader(x, char)
x |
caption |
char |
character used for the underline |
Print the Structure of an Object
catStructure(x, max.level = NA)
catStructure(x, max.level = NA)
x |
any R object |
max.level |
passed to |
print the structure of an object
Bind Columns from a list of Data Frames
cbindDataFrames(dataFrames, keyindex = 1:2)
cbindDataFrames(dataFrames, keyindex = 1:2)
dataFrames |
list of data frames |
keyindex |
indices of (key) columns to be excluded |
Warn if the model did not converge for all strata
checkConvergence(calibration, do.warn = TRUE)
checkConvergence(calibration, do.warn = TRUE)
calibration |
calibration object as returned by
|
do.warn |
if |
named logical vector with element names corresponding to the names of
the elements of calibration
that represent the different strata.
Checks if input data is defined properly
checkInputData(input.data)
checkInputData(input.data)
input.data |
input.data |
error in case input data was not defined properly
Apply a Function for each Column
columnwise(x, FUN, ...)
columnwise(x, FUN, ...)
x |
two dimensional object |
FUN |
function to be called for each column |
... |
arguments passed to |
Compare Estimates in calib.txt and param.txt
compareEstimates(calibration, parameters, digits, warn = FALSE)
compareEstimates(calibration, parameters, digits, warn = FALSE)
calibration |
list structure as returned by
|
parameters |
list structure as returned by
|
digits |
round the estimates to this number of significant (not decimal!) digits before comparing |
warn |
if |
number of warnings that occurred
Compose input data for Gompitz functions runGompitzCalibration
,
runGompitzPrediction
composeGompitzInputData( masterdata, covariates, weight, covariates.status, condition.labels = NULL, warn = FALSE )
composeGompitzInputData( masterdata, covariates, weight, covariates.status, condition.labels = NULL, warn = FALSE )
masterdata |
data.frame containing master data as retrieved by
|
covariates |
data.frame containing covariates in columns. Must have as many rows as masterdata |
weight |
weight to be given for each inspection (each row) in masterdata. Should be a vector of same length as there are rows in masterdata. Default: 1 |
covariates.status |
matrix of covariate status as retrieved by
|
condition.labels |
All possible condition labels, e.g. c("1", "2", "3", "4"). Default: unique values in column "condition" of masterdata |
warn |
if TRUE (default), a warning is given if weight does not have the expected length |
list with elements masterdata (data.frame), covariates (data.frame), weight (numeric vector), covariates.status (numeric matrix) and condition.labels (character vector)
Prepare "master data" (stratum, pipe-ID, year of installation, year of inspection, condition class) for Gompitz functions
composeMasterData(stratum, pipeid, instyear, inspyear, condition)
composeMasterData(stratum, pipeid, instyear, inspyear, condition)
stratum |
Stratum alphanumerical label |
pipeid |
Pipeline Identifier alphanumerical label |
instyear |
Installation year (integer) |
inspyear |
Inspection Year (integer - void field if not inspected) |
condition |
Condition Class alphanumerical label |
data.frame with columns stratum, pipeid, instyear, inspyear, condition,
Copy Model Parameters from one Stratum to another
copyParameters(calibration, from = NULL, to = NULL, dbg = TRUE)
copyParameters(calibration, from = NULL, to = NULL, dbg = TRUE)
calibration |
calibration object as returned by
|
from |
name of stratum to copy parameters from |
to |
vector of names of strata to which parameters are to be
copied to. If not given, the parameters of |
dbg |
if |
## Not run: # Get an example calibration calibration <- kwbGompitz::exampleCalibration() # Check for which strata the model parameters converged checkConvergence(calibration, do.warn = FALSE) # Copy parameters from a stratum for which the model parameters converged # to a stratum for which the model parameters did not converge calibration <- copyParameters(calibration, from = "Cast Iron", to = "Concrete") # Check again checkConvergence(calibration, do.warn = FALSE) # The following gives a warning (no convergence for source stratum) and returns # the calibration unchanged calibration <- copyParameters(calibration, "Clay", "Brick") # The following gives a warning (differing distinct condition classes) and # returns the calibration unchanged calibration <- copyParameters(calibration, "Cast Iron", "Brick") ## End(Not run)
## Not run: # Get an example calibration calibration <- kwbGompitz::exampleCalibration() # Check for which strata the model parameters converged checkConvergence(calibration, do.warn = FALSE) # Copy parameters from a stratum for which the model parameters converged # to a stratum for which the model parameters did not converge calibration <- copyParameters(calibration, from = "Cast Iron", to = "Concrete") # Check again checkConvergence(calibration, do.warn = FALSE) # The following gives a warning (no convergence for source stratum) and returns # the calibration unchanged calibration <- copyParameters(calibration, "Clay", "Brick") # The following gives a warning (differing distinct condition classes) and # returns the calibration unchanged calibration <- copyParameters(calibration, "Cast Iron", "Brick") ## End(Not run)
Create Example Files Using Different Windows Executables. Run different executables of gompcal and gompred (as provided in subfolders "bin_<version>" with version in ["win32", "win32_kwb", "unix_home"]) on the example input file (obs.txt) and store the results in folders "example_<version>".
createExampleFiles()
createExampleFiles()
Create smaller versions of the example files
createExampleFilesSmall( parts = c(2, 4, 8, 16), version = c("unix", "unix_home", "win32", "win32_kwb")[ifelse(kwb.utils::.OStype() == "unix", 1, 3)], types = c("obs", "predict0", "predict1", "predict2", "iff"), targetdir = NULL )
createExampleFilesSmall( parts = c(2, 4, 8, 16), version = c("unix", "unix_home", "win32", "win32_kwb")[ifelse(kwb.utils::.OStype() == "unix", 1, 3)], types = c("obs", "predict0", "predict1", "predict2", "iff"), targetdir = NULL )
parts |
vector of integer determining the parts of the files to be created: 2 = first half, 3 = first third, ..., 10 = first 10 percent, etc. |
version |
one of c("unix", "unix_home", "win32", "win32_kwb") |
types |
vector of file types to be created. See the default assignment for possible items |
targetdir |
full path to the target directory in which to put the files.
By default the files go into the package's example directory related to
the selected |
## Not run: kwbGompitz:::createExampleFilesSmall(c(2, 4, 10))
## Not run: kwbGompitz:::createExampleFilesSmall(c(2, 4, 10))
Default covariate status matrix
createStatusMatrix( strata = NULL, covariateNames = NULL, default.other = 3, default.length = 0, covariates = "Length_num", Data = NULL, column.strata = "Material_cat", column.length = NULL, note = TRUE )
createStatusMatrix( strata = NULL, covariateNames = NULL, default.other = 3, default.length = 0, covariates = "Length_num", Data = NULL, column.strata = "Material_cat", column.length = NULL, note = TRUE )
strata |
names of strata (e.g. unique values in column stratum of masterdata) |
covariateNames |
names of covariates |
default.other |
default status value to be used in any cell of the matrix, except the cells in column LENGTH. Default: 3 |
default.length |
status value to be used in column LENGTH. Default: 0 |
covariates |
names of columns in |
Data |
data frame with one row per inspection |
column.strata |
name of column in |
column.length |
name of column in |
note |
if |
Get default Vector of Condition Colours
default_condition_colours(condition_labels)
default_condition_colours(condition_labels)
condition_labels |
vector of condition class names ordered from the best to the worst condition |
vector of colour codes with the conditions as element names
Interactive Plot of Survival Curves
demo_survival( t = 1:100, alpha.0 = -1.15, bz0.0 = -0.88, bz1.0 = -2.77, theme = ggplot2::theme_bw() )
demo_survival( t = 1:100, alpha.0 = -1.15, bz0.0 = -0.88, bz1.0 = -2.77, theme = ggplot2::theme_bw() )
t |
vector of times at which to calculate the survival curves |
alpha.0 |
initial value of the |
bz0.0 |
initial value of the |
bz1.0 |
initial value of the |
theme |
ggplot2-theme applied to the plots |
This function returns a calibration object (as returned by
runGompitzCalibration
), corresponding to the example provided
with the Gompitz software package
exampleCalibration(VERSION = getOperatingSystemType())
exampleCalibration(VERSION = getOperatingSystemType())
VERSION |
one of "unix", "unix_home", "win32", "win32_kwb" |
Get the full path to one of the example files provided with the GompitZ software package of which copies are available in this R package.
exampleFile(filename = "none", ..., dbg = TRUE)
exampleFile(filename = "none", ..., dbg = TRUE)
filename |
name of the example file |
... |
passed to |
dbg |
if |
full path to the example file
Provide Label for Plot in selected Language
get_label(element = NULL, lng = "en")
get_label(element = NULL, lng = "en")
element |
one of "title", "ylab", "ylab.rel", "ylab.dev", "title.legend" |
lng |
language acronym, "de" for German or "en" for English |
???
Create target directory if required and return the path to it
get_or_create_target_dir(version)
get_or_create_target_dir(version)
version |
one of |
Get Survival Curves from a Calibration Object
get_survivals(calibration, stratum, t = 1:100, matrix = TRUE, ...)
get_survivals(calibration, stratum, t = 1:100, matrix = TRUE, ...)
calibration |
calibration object as returned by
|
stratum |
name of stratum for which to return the survival curves |
t |
vector of times for which to calculate the survival probabilities |
matrix |
if |
... |
further arguments passed to |
Get a full calibration object as returned by
runGompitzCalibration
, but not by calling this function but by
just reading the file calibr.txt
getCalibration(file_calib, file_param = NULL, digits = 3)
getCalibration(file_calib, file_param = NULL, digits = 3)
file_calib |
full path to calibration file |
file_param |
full path to file |
digits |
passed to |
Source File of Calibration Result
getCalibrationFile(calib.result)
getCalibrationFile(calib.result)
calib.result |
calibration result of Gompitz calibration as provided by
|
Get the calibration parameters as they are required to generate the param.txt file for the gompred program, from the calibration object
getCalibrationParameters( calibration = exampleCalibration(), remove_non_calibrated = TRUE )
getCalibrationParameters( calibration = exampleCalibration(), remove_non_calibrated = TRUE )
calibration |
calibration object as returned by
|
remove_non_calibrated |
if |
Gompitz constants regarding the status of covariates (not used, influencing the initial state, influencint the deterioration speed, influencing both)
getConstants()
getConstants()
@export
Default paths to GompitZ executable and example files
getDefaultPaths(VERSION = getOperatingSystemType(), ...)
getDefaultPaths(VERSION = getOperatingSystemType(), ...)
VERSION |
one of "unix", "win32", "win32_kwb" |
... |
arguments passed to resolve |
Example Covariate Status Matrix
getExampleStatusMatrix()
getExampleStatusMatrix()
Get file Content for Input File
getFileContentForInputFile( masterdata, covariates, covariates.status, condition.labels, weight, sep, file = NULL )
getFileContentForInputFile( masterdata, covariates, covariates.status, condition.labels, weight, sep, file = NULL )
masterdata |
masterdata as returned by |
covariates |
data.frame with as many rows as there are in masterdata and as many columns as there are covariates, containing the covariate values |
covariates.status |
matrix of covariate status as retrieved by
|
condition.labels |
condition labels |
weight |
Weight of the pipeline for the calibration |
sep |
column separator |
file |
if a path to a file is given here, the content will be written to the file instead of returned by this function |
Random Observation Data
getSampleObservations(n = 100)
getSampleObservations(n = 100)
n |
number of rows to be generated |
data frame with columns MATERIAL, Baujahr, DN, Pipe, Note, Inspection, PipeLength, before1970
Read Strata Labels from Observation File
getStataLabels(input.file, sep)
getStataLabels(input.file, sep)
input.file |
path to input fule |
sep |
column separator |
Generate gg-plot of stacked Bars
gg_stacked_bars( data, relative = TRUE, labels = FALSE, legend = c("bottom", "left", "top", "right", "none")[5], reverse = TRUE, lng = "en", colours = NULL )
gg_stacked_bars( data, relative = TRUE, labels = FALSE, legend = c("bottom", "left", "top", "right", "none")[5], reverse = TRUE, lng = "en", colours = NULL )
data |
data frame with columns |
relative |
logical indicating whether to show absolute or relative lenghts |
labels |
logical indicating whether to show labels (axes, title) are shown. |
legend |
legend position: one of |
reverse |
logical indicating whether to stack the bars in reversed order |
lng |
language acronym, "de" for German or "en" for English, that is
passed to |
colours |
named vector that maps the values in |
Calibration Input File Body
inputFileBody(masterdata, covariates, weight, sep)
inputFileBody(masterdata, covariates, weight, sep)
masterdata |
masterdata as returned by |
covariates |
data.frame with as many rows as there are in masterdata and as many columns as there are covariates, containing the covariate values |
weight |
Weight of the pipeline for the calibration |
sep |
column separator |
kwbGompitz:::inputFileHeader
Calibration Input File Header
inputFileHeader(condition.labels, covariates, covariates.status, sep = ";")
inputFileHeader(condition.labels, covariates, covariates.status, sep = ";")
condition.labels |
condition labels |
covariates |
data.frame containing covariates. Needed to determine if covariates are numeric or categorical |
covariates.status |
matrix of covariate status as retrieved by
|
sep |
column separator |
kwbGompitz:::inputFileBody
Interpolate equidistantly between End Points
interpolate_between(y1, y2, n = 2L, version = 3)
interpolate_between(y1, y2, n = 2L, version = 3)
y1 |
numeric vector of y-values at the beginning |
y2 |
numeric vector of y-values at the end. Must be as long as |
n |
number of interpolation points including first and last value |
version |
version of implementation |
matrix M
with n
columns and as many rows as there are
values in y1
(and also in y1
). The first column contains the
values from y1
, the last column contains the values from y2
and the n - 2
columns in between contain the interpolated values.
y1 <- c(1, 1, 1) y2 <- c(0.1, 0.5, 0.8) n <- 10 y <- interpolate_between(y1, y2, n) barplot(y, beside = TRUE) # Compare the performance of slightly different implementations microbenchmark::microbenchmark( v1 = interpolate_between(y1, y2, n, version = 1), v2 = interpolate_between(y1, y2, n, version = 2), v3 = interpolate_between(y1, y2, n, version = 3), times = 1000, check = function(x) kwb.utils::allAreIdentical(x[2:3]) && all(kwb.utils::almostEqual(x[[1]], x[[2]])) )
y1 <- c(1, 1, 1) y2 <- c(0.1, 0.5, 0.8) n <- 10 y <- interpolate_between(y1, y2, n) barplot(y, beside = TRUE) # Compare the performance of slightly different implementations microbenchmark::microbenchmark( v1 = interpolate_between(y1, y2, n, version = 1), v2 = interpolate_between(y1, y2, n, version = 2), v3 = interpolate_between(y1, y2, n, version = 3), times = 1000, check = function(x) kwb.utils::allAreIdentical(x[2:3]) && all(kwb.utils::almostEqual(x[[1]], x[[2]])) )
alpha = theta[cond] Integr PY(t) <= j | theta, Z, IFF . phi(IFF) . dIFF Gauss-Legendre Integration on [a,b]
marginal_survival(t, alpha, bz0, bz1, s, version = 1)
marginal_survival(t, alpha, bz0, bz1, s, version = 1)
t |
time |
alpha |
parameter "alpha" |
bz0 |
parameter "bz0" |
bz1 |
parameter "bz1" |
s |
standard deviation? |
version |
1, 2, or 3 |
Convert Data in wide View to long View
matrixToLongDataFrame(x, columnName = deparse(substitute(x)))
matrixToLongDataFrame(x, columnName = deparse(substitute(x)))
x |
data frame or list of data frames |
columnName |
column name in result data frame |
Call a function with all possible combinations of argument ranges
multicall(FUN, ..., fix. = names(formals(FUN))[1], max.combinations = 1000)
multicall(FUN, ..., fix. = names(formals(FUN))[1], max.combinations = 1000)
FUN |
function to be called |
... |
scalars or vectors named as the arguments that are accepted by
|
fix. |
names of arguments to be kept constant |
max.combinations |
maximum number of argument combinations to be created at maximum |
bmi <- function(mass, height) round(mass / (height * height), 1) kwbGompitz:::multicall( bmi, mass = 60:70, height = seq(1.7, 1.8, 0.1), fix. = NULL )
bmi <- function(mass, height) round(mass / (height * height), 1) kwbGompitz:::multicall( bmi, mass = 60:70, height = seq(1.7, 1.8, 0.1), fix. = NULL )
Plot several Survival Curves
multiplot_survival( t, alpha = 0, bz0 = 0, bz1 = 0, span = rep(TRUE, 3), theme = ggplot2::theme_bw() )
multiplot_survival( t, alpha = 0, bz0 = 0, bz1 = 0, span = rep(TRUE, 3), theme = ggplot2::theme_bw() )
t |
vector of times for which to calculate the survival curves |
alpha |
parameter alpha of the survival function |
bz0 |
parameter bz0 of the survival function |
bz1 |
parameter bz1 of the survival function |
span |
vector of logical of length three indicating for each of the
parameters |
theme |
ggplot2-theme applied to the plots |
Convert the list structure containing calibration parameters as retrieved by
kwbGompitz:::readParameters
to a vector of character representing the
text lines to be written to file
parameterLines(parameters, sep = ";", digits_exp = 2L)
parameterLines(parameters, sep = ";", digits_exp = 2L)
parameters |
list structure containing calibration parameters as
provided by |
sep |
column separator. Default: ";" |
digits_exp |
number of exponent digits in scientific notation, such as "1.23e+01" (digits_exp = 2L, the default) or "1.23e+001" (digits_exp = 3L) |
vector of character representing the lines of param.txt, containing the calibration parameters as generated by /codegompcal
Plot multiple Survival Curves
parameterplot(t, alpha = 0, bz0 = 0, bz1 = 0, xlim = c(0, 1.2 * max(t)))
parameterplot(t, alpha = 0, bz0 = 0, bz1 = 0, xlim = c(0, 1.2 * max(t)))
t |
vector of times for which to calculate the survival curves |
alpha |
vector of parameters alpha to be passed to the survival function |
bz0 |
vector of parameters bz0 to be passed to the survival function |
bz1 |
vector of parameters bz1 to be passed to the survival function |
xlim |
limits of the x axis |
Plot the Pipe Conditions over Time
plot_pipe_conditions( x, column_instyear = "instyear", column_ident = "ident", column_inspyear = "inspyear", column_condition = "condition", colour_values = c(C4 = "green", C3 = "yellow", C2 = "orange", C1 = "red", "grey"), y_labels = FALSE, facet_by = sprintf(kwb.utils::underscoreToPercent("~(10*as.integer(_s/10))"), column_instyear), by_pipe = FALSE )
plot_pipe_conditions( x, column_instyear = "instyear", column_ident = "ident", column_inspyear = "inspyear", column_condition = "condition", colour_values = c(C4 = "green", C3 = "yellow", C2 = "orange", C1 = "red", "grey"), y_labels = FALSE, facet_by = sprintf(kwb.utils::underscoreToPercent("~(10*as.integer(_s/10))"), column_instyear), by_pipe = FALSE )
x |
data frame |
column_instyear |
name of column containing the installation year |
column_ident |
name of column containing the pipe identifier |
column_inspyear |
name of column containing the inspection year |
column_condition |
name of column containing the pipe condition |
colour_values |
named vector of colour names. The names must refer to
the values in |
y_labels |
logical. If |
facet_by |
character string representing a formula to be used to create
facets with |
by_pipe |
if |
## Not run: x <- kwbGompitz:::readObservations(kwbGompitz::exampleFile("obs.txt")) plot_pipe_conditions(x[1:100, ]) ## End(Not run)
## Not run: x <- kwbGompitz:::readObservations(kwbGompitz::exampleFile("obs.txt")) plot_pipe_conditions(x[1:100, ]) ## End(Not run)
List of ggplots with each plot representing the evolution of condition probabilities over time for one pipe
plot_prediction_by_pipe( prediction, prefix = "prob", pipe_ids = unique(kwb.utils::selectColumns(prediction, "pipe_id")), width = 1 )
plot_prediction_by_pipe( prediction, prefix = "prob", pipe_ids = unique(kwb.utils::selectColumns(prediction, "pipe_id")), width = 1 )
prediction |
data frame as returned by |
prefix |
prefix of column names containing the probabilities. Default: "prob" |
pipe_ids |
vector of pipe IDs for which a plot is to be generated. By default all available pipes are considered! |
width |
passed to |
???
Generate gg-plot of Stacked Bars
plot_stacked_bars(x, x.sd = NULL, reverse = TRUE, ...)
plot_stacked_bars(x, x.sd = NULL, reverse = TRUE, ...)
x |
matrix containing the bar heights |
x.sd |
optional. Standard deviations. |
reverse |
logical indicating whether to reverse the stack order |
... |
additional arguments passed to |
values <- c( 0, 2, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 2, 5, 0, 0, 3, 0, 0 ) conditionStat <- matrix(values, nrow = 4, byrow = TRUE, dimnames = list( condition = paste0("prob", 1:4), year = 2001:2005 )) # Get the base plot baseplot <- kwbGompitz::plot_stacked_bars(conditionStat, legend = "right") # Show the base plot baseplot # Modify the base plot (titles, axis titles, legend title, legend content) baseplot + ggplot2::labs( x = "Jahr", y = "Anteil Kanaele in %", title = "Zustandsverteilung", subtitle = "Netzwerk: Berlin" ) + ggplot2::guides(fill = ggplot2::guide_legend("Zustandsklasse")) + ggplot2::scale_fill_manual( values = c("darkgreen", "yellow", "darkorange3", "red3"), labels = c("good", "ok", "not so good", "bad") )
values <- c( 0, 2, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 2, 5, 0, 0, 3, 0, 0 ) conditionStat <- matrix(values, nrow = 4, byrow = TRUE, dimnames = list( condition = paste0("prob", 1:4), year = 2001:2005 )) # Get the base plot baseplot <- kwbGompitz::plot_stacked_bars(conditionStat, legend = "right") # Show the base plot baseplot # Modify the base plot (titles, axis titles, legend title, legend content) baseplot + ggplot2::labs( x = "Jahr", y = "Anteil Kanaele in %", title = "Zustandsverteilung", subtitle = "Netzwerk: Berlin" ) + ggplot2::guides(fill = ggplot2::guide_legend("Zustandsklasse")) + ggplot2::scale_fill_manual( values = c("darkgreen", "yellow", "darkorange3", "red3"), labels = c("good", "ok", "not so good", "bad") )
Plot Survival Curves
plot_survival_curves( calibration = exampleCalibration(), stratum = NULL, marginal = TRUE, t = 1:100, col = NULL, ..., args = NULL )
plot_survival_curves( calibration = exampleCalibration(), stratum = NULL, marginal = TRUE, t = 1:100, col = NULL, ..., args = NULL )
calibration |
calibration object |
stratum |
name of stratum |
marginal |
logical. If |
t |
vector of times at which to calculate the survival curves |
col |
vector of colour names, named according to the conditions as
stored in |
... |
arguments passed to |
args |
arguments passed to get_survivals |
## Not run: # Get the example calibration provided with the Gompitz software calibration <- kwbGompitz::exampleCalibration() # Generate one ggplot2-object for each calibrated stratum (plots_1 <- plot_survival_curves(calibration)) # By default the marginal survival curves are shown. You may set marginal to # FALSE to get the non-marginal survival curves (plots_2 <- plot_survival_curves(calibration, marginal = FALSE)) # Compare the plots gridExtra::grid.arrange(plots_1[[1]], plots_2[[1]], plots_1[[2]], plots_2[[2]]) ## End(Not run)
## Not run: # Get the example calibration provided with the Gompitz software calibration <- kwbGompitz::exampleCalibration() # Generate one ggplot2-object for each calibrated stratum (plots_1 <- plot_survival_curves(calibration)) # By default the marginal survival curves are shown. You may set marginal to # FALSE to get the non-marginal survival curves (plots_2 <- plot_survival_curves(calibration, marginal = FALSE)) # Compare the plots gridExtra::grid.arrange(plots_1[[1]], plots_2[[1]], plots_1[[2]], plots_2[[2]]) ## End(Not run)
Plot Calibration Result
plotCalibration1(calib, to.pdf = FALSE)
plotCalibration1(calib, to.pdf = FALSE)
calib |
calibration result as retrieved by
|
to.pdf |
if |
Plot Calibration Result (2)
plotCalibration2(calib, to.pdf = FALSE)
plotCalibration2(calib, to.pdf = FALSE)
calib |
calibration result as retrieved by
|
to.pdf |
if |
Plot the distribution of condition classes by predicted year
plotPrediction( prediction, legend_pos = c("bottom", "left", "top", "right", "none")[5], do_print = TRUE )
plotPrediction( prediction, legend_pos = c("bottom", "left", "top", "right", "none")[5], do_print = TRUE )
prediction |
data frame with columns |
legend_pos |
legend position: one of |
do_print |
logical indicating whether to actually print the plot to the current graphical device. |
prediction <- data.frame( prob1 = c(0, 1, 0, 0.0, 0), prob2 = c(1, 0, 0, 0.5, 0), prob3 = c(0, 0, 0, 0.5, 1), prob4 = c(0, 0, 1, 0.0, 0), pipeLength = 1:5, InspectionYear = seq(2001, 2005) ) kwbGompitz:::plotPrediction(prediction, legend_pos = "right")
prediction <- data.frame( prob1 = c(0, 1, 0, 0.0, 0), prob2 = c(1, 0, 0, 0.5, 0), prob3 = c(0, 0, 0, 0.5, 1), prob4 = c(0, 0, 1, 0.0, 0), pipeLength = 1:5, InspectionYear = seq(2001, 2005) ) kwbGompitz:::plotPrediction(prediction, legend_pos = "right")
Plot prediction by year to temporary PDF file
plotPredictionByYear( prediction, to.pdf = TRUE, FUN.name = "orderByWeightedProbabilities", column.year = "year" )
plotPredictionByYear( prediction, to.pdf = TRUE, FUN.name = "orderByWeightedProbabilities", column.year = "year" )
prediction |
prediction result as provided by e.g.
|
to.pdf |
if |
FUN.name |
name of function to be used to order the matrix of probabilities. Available functions: "orderByWeightedProbabilities", "orderByMostProbClassAndDecreasingProb"; default: "orderByWeightedProbabilities" |
column.year |
name of column containing the year |
Plot Prediction for the given Year
plotPredictionForYear( res, year, FUN.name = "orderByWeightedProbabilities", main = NULL, column.year = "year" )
plotPredictionForYear( res, year, FUN.name = "orderByWeightedProbabilities", main = NULL, column.year = "year" )
res |
prediction result as provided by e.g.
|
year |
year number for which results are to be filtered an plot is to be generated |
FUN.name |
name of function to be used to order the matrix of probabilities. Available functions: "orderByWeightedProbabilities", "orderByMostProbClassAndDecreasingProb"; default: "orderByWeightedProbabilities" |
main |
main title of plot |
column.year |
name of column containing the year |
Prepare data for plot_stacked_bars()
prepare_for_gg_stacked_bars(x, x.sd = NULL)
prepare_for_gg_stacked_bars(x, x.sd = NULL)
x |
numeric vector |
x.sd |
standard deviation |
Print the Calibration for one Stratum
## S3 method for class 'gompitz_stratum_calib' print(x, ...)
## S3 method for class 'gompitz_stratum_calib' print(x, ...)
x |
list of class "gompitz_stratum_calib" as contained in a calibration
object returned by |
... |
further arguments (not used) |
print the Calibration for one Stratum
Print a GompitZ Calibration Structure
## S3 method for class 'gompitz.calibration' print(x, ...)
## S3 method for class 'gompitz.calibration' print(x, ...)
x |
list of class "gompitz.calibration" as returned by
|
... |
further arguments (not used) |
print GompitZ Calibration Structure
Print the Convergence Information
printConvergence(x)
printConvergence(x)
x |
|
Print the convergence information
Read calibration result from given file
readCalibration(file, verbose = 1)
readCalibration(file, verbose = 1)
file |
path to gompcal result file "calibr.txt" |
verbose |
integer number specifying the level of verbosity |
Read Observation Data from File in GompitZ-Format
readObservations(file = exampleFile("obs.txt"), sep = ";", dbg = TRUE)
readObservations(file = exampleFile("obs.txt"), sep = ";", dbg = TRUE)
file |
full path to text file in the format that is required by GompitZ (see "The GompitZ Tool User's Guide") |
sep |
column separator |
dbg |
if |
Read parameters from param.txt into list structure
readParameters(file, sep = ";", dbg = FALSE)
readParameters(file, sep = ";", dbg = FALSE)
file |
full path to parameter file "param.txt", generated by gompcal.exe |
sep |
column separator, default: ";" |
dbg |
if |
list with sections conditions
, /codestrata,
/codecovariates, /codecategoryLevels, /codebyStratum,
Read Prediction Result File
readPredictionFile(file, sep = ";", stringsAsFactors = FALSE)
readPredictionFile(file, sep = ";", stringsAsFactors = FALSE)
file |
full path to prediction result file (predict<n>.txt) with <n> being the strategy number |
sep |
column separator, default: ";" |
stringsAsFactors |
if |
Run calibration example provided with GompitZ
runGompcalExample()
runGompcalExample()
Run gompcal.exe in given Directory
runGompcalInDirectory( target.dir = tempGompitzDir(), input.file = exampleFile("obs.txt"), sep = ";", ... )
runGompcalInDirectory( target.dir = tempGompitzDir(), input.file = exampleFile("obs.txt"), sep = ";", ... )
target.dir |
path to target directory |
input.file |
path to input file |
sep |
column separator |
... |
arguments that are passed to .runModuleInDirectory, such as
|
Perform GompitZ Calibration
runGompitzCalibration( input.data, subset = NULL, verbose = 1, sep = ";", digits = 3, VERSION = getOperatingSystemType() )
runGompitzCalibration( input.data, subset = NULL, verbose = 1, sep = ";", digits = 3, VERSION = getOperatingSystemType() )
input.data |
prepared input data as retrieved by
|
subset |
indexes of rows in |
verbose |
verbosity level |
sep |
column separator |
digits |
round estimates read from calibr.txt and param.txt, respectively, to this number of (significant) digits before comparing them. Default: 3 |
VERSION |
name of subdirectory in package containing the binary files to be executed. Possible values: "unix", "win32", "win32_kwb" |
# For an example, see the Tutorial vignette "How to Use the Package"
# For an example, see the Tutorial vignette "How to Use the Package"
Run Gompitz Predicion
runGompitzPrediction( input.data, subset = NULL, calibration, strategy = 0, ..., verbose = 1, do.stop = TRUE, clear.observations = TRUE, VERSION = getOperatingSystemType(), use.data.table = getOption("kwbGompitz.use.data.table", FALSE) )
runGompitzPrediction( input.data, subset = NULL, calibration, strategy = 0, ..., verbose = 1, do.stop = TRUE, clear.observations = TRUE, VERSION = getOperatingSystemType(), use.data.table = getOption("kwbGompitz.use.data.table", FALSE) )
input.data |
prepared input data as retrieved by
|
subset |
indexes of rows in |
calibration |
result of Gompitz calibration as retrieved by
|
strategy |
strategy identifier. Must be one of 0 (do nothing), 1 (length-driven strategy), 2 (budget-driven strategy), or 3 (optimised strategy).") |
... |
arguments passed to the corresponding
|
verbose |
verbosity level, default: 1 |
do.stop |
if |
clear.observations |
if |
VERSION |
name of subdirectory in package containing the binary files to be executed. Possible values: "unix", "win32", "win32_kwb" |
use.data.table |
if |
# For an example, see the Tutorial vignette "How to Use the Package"
# For an example, see the Tutorial vignette "How to Use the Package"
Run gompred.exe in given Directory
runGompredInDirectory( target.dir = tempdir(), input.file = exampleFile("obs.txt"), sep = ";", strategy = 0, ... )
runGompredInDirectory( target.dir = tempdir(), input.file = exampleFile("obs.txt"), sep = ";", strategy = 0, ... )
target.dir |
path to target directory |
input.file |
path to input file |
sep |
column separator |
strategy |
integer number specifying the strategy to be applied |
... |
arguments that are passed to .runModuleInDirectory, such as
|
Span a Vector around x if Condition is met
spanIf(condition, x, digits = 4)
spanIf(condition, x, digits = 4)
condition |
logical. If |
x |
value around which to span a vector (or not if |
digits |
number of digits to which the values are rounded |
sqrt(2 * pi)
Mathematical Constant sqrt(2 * pi)
SQRT_2_PI
SQRT_2_PI
An object of class numeric
of length 1.
Weibull condition state survival function
standard_survival( alpha, t, bz1, bz0 = 0, offset = t * exp(bz1) + bz0, limits = NULL )
standard_survival( alpha, t, bz1, bz0 = 0, offset = t * exp(bz1) + bz0, limits = NULL )
alpha |
parameter "alpha" |
t |
time |
bz1 |
parameter "bz1" |
bz0 |
parameter "bz0" |
offset |
in order not to recalculate the following expression each time
again, its result can be given here: |
limits |
numeric vector of two elements giving the minimum and maximum
value to which the result shall be restricted. If not given or |
Create the text content for a gompred strategy file
strategyFileContent(strategy, ...)
strategyFileContent(strategy, ...)
strategy |
strategy identifier. Must be one of 0 (do nothing), 1 (length-driven strategy), 2 (budget-driven strategy), or 3 (optimised strategy).") |
... |
arguments passed to the corresponding
|
character vector of length one representing the file content of the strategy file
Aggregate simulated Condition Classes
summary_generic_sim(x, column.group.by, column.length)
summary_generic_sim(x, column.group.by, column.length)
x |
data frame |
column.group.by |
name of column in |
column.length |
name of column in |
Get Values of (Standard or Marginal) Survival Curves
survivals( t = 0:99, alpha, bz1, bz0, s = NULL, marginal = !is.null(s), matrix = TRUE, set_attributes = FALSE, interpol_info = NULL, ... )
survivals( t = 0:99, alpha, bz1, bz0, s = NULL, marginal = !is.null(s), matrix = TRUE, set_attributes = FALSE, interpol_info = NULL, ... )
t |
numeric vector of times (ages) |
alpha |
numeric vector of alpha-parameter(s) |
bz1 |
bz1 parameter |
bz0 |
bz0 parameter |
s |
passed to |
marginal |
if |
matrix |
if |
set_attributes |
if |
interpol_info |
if not |
... |
further arguments passed to |
Get Values of (Standard or Marginal) Survival Curves
survivals_original( t = 0:99, alpha, bz1, bz0, s = NULL, marginal = !is.null(s), matrix = TRUE, set_attributes = FALSE, ... )
survivals_original( t = 0:99, alpha, bz1, bz0, s = NULL, marginal = !is.null(s), matrix = TRUE, set_attributes = FALSE, ... )
t |
numeric vector of times (ages) |
alpha |
numeric vector of alpha-parameter(s) |
bz1 |
bz1 parameter |
bz0 |
bz0 parameter |
s |
passed to |
marginal |
if |
matrix |
if |
set_attributes |
if |
... |
further arguments passed to |
Create temporary gompitz directory
tempGompitzDir(verbose = 1)
tempGompitzDir(verbose = 1)
verbose |
integer value determining the level of verbosity |
Test Marginal Survival
test_marginal_survival(t = 0:99)
test_marginal_survival(t = 0:99)
t |
t (default: 0:99) |
???
Generate ggplot Theme for Legend
to_theme_legend(legend)
to_theme_legend(legend)
legend |
logical indicating whether to put a legend or not or a string giving the legend position ("left", "right", "top", "bottom") |
Convert text lines to status matrix, as e.g. required by
kwb.rsproto::configure
toStatusMatrix(textlines, sep = ";", order_rows = FALSE)
toStatusMatrix(textlines, sep = ";", order_rows = FALSE)
textlines |
vector of character linees as they appear in the GompitZ input file header (only the lines defining the status matrix) |
sep |
column separator. Default: ";" |
order_rows |
if |
## Not run: file <- kwbGompitz::exampleFile("obs.txt") kwbGompitz:::toStatusMatrix(textlines = readLines(file, 8)[-(1:2)]) ## End(Not run)
## Not run: file <- kwbGompitz::exampleFile("obs.txt") kwbGompitz:::toStatusMatrix(textlines = readLines(file, 8)[-(1:2)]) ## End(Not run)
Create a String to be used as an Underline
underline(n = 10, char = "-")
underline(n = 10, char = "-")
n |
number of characters |
char |
character used for the underline |
Write the given character vector into the input file at given path
writeInputFile(textlines, file, verbose = 1)
writeInputFile(textlines, file, verbose = 1)
textlines |
vector of text lines to be written to |
file |
path to the file to be written |
verbose |
integer number specifying the verbosity level. If this is a positive value, debug messages are shown. |
Write Calibration Parameters to File
writeParameters( parameters, file, sep = ";", dbg = TRUE, warn = FALSE, digits_exp = 2L )
writeParameters( parameters, file, sep = ";", dbg = TRUE, warn = FALSE, digits_exp = 2L )
parameters |
list structure containing calibration parameters as
provided by |
file |
full path to file to which parameters are to be written |
sep |
column separator. Default: ";" |
dbg |
if |
warn |
if |
digits_exp |
passed to |