factorize: S3 generic function and methods for factorization.

Description Usage Arguments Details Value Side Effects See Also Examples

View source: R/conf.design.R

Description

The default method factorizes positive numeric integer arguments, returning a vector of prime factors. The factor method can be used to generate pseudo-factors. It accepts a factor, f, as principal argument and returns a data frame with factors fa, fb, ... each with a prime number of levels such that f is model equivalent to join(fa, fb, ...).

Usage

1
2
3
4
5
## Default S3 method:
factorize(x, divisors = primes(max(x)), ...)
## S3 method for class 'factor'
factorize(x, name = deparse(substitute(x)), extension =
letters, ...)

Arguments

x

Principal argument.

The default method factorizes (smallish) positive integers;

The factor method generates prime pseudo-factors from a factor with a composite number of levels (as required for partial confounding).

divisors

Candidate prime divisors for all numers to be factorized.

name

Stem of the name to be given to component pseudo-factors.

extension

Distinguishing strings to be added to the stem to nominate the pseudo-factors.

...

Additional arguments, if any. (Presently ignored.)

Details

Primarily intended to split a factor with a non-prime number of levels into a series of pseudo-factors, each with a prime number of levels and which jointly define the same classes as the factor itself.

The main reason to do this would be to confound one or more of the pseudo-factors, or their interactions, with blocks using constructions that only apply for prime numbers of levels. In this way the experiment can be made smaller, at the cost of some treatment contrasts being confounded with blocks.

The default method factorizes integers by a clumsy, though effective enough way for small integers. The function is vectorized in the sense that if a vector of integers to factorize is specified, the object returned is a list of numeric vectors, giving the prime divisors (including repeats) of the given integers respectively.

As with any method of factorizing integers, it may become very slow if the prime factors are large.

Value

For the default method a vector, or list of vectors, of prime integer divisors of the components of x, (including repeats).

For the factor method, a design with factors having prime numbers of levels for factor arguments.

Side Effects

None.

See Also

conf.design, join

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
factorize(12321)
### [1]  3  3 37 37

f <- factor(1:6)
data.frame(f, factorize(f))
###   f fa fb
### 1 1  0  0
### 2 2  1  0
### 3 3  0  1
### 4 4  1  1
### 5 5  0  2
### 6 6  1  2

des <- with(list(f = factor(rep(6:1, 1:6))),
            data.frame(f, factorize(f)))
head(des, 7)
##   f fa fb
## 1 6  1  2
## 2 5  0  2
## 3 5  0  2
## 4 4  1  1
## 5 4  1  1
## 6 4  1  1
## 7 3  0  1

conf.design documentation built on May 2, 2019, 4:02 p.m.