Title: | Collection of Scripts for Interface Between 'Cornerstone' and 'R' |
---|---|
Description: | Collection of generic 'R' scripts which enable you to use existing 'R' routines in 'Cornerstone'. The desktop application 'Cornerstone' (<https://www.camline.com/en/products/cornerstone/cornerstone-core.html>) is a data analysis software provided by 'camLine' that empowers engineering teams to find solutions even faster. The engineers incorporate intensified hands-on statistics into their projects. They benefit from an intuitive and uniquely designed graphical Workmap concept: you design experiments (DoE) and explore data, analyze dependencies, and find answers you can act upon, immediately, interactively, and without any programming. While 'Cornerstone's' interface to the statistical programming language 'R' has been available since version 6.0, the latest interface with 'R' is even much more efficient. 'Cornerstone' release 7.1.1 allows you to integrate user defined 'R' packages directly into the standard 'Cornerstone' GUI. Your engineering team stays in 'Cornerstone's' graphical working environment and can apply 'R' routines, immediately and without the need to deal with programming code. Additionally, your 'R' programming team develops corresponding 'R' packages detached from 'Cornerstone' in their favorite 'R' environment. Learn how to use 'R' packages in 'Cornerstone' 7.1.1 on 'camLineTV' YouTube channel (<https://www.youtube.com/watch?v=HEQHwq_laXU>) (available in German). |
Authors: | Gerrith Djaja [aut, cre], Dirk Surmann [aut] |
Maintainer: | Gerrith Djaja <[email protected]> |
License: | GPL-3 |
Version: | 2.0.2 |
Built: | 2024-12-14 06:50:48 UTC |
Source: | CRAN |
Collection of generic 'R' scripts which enable you to use existing 'R' routines in 'Cornerstone'.
The desktop application 'Cornerstone' (<https://www.camline.com/en/products/cornerstone/cornerstone-core.html>) is a data analysis software provided by 'camLine' that empowers engineering teams to find solutions even faster. The engineers incorporate intensified hands-on statistics into their projects. They benefit from an intuitive and uniquely designed graphical Workmap concept: you design experiments (DoE) and explore data, analyze dependencies, and find answers you can act upon, immediately, interactively, and without any programming.
While 'Cornerstone's' interface to the statistical programming language 'R' has been available since version 6.0, the latest interface with 'R' is even much more efficient. 'Cornerstone' release 7.1.1 allows you to integrate user defined 'R' packages directly into the standard 'Cornerstone' GUI. Your engineering team stays in 'Cornerstone's' graphical working environment and can apply 'R' routines, immediately and without the need to deal with programming code. Additionally, your 'R' programming team develops corresponding 'R' packages detached from 'Cornerstone' in their favorite 'R' environment.
Learn how to use 'R' packages in 'Cornerstone' 7.1.1 on 'camLineTV' YouTube channel (<https://www.youtube.com/watch?v=HEQHwq_laXU>) (available in German).
Maintainer: Gerrith Djaja [email protected]
Authors:
Dirk Surmann [email protected] (ORCID)
Useful links:
Report bugs at https://gitlab.com/camLine/CornerstoneR/-/issues
Dataset of different cars and various values.
A data.table
object with 406 observations and 9 variables.
The variables and their scale of measurement are as follows:
Model: nominal
Origin: nominal
MPG: interval
Cylinders: ordinal
Displacement: interval
Horsepower: interval
Weight: interval
Acceleration: interval
Model.Year: interval
Cornerstone sample dataset
Fit predefined functions to data via nonlinear least squares using Levenberg-Marquardt
algorithm via nlsLM
.
fitFunction( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), groups = cs.in.groupvars(), auxs = cs.in.auxiliaries(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
fitFunction( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), groups = cs.in.groupvars(), auxs = cs.in.auxiliaries(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
dataset |
[ |
preds |
[ |
resps |
[ |
groups |
[ |
auxs |
[ |
scriptvars |
[ |
return.results |
[ |
... |
[ANY] |
The following script variables are summarized in scriptvars
list:
[character(1)
]
Function selection for fitting data. It is possible to choose a predefined model, or
compose a model manually by selecting User Defined
.
Default is User Defined
[character(1)
]
Required if math.fun
is set to User Defined
.
Valid R formula
for the right hand side (predictors) of the model equation.
[character(1)
]
Required if math.fun
is set to User Defined
.
Valid R formula
for the left hand side (response) of the model equation.
[character(1)
]
Optional if math.fun
is set to User Defined
.
Specifies minimum and maximum value for function math.fun
as a comma separated list
of min
and max
.
It is possible to assign variables, e.g. min=a
, which need start values in
start.vals
, as well as real numbers, e.g. min=4.5
, with a period as decimal
separator.
[character(1)
]
Required if math.fun
is set to User Defined
.
Specify starting values for all terms of the right hand side as a comma separated list
with a period as decimal separator.
[character(1)
]
Select a weighting variable from the auxiliary variables.
Maximum number of iterations.
For details see link[minpack.lm]{nls.lm.control}
Maximum relative error desired in the sum of squares. If 0
,
the default is used.
For details see link[minpack.lm]{nls.lm.control}
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
objects:
coeff |
Estimated coefficients and standard errors for each group.
Convergence information is available for every group (for details see
|
vcov |
Variance-Covariance matrix of the main coefficients for the fitted model of each
group (for details see |
predictions |
Dataset to brush with predictions and residuals added to original values and groups, if available. |
# Generate data from logistic function: fun = function(x, a, b, c, d, sigma = 1) { a+(b-a) / (1+exp(-d*(x-c))) + rnorm(length(x), sd = sigma) } library(data.table) dt = data.table( x1 = sample(seq(-10, 10, length.out = 100)) , group1 = sample(x = c("A", "B"), replace = TRUE, size = 100) ) dt[group1 == "A", y1 := fun(x1, 1, 10, 1, 0.6, 0.1)] dt[group1 == "B", y1 := fun(x1, 8, 2, -1, 0.3, 0.1)] # Set script variables scriptvars = list(math.fun = "Logistic", resp.frml = "", preds.frml = "", limits = "" , start.vals = "", weights = "", max.iter = 50, max.ftol = 0 ) # Fit the logistic function: res = fitFunction(dt, "x1", "y1", "group1", character(0), scriptvars, TRUE) # Show estimated coefficients: res$coeff # Variance-Covariance matrix: res$vcov # Plot fitted vs. residuals: plot(res$predictions$Fitted, res$predictions$Residuals)
# Generate data from logistic function: fun = function(x, a, b, c, d, sigma = 1) { a+(b-a) / (1+exp(-d*(x-c))) + rnorm(length(x), sd = sigma) } library(data.table) dt = data.table( x1 = sample(seq(-10, 10, length.out = 100)) , group1 = sample(x = c("A", "B"), replace = TRUE, size = 100) ) dt[group1 == "A", y1 := fun(x1, 1, 10, 1, 0.6, 0.1)] dt[group1 == "B", y1 := fun(x1, 8, 2, -1, 0.3, 0.1)] # Set script variables scriptvars = list(math.fun = "Logistic", resp.frml = "", preds.frml = "", limits = "" , start.vals = "", weights = "", max.iter = 50, max.ftol = 0 ) # Fit the logistic function: res = fitFunction(dt, "x1", "y1", "group1", character(0), scriptvars, TRUE) # Show estimated coefficients: res$coeff # Variance-Covariance matrix: res$vcov # Plot fitted vs. residuals: plot(res$predictions$Fitted, res$predictions$Residuals)
CS-R interface functions are defined in package namespace via this file. Each function overwrites itself with the corresponding counterpart defined in the global environment from CS.
invokeFromR() cs.in.auxiliaries(quote = FALSE) cs.in.brushed() cs.in.dataset() cs.in.excluded() cs.in.groupvars(quote = FALSE) cs.in.predictors(quote = FALSE) cs.in.responses(quote = FALSE) cs.in.Robject(name = NA) cs.in.scriptvars(name = NA) cs.in.subsets() cs.in.subsets.current() cs.quote(x) cs.out.dataset(data, name = NA, brush = FALSE) cs.out.emf(name = NULL, width = 10, height = 10) cs.out.png(name = NULL, width = 480, height = 480) cs.out.Robject(R_object, name = NA)
invokeFromR() cs.in.auxiliaries(quote = FALSE) cs.in.brushed() cs.in.dataset() cs.in.excluded() cs.in.groupvars(quote = FALSE) cs.in.predictors(quote = FALSE) cs.in.responses(quote = FALSE) cs.in.Robject(name = NA) cs.in.scriptvars(name = NA) cs.in.subsets() cs.in.subsets.current() cs.quote(x) cs.out.dataset(data, name = NA, brush = FALSE) cs.out.emf(name = NULL, width = 10, height = 10) cs.out.png(name = NULL, width = 480, height = 480) cs.out.Robject(R_object, name = NA)
quote |
[ |
name |
[ |
x |
[ |
data |
[ |
brush |
[ |
width |
[ |
height |
[ |
R_object |
[ |
Match the nearest neighbor from a redirected Cornerstone Robject
dataset
(redirectDataset
) to corresponding selected predictor variables.
Predictor variables from both datasets are supposed to be numeric to apply the Euclidean
distance calculated by dist2
.
The function returns a dataset with the nearest neighbor to every observation, matched by
the predictor variables.
Available response, group, and auxiliary variables from the redirected datasets are passed
through, as well as, selected auxiliary variables.
The calculated distance is attached.
matchNearestNeighbor( dataset = cs.in.dataset(), preds = cs.in.predictors(), auxs = cs.in.auxiliaries(), robject = cs.in.Robject(), return.results = FALSE )
matchNearestNeighbor( dataset = cs.in.dataset(), preds = cs.in.predictors(), auxs = cs.in.auxiliaries(), robject = cs.in.Robject(), return.results = FALSE )
dataset |
[ |
preds |
[ |
auxs |
[ |
robject |
[ |
return.results |
[ |
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
objects:
nearest.neighbor |
Matched nearest neighbor which consists of predictor and available response, group, and auxiliary variables. The calculated distance is attached to this dataset. |
runtimes |
Run times for every input R object. |
Plots (extended) mosaic displays via mosaic
.
The last response variable is highlighted.
A high-dimensional contingency table is calculated via structable
from the given dataset.
Flat contingency table splits predictors horizontally and optional responses vertically.
mosaicPlot( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), return.results = FALSE, ... )
mosaicPlot( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), return.results = FALSE, ... )
dataset |
[ |
preds |
[ |
resps |
[ |
return.results |
[ |
... |
[ANY] |
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
objects:
long.contingency |
Contingency table in long format. |
# Draw mosaic plot from 'titanic' data: mosaicPlot(titanic, c("Class", "Age", "Sex", "Survived")) res = mosaicPlot(titanic, c("Class", "Age"), c("Sex", "Survived"), return.results = TRUE) print(res)
# Draw mosaic plot from 'titanic' data: mosaicPlot(titanic, c("Class", "Age", "Sex", "Survived")) res = mosaicPlot(titanic, c("Class", "Age"), c("Sex", "Survived"), return.results = TRUE) print(res)
Random Forest via ranger
. Predicts response variables or brushed set of
rows from predictor variables, using Random Forest classification or regression.
randomForest( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), brush = cs.in.brushed(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
randomForest( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), brush = cs.in.brushed(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
dataset |
[ |
preds |
[ |
resps |
[ |
brush |
[ |
scriptvars |
[ |
return.results |
[ |
... |
[ANY] |
The following script variables are summarized in scriptvars
list:
[logical(1)
]
Use brush
vector as additional predictor.
Default is FALSE
.
[character(1)
]
Rows to use in model fit. Possible values are all
, non-brushed
, or
brushed
.
Default is all
.
[integer(1)
]
Number of trees to fit in ranger
.
Default is 500
.
[character(1)
]
Variable importance mode. For details see ranger
.
Default is permutation
.
[character(1)
]
Handling of unordered factor covariates. For details see ranger
.
Default is NULL
.
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
objects:
statistics |
General statistics about the random forest. |
importances |
Variable importance of prediction variables in descending order of importance (most important first) |
predictions |
Dataset to brush with predicted values for |
confusion |
For categorical response variables or brush state only. A table with counts of each distinct combination of predicted and actual values. |
rgobjects |
List of |
# Fit random forest to iris data: res = randomForest(iris, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"), "Species" , scriptvars = list(brush.pred = FALSE, use.rows = "all", num.trees = 500 , importance.mode = "permutation" , respect.unordered.factors = "ignore" ) , brush = rep(FALSE, nrow(iris)), return.results = TRUE ) # Show general statistics: res$statistics # Prediction randomForestPredict(iris[, 1:4], c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width") , robject = res$rgobjects , return.results = TRUE )
# Fit random forest to iris data: res = randomForest(iris, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"), "Species" , scriptvars = list(brush.pred = FALSE, use.rows = "all", num.trees = 500 , importance.mode = "permutation" , respect.unordered.factors = "ignore" ) , brush = rep(FALSE, nrow(iris)), return.results = TRUE ) # Show general statistics: res$statistics # Prediction randomForestPredict(iris[, 1:4], c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width") , robject = res$rgobjects , return.results = TRUE )
Random Forest prediction via predict.ranger
. Predicts response variables
from predictor variables, using ranger
objects. All ranger
objects have to work
on the same set of prediction variables. These variables are exactly available in the
prediction dataset. A response is not necessary, it will be predicted via this function.
randomForestPredict( dataset = cs.in.dataset(), preds = cs.in.predictors(), robject = cs.in.Robject(), return.results = FALSE, ... )
randomForestPredict( dataset = cs.in.dataset(), preds = cs.in.predictors(), robject = cs.in.Robject(), return.results = FALSE, ... )
dataset |
[ |
preds |
[ |
robject |
[ |
return.results |
[ |
... |
[ANY] |
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
objects:
predictions |
Dataset to brush with predicted values for |
Redirect input dataset to an output R object.
redirectDataset( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), groups = cs.in.groupvars(), auxs = cs.in.auxiliaries(), scriptvars = cs.in.scriptvars(), return.results = FALSE )
redirectDataset( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), groups = cs.in.groupvars(), auxs = cs.in.auxiliaries(), scriptvars = cs.in.scriptvars(), return.results = FALSE )
dataset |
[ |
preds |
[ |
resps |
[ |
groups |
[ |
auxs |
[ |
scriptvars |
[ |
return.results |
[ |
The following script variables are summarized in scriptvars
list:
[character(1)
]
The given pattern is removed in all variable names via gsub
.
Leading and / or trailing whitespaces are removed using trimws
.
Default is ""
.
Logical [TRUE
] invisibly and outputs to Cornerstone cs.out.Robject
or,
if return.results = TRUE
, list
of resulting
data.frame
objects and character(n)
vectors:
dataset |
Input dataset. |
predictors |
Vector of predictors. |
responses |
Vector of responses. |
groups |
Vector of groups. |
auxiliaries |
Vector of auxiliaries. |
The list
is wrapped in an additional list
to get the same return value
corresponding to cs.in.Robject
.
Reshaping grouped data via melt
to 'long' format. The
responses are merged in one column, with its column name in an additional column.
This column is split into multiple columns, if a split character is given.
All predictors are merged multiple times corresponding to the number or responses.
reshapeLong( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
reshapeLong( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
dataset |
[ |
preds |
[ |
resps |
[ |
scriptvars |
[ |
return.results |
[ |
... |
[ANY] |
One script variables is summarized in scriptvars
list:
[character(1)
]
Split character to split response names into multiple columns. Default is “_”.
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
object:
reshapeLong |
Dataset with reshaped data. |
# Data to transform: library(data.table) dtTest = data.table(i_1 = c(1:4, NA, 5), i_2 = c(51, 61, NA , 71, 81, 91) , f1 = factor(sample(c(letters[1:3], NA), 6, TRUE)) , f2 = factor(c("z", "a", "x", "c", "x", "x"), ordered = TRUE) ) # Reshape to long format: reshapeLong(dtTest, c("i_1", "i_2"), c("f1", "f2"), list(split = "_"), return.results = TRUE)
# Data to transform: library(data.table) dtTest = data.table(i_1 = c(1:4, NA, 5), i_2 = c(51, 61, NA , 71, 81, 91) , f1 = factor(sample(c(letters[1:3], NA), 6, TRUE)) , f2 = factor(c("z", "a", "x", "c", "x", "x"), ordered = TRUE) ) # Reshape to long format: reshapeLong(dtTest, c("i_1", "i_2"), c("f1", "f2"), list(split = "_"), return.results = TRUE)
Transpose data via transpose
.
All predictors, responses, groups, and auxiliaries are transpose.
reshapeTranspose( dataset = cs.in.dataset(), groups = cs.in.groupvars(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
reshapeTranspose( dataset = cs.in.dataset(), groups = cs.in.groupvars(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
dataset |
[ |
groups |
[ |
scriptvars |
[ |
return.results |
[ |
... |
[ANY] |
One script variables is summarized in scriptvars
list:
[character(1)
]
Split character to split response names into multiple columns. Default is “_”.
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
object:
reshapeTranspose |
Dataset with transposed data. |
# Data to transform: library(data.table) dtTest = data.table(i_1 = c(1:4, NA, 5), i_2 = c(51, 61, NA , 71, 81, 91)) # Reshape to long format: reshapeTranspose(dtTest, groups = character(0), list(convert.numeric = TRUE), return.results = TRUE)
# Data to transform: library(data.table) dtTest = data.table(i_1 = c(1:4, NA, 5), i_2 = c(51, 61, NA , 71, 81, 91)) # Reshape to long format: reshapeTranspose(dtTest, groups = character(0), list(convert.numeric = TRUE), return.results = TRUE)
Reshaping grouped data via dcast
to 'wide' format with
rows for each unique combination of group variables. The response are arranged in
separate columns for each datum in predictors. If a combination of groups identifies
multiple rows, the number of rows in a group is returned to CS for the whole dataset
instead of the response variable value.
reshapeWide( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), groups = cs.in.groupvars(), auxs = cs.in.auxiliaries(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
reshapeWide( dataset = cs.in.dataset(), preds = cs.in.predictors(), resps = cs.in.responses(), groups = cs.in.groupvars(), auxs = cs.in.auxiliaries(), scriptvars = cs.in.scriptvars(), return.results = FALSE, ... )
dataset |
[ |
preds |
[ |
resps |
[ |
groups |
[ |
auxs |
[ |
scriptvars |
[ |
return.results |
[ |
... |
[ANY] |
One script variables is summarized in scriptvars
list:
[logical(1)
]
Drop missing combinations (TRUE
) or include all (FALSE
).
Default is TRUE
.
For details see dcast
.
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
object:
reshapeWide |
Dataset with reshaped data. |
# Reshape dataset to wide format: reshapeWide(Indometh, "time", "conc", "Subject", character(0) , list(drop = TRUE, aggr.fun = "mean"), return.results = TRUE )
# Reshape dataset to wide format: reshapeWide(Indometh, "time", "conc", "Subject", character(0) , list(drop = TRUE, aggr.fun = "mean"), return.results = TRUE )
The datasets contains 26 different runs in each case measuring the voltage over time. The S-shaped curves are different for each run.
A data.table
object with 7826 observations and 3 variables.
The discrete variable 'FileName' has 26 levels corresponding to the file name of the source data
from Cornerstone. The remaining other two variables are continuous.
Cornerstone sample dataset
Write the versions of R and CornerstoneR in a Cornerstone dataset.
showVersions(return.results = FALSE)
showVersions(return.results = FALSE)
return.results |
[ |
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
objects:
versions |
Dataset with versions of R and CornerstoneR. |
res = showVersions(return.results = TRUE) res$versions
res = showVersions(return.results = TRUE) res$versions
This data set provides information on the fate of passengers on the fatal maiden voyage of the ocean liner Titanic, summarized according to economic status (Class), Age, Sex, and Survival.
A data.table
object with 2201 observations and 4 variables.
The discrete variables and their levels are as follows:
Class: 1st, 2nd, 3rd, Crew
Age: Child, Adult
Sex: Male, Female
Survived: Yes, No
Cornerstone sample dataset
Dawson, Robert J. MacG. (1995), The Unusual Episode Data Revisited. Journal of Statistics Education, 3. http://jse.amstat.org/v3n3/datasets.dawson.html