Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

moffset

Matrix Offset


Description

Modify a matrix by shifting successive elements.

Usage

moffset(mat, roffset = 0, coffset = 0, postfix = "",
        rprefix = "Row.", cprefix = "Col.")

Arguments

mat

Data frame or matrix. This ought to have at least three rows and three columns. The elements are shifted in the order of c(mat), i.e., going down successive columns, as the columns go from left to right. Wrapping of values is done.

roffset, coffset

Numeric or character. If numeric, the amount of shift (offset) for each row and column. The default is no change to mat. If character, the offset is computed by matching with the row or column names. For example, for the alcoff, put roffset = "6" means that we make an effective day's dataset start from 6:00 am, and this wraps around to include midnight to 05.59 am on the next day.

postfix

Character. Modified rows and columns are renamed by pasting this argument to the end of each name. The default is no change.

rprefix, cprefix

Same as rcim.

Details

This function allows a matrix to be rearranged so that element (roffset + 1, coffset + 1) becomes the (1, 1) element. The elements are assumed to be ordered in the same way as the elements of c(mat),

This function is applicable to, e.g., alcoff, where it is useful to define the effective day as starting at some other hour than midnight, e.g., 6.00am. This is because partying on Friday night continues on into Saturday morning, therefore it is more interpretable to use the effective day when considering a daily effect.

This is a data preprocessing function for rcim and plotrcim0. The differences between Rcim and moffset is that Rcim only reorders the level of the rows and columns so that the data is shifted but not moved. That is, a value in one row stays in that row, and ditto for column. But in moffset values in one column can be moved to a previous column. See the examples below.

Value

A matrix of the same dimensional as its input.

Note

The input mat should have row names and column names.

Author(s)

T. W. Yee, Alfian F. Hadi.

See Also

Examples

moffset(alcoff, 3, 2, "*")  # Some day's data is moved to previous day.
Rcim(alcoff, 3 + 1, 2 + 1)  # Data does not move as much.
alcoff  # Original data
moffset(alcoff, 3, 2, "*") - Rcim(alcoff, 3+1, 2+1)  # Note the differences

# An 'effective day' data set:
alcoff.e <- moffset(alcoff, roffset = "6", postfix = "*")
fit.o <- rcim(alcoff)    # default baselines are first row and col
fit.e <- rcim(alcoff.e)  # default baselines are first row and col

## Not run:  par(mfrow = c(2, 2), mar = c(9, 4, 2, 1))
plot(fit.o, rsub = "Not very interpretable", csub = "Not very interpretable")
plot(fit.e, rsub = "More interpretable", csub = "More interpretable")

## End(Not run)

# Some checking
all.equal(moffset(alcoff), alcoff)  # Should be no change
moffset(alcoff, 1, 1, "*")
moffset(alcoff, 2, 3, "*")
moffset(alcoff, 1, 0, "*")
moffset(alcoff, 0, 1, "*")
moffset(alcoff, "6", "Mon", "*")  # This one is good

# Customise row and column baselines
fit2 <- rcim(Rcim(alcoff.e, rbaseline = "11", cbaseline = "Mon*"))

VGAM

Vector Generalized Linear and Additive Models

v1.1-5
GPL-3
Authors
Thomas Yee [aut, cre], Cleve Moler [ctb] (author of several LINPACK routines)
Initial release
2021-01-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.