conf.design (version 2.0.0)

factorize: S3 generic function and methods for factorization.

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

"factorize"(x, divisors = primes(max(x)), ...) "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.)

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.

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.

See Also

conf.design, join

Examples

Run this code
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

Run the code above in your browser using DataCamp Workspace