Skip to content

Commit 263d8ca

Browse files
committed
Add methods for filler contrasts
1 parent 0e69976 commit 263d8ca

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

NAMESPACE

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export(contr.hypothesis)
1515
export(eqs2cmat)
1616
export(eqs2hmat)
1717
export(filler_contrasts)
18+
export(filler_names)
1819
export(ginv2)
1920
export(has_intercept)
2021
export(hmat)
@@ -24,10 +25,12 @@ export(hypr)
2425
export(is_centered)
2526
export(is_intercept)
2627
export(remove_intercept)
28+
export(target_names)
2729
export(thmat)
2830
export(which_centered)
2931
export(which_filler)
3032
export(which_intercept)
33+
export(which_target)
3134
exportMethods("&")
3235
exportMethods("*")
3336
exportMethods("+")

R/hypr.R

+33-3
Original file line numberDiff line numberDiff line change
@@ -1183,9 +1183,39 @@ filler_contrasts <- function(x, how.many = nlevels(x), rescale = TRUE) {
11831183
#' @describeIn filler_contrasts Return indices of filler contrasts
11841184
#' @export
11851185
which_filler <- function(x) {
1186-
if(!inherits(x, "hypr")) stop("`x` must be a hypr object!")
1187-
if(!is.null(attr(x@cmat, "which_fillers"))) return(attr(x@cmat, "which_fillers"))
1188-
integer(0)
1186+
if(inherits(x, "hypr") || inherits(x, "hypr_cmat")) {
1187+
cm <- if(inherits(x, "hypr")) cmat(x, add_intercept = FALSE, remove_intercept = FALSE) else x
1188+
if(!is.null(attr(cm, "which_fillers"))) return(attr(cm, "which_fillers"))
1189+
integer(0)
1190+
} else stop("`x` must be a hypr object or hypr cmat!")
1191+
}
1192+
1193+
#' @describeIn filler_contrasts Return indices of filler contrasts
1194+
#' @export
1195+
which_target <- function(x) {
1196+
if(inherits(x, "hypr") || inherits(x, "hypr_cmat")) {
1197+
cm <- if(inherits(x, "hypr")) cmat(x, add_intercept = FALSE, remove_intercept = FALSE) else x
1198+
setdiff(seq_len(ncol(cm)), which_filler(cm))
1199+
} else stop("`x` must be a hypr object or hypr cmat!")
1200+
}
1201+
1202+
1203+
#' @describeIn filler_contrasts Return names of filler contrasts
1204+
#' @export
1205+
filler_names <- function(x) {
1206+
if(inherits(x, "hypr") || inherits(x, "hypr_cmat")) {
1207+
cm <- if(inherits(x, "hypr")) cmat(x, add_intercept = FALSE, remove_intercept = FALSE) else x
1208+
colnames(cm)[which_filler(cm)]
1209+
} else stop("`x` must be a hypr object or hypr cmat!")
1210+
}
1211+
1212+
#' @describeIn filler_contrasts Return names of target contrasts
1213+
#' @export
1214+
target_names <- function(x) {
1215+
if(inherits(x, "hypr") || inherits(x, "hypr_cmat")) {
1216+
cm <- if(inherits(x, "hypr")) cmat(x, add_intercept = FALSE, remove_intercept = FALSE) else x
1217+
colnames(cm)[-which_filler(cm)]
1218+
} else stop("`x` must be a hypr object or hypr cmat!")
11891219
}
11901220

11911221

man/filler_contrasts.Rd

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)