as.top_ordering: Coercion into top-ordering datasets

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/PLMIXfunctions.R

Description

Attempt to coerce the input data into a top-ordering dataset.

Usage

1
2
as.top_ordering(data, format_input = NULL, aggr = NULL,
  freq_col = NULL, ties_method = "random", ...)

Arguments

data

An object containing the partial sequences to be coerced into an object of class top_ordering. The following classes are admissible for data: numeric matrix, data.frame, RandData from the rankdist package and rankings from the PlackettLuce package.

format_input

Character string indicating the format of the data input, namely "ordering" or "ranking". Used only when the class of the data argument is matrix or data frame. Default is NULL.

aggr

Logical: whether the data argument collects the distinct observed sequences with the corresponding frequencies (aggregated format). Used only when the class of the data aargument is matrix or data frame. Default is NULL.

freq_col

Integer indicating the column of the data argument containing the frequencies of the distinct observed sequences. Used only when the class of the data argument is matrix or data frame and aggr argument is TRUE. Default is NULL.

ties_method

Character string indicating the treatment of sequences with ties (not used for data of class RankData). If "remove", the sequences with ties are removed before acting the coercion; if "random" (default), tied positions are re-assigned at random before acting the coercion.

...

Further arguments passed to or from other methods (not used).

Details

The coercion function as.top_ordering tries to coerce the input data into an object of class top_ordering after checking for possible partial sequences that do not satisfy the top-ordering requirements. If none of the supplied sequences satisfies the top-ordering conditions, an error message is returned. NA's in the input data are tacitly converted into zero entries.

Value

An object of S3 class c("top_ordering","matrix").

Author(s)

Cristina Mollica and Luca Tardella

References

Turner, H., Kormidis, I. and Firth, D. (2018). PlackettLuce: Plackett-Luce Models for Rankings. R package version 0.2-3. https://CRAN.R-project.org/package=PlackettLuce

Qian, Z. (2018). rankdist: Distance Based Ranking Models. R package version 1.1.3. https://CRAN.R-project.org/package=rankdist

See Also

is.top_ordering, as.rankings and rankings

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
25
26
27
28
29
30
31
## Coerce an object of class 'rankings' into an object of class 'top_ordering'
library(PlackettLuce)
RR <- matrix(c(1, 2, 0, 0,
4, 1, 2, 3,
2, 1, 1, 1,
1, 2, 3, 0,
2, 1, 1, 0,
1, 0, 3, 2), nrow = 6, byrow = TRUE) 
RR_rank=as.rankings(RR)
RR_rank
as.top_ordering(RR_rank, ties_method="random")

## Coerce an object of class 'RankData' into an object of class 'top_ordering'
library(rankdist) 
data(apa_partial_obj)
d_apa_top_ord=as.top_ordering(data=apa_partial_obj)
identical(d_apa,d_apa_top_ord)

## Coerce a data frame from the package prefmod into an object of class 'top_ordering'
library(prefmod)
data(carconf)
carconf_rank=carconf[,1:6]
carconf_top_ord=as.top_ordering(data=carconf_rank,format_input="ranking",aggr=FALSE)
identical(d_carconf,carconf_top_ord)

## Coerce a data frame from the package pmr into an object of class 'top_ordering'
library(pmr)
data(big4)
head(big4)
big4_top_ord=as.top_ordering(data=big4,format_input="ranking",aggr=TRUE,freq_col=5)
head(big4_top_ord)

PLMIX documentation built on Sept. 4, 2019, 5:03 p.m.