Title: | Helper functions for repgames and dyngames |
---|---|
Description: | Helper functions needed by my package repgames and dyngames |
Authors: | Sebastian Kranz |
Maintainer: | Sebastian Kranz <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1 |
Built: | 2024-11-14 03:58:29 UTC |
Source: | https://github.com/skranz/skUtils |
Add a vector v to each row of m
add.rowvec(m, v)
add.rowvec(m, v)
APPROXEQ Are a and b approximately equal (to within a specified tolerance)? p = approxeq(a, b, thresh) 'tol' defaults to 1e-3.
approxeq(a, b, tol = 0.001)
approxeq(a, b, tol = 0.001)
Assigns all columns of df into variables with the same name in environment env
assign.cols(df, dest = sys.frame(sys.parent(1)))
assign.cols(df, dest = sys.frame(sys.parent(1)))
Calculate numerically the expected value given a cdf
calc.mean.from.F.fun(F.fun, x.min = 0, x.max = Inf, abs.tol = 10^(-10), x.seq = NULL, use.num.integrate = TRUE, ...)
calc.mean.from.F.fun(F.fun, x.min = 0, x.max = Inf, abs.tol = 10^(-10), x.seq = NULL, use.num.integrate = TRUE, ...)
Some functions that are useful for coding Looks through all loaded functions and searches for global variables that are used within the functions this is a common source for errors
check.global.vars()
check.global.vars()
Clones an environment and its children
clone.environment(env, made.clones = as.environment(list(org = list(), copy = list())), clone.parents = TRUE, clone.global = FALSE, exclude = NULL, clone.children = TRUE)
clone.environment(env, made.clones = as.environment(list(org = list(), copy = list())), clone.parents = TRUE, clone.global = FALSE, exclude = NULL, clone.children = TRUE)
Generates a matrix in which all cols are equal to col
col.matrix(row = NULL, col, ncol = length(row), dim = 2)
col.matrix(row = NULL, col, ncol = length(row), dim = 2)
Computes quickly the maxima of each column of a matrix
colMaxs(mat)
colMaxs(mat)
Computes quickly the minima of each column of a matrix
colMins(mat)
colMins(mat)
Copies an environment
copy.env(dest = sys.frame(sys.parent(1)), source = sys.frame(sys.parent(1)), names = NULL, name.change = NULL, exclude = NULL)
copy.env(dest = sys.frame(sys.parent(1)), source = sys.frame(sys.parent(1)), names = NULL, name.change = NULL, exclude = NULL)
Helper function to discretize a continous distribution. F.vec is a finite vector containing the value of the cdf at M different points. The function generates an M dimension vector of probabilities summing up to 1 that discretize the distribution
discretize.given.F.vec(F.vec)
discretize.given.F.vec(F.vec)
Finds position where the function f becomes zero First tries find.root and if this fails tries optimize
findzero(f, lower, upper, tol = .Machine$double.eps * 10, result.tol = tol, try.uniroot = TRUE, ...)
findzero(f, lower, upper, tol = .Machine$double.eps * 10, result.tol = tol, try.uniroot = TRUE, ...)
Gives the corresponding rows for a permutated grid.matrix given a permutation x.perm of the elements of the original list x
grid.matrix.permutation(x, perm.col)
grid.matrix.permutation(x, perm.col)
Transforms a grid in long format into a matrix
grid.to.matrix(grid, nrow = length(unique(grid[, 1])), ncol = length(unique(grid[, 2])), val.col = 3)
grid.to.matrix(grid, nrow = length(unique(grid[, 1])), ncol = length(unique(grid[, 2])), val.col = 3)
List all functions
ls.funs(env = sys.frame(-1))
ls.funs(env = sys.frame(-1))
List all variables
ls.vars(env = sys.frame(-1))
ls.vars(env = sys.frame(-1))
Some functions that are useful for manipulating or creating matrices and data.frames and working with lists of vectors, lists of lists or lists of matrices Transforms a matrix into grid in long format
matrix.to.grid(mat, x = 1:NROW(mat), y = 1:NCOL(mat), x.name = "x", y.name = "y")
matrix.to.grid(mat, x = 1:NROW(mat), y = 1:NCOL(mat), x.name = "x", y.name = "y")
Some functions that are useful for lists and environments in particular generating, transforming, copying and assigning values Creates a list that is named by the names of its arguments
named.list(...)
named.list(...)
Paste together columns of a matrix or data.frame
paste.matrix.cols(mat, cols = 1:NCOL(mat), ...)
paste.matrix.cols(mat, cols = 1:NCOL(mat), ...)
Paste together rows of a matrix or data.frame
paste.matrix.rows(mat, rows = 1:NROW(mat), ...)
paste.matrix.rows(mat, rows = 1:NROW(mat), ...)
Plot several lines
## S3 method for class 'multi.lines' plot(mat = NULL, xvar, yvar, ynames = yvar, col = NULL, ylim = NULL, xlab = xvar, ylab = "", legend.pos = NULL, legend.title = NULL, add = FALSE, lwd = 1, ...)
## S3 method for class 'multi.lines' plot(mat = NULL, xvar, yvar, ynames = yvar, col = NULL, ylim = NULL, xlab = xvar, ylab = "", legend.pos = NULL, legend.title = NULL, add = FALSE, lwd = 1, ...)
rbinds a list of matrices, a list of lists, or a list of vectors into a data.frame (or matrix) each column is a list Assume that all columns in the sublists are in the same order
rbind.list(li, cols = NULL, check.common.cols = FALSE)
rbind.list(li, cols = NULL, check.common.cols = FALSE)
Generates a matrix in which all rows are equal to row
row.matrix(row, col, nrow = length(col), dim = 1)
row.matrix(row, col, nrow = length(col), dim = 1)
Computes quickly the minima of each row of a matrix
rowMaxs(mat)
rowMaxs(mat)
Computes quickly the minima of each row of a matrix
rowMins(mat)
rowMins(mat)
Need to check what it does
set.default(env, name, x, overwrite.null = TRUE, inherits = TRUE)
set.default(env, name, x, overwrite.null = TRUE, inherits = TRUE)
My wrapper to the lattice function levelplot. Allows for some own color schemes The parameter focus specifies at which z range stronger color changes shall appear
sk.levelplot(x = NULL, y = NULL, z = NULL, xnames = NULL, ynames = NULL, grid.xyz = NULL, col.scheme = "darkredgreen", na.col = NULL, at = NULL, at.scheme = "interval", focus = 0, cuts = 15, col.regions = NULL, xlab = NULL, ylab = NULL, panel = panel.levelplot, zlim = NULL, reverse.colors = FALSE, ...)
sk.levelplot(x = NULL, y = NULL, z = NULL, xnames = NULL, ynames = NULL, grid.xyz = NULL, col.scheme = "darkredgreen", na.col = NULL, at = NULL, at.scheme = "interval", focus = 0, cuts = 15, col.regions = NULL, xlab = NULL, ylab = NULL, panel = panel.levelplot, zlim = NULL, reverse.colors = FALSE, ...)
A wrapper for optimization. Allows to specify which variables shall be free Has the same syntax for one and multidimensional optmization Uses optim, omptimize or a grid search
sk.optim(par, f, lower = NULL, upper = NULL, free.par = 1:NROW(par), method = "default", num.grid.steps = NULL, maximize = TRUE, f.can.take.matrix = FALSE, tol = .Machine$double.eps^0.25, ...)
sk.optim(par, f, lower = NULL, upper = NULL, free.par = 1:NROW(par), method = "default", num.grid.steps = NULL, maximize = TRUE, f.can.take.matrix = FALSE, tol = .Machine$double.eps^0.25, ...)
Calculates the 2dimensional paretofrontier of the points val1 and val2 The function returns the indices of the points that lie on the Pareto Frontier ordered by val1 and val2.
sk.pareto.frontier(val1, val2, tol = 0, ord = NULL)
sk.pareto.frontier(val1, val2, tol = 0, ord = NULL)
Computes quickly the index of the largest element of each column of a matrix
which.colMaxs(mat)
which.colMaxs(mat)
Computes quickly the index of the smallest element of each column of a matrix
which.colMins(mat)
which.colMins(mat)
Computes quickly the index of the largest element of each row of a matrix
which.rowMaxs(mat)
which.rowMaxs(mat)
Computes quickly the index of the smallest element of each row of a matrix
which.rowMins(mat)
which.rowMins(mat)