distance: Distance measures (between constructs or elements).

View source: R/distance.R

distanceR Documentation

Distance measures (between constructs or elements).

Description

Various distance measures between elements or constructs are calculated.

Usage

distance(
  x,
  along = 1,
  dmethod = "euclidean",
  p = 2,
  normalize = FALSE,
  trim = 20,
  index = TRUE,
  ...
)

Arguments

x

repgrid object.

along

Whether to calculate distance for 1 = constructs (default) or for 2= elements.

dmethod

The distance measure to be used. This must be one of "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski". Any unambiguous substring can be given. For additional information on the different types type ?dist.

p

The power of the Minkowski distance, in case "minkowski" is used as argument for dmethod.

normalize

Use normalized distances. The distances are divided by the highest possible value given the rating scale fo the grid, so all distances are in the interval [0,1].

trim

The number of characters a construct or element is trimmed to (default is 20). If NA no trimming occurs. Trimming simply saves space when displaying correlation of constructs with long names.

index

Whether to print the number of the construct or element in front of the name (default is TRUE). This is useful to avoid identical row names, which may cause an error.

...

Additional parameters to be passed to function dist. Type dist for further information.

Value

matrix object.

Examples

## Not run: 

   # between constructs
   distance(bell2010, along = 1)
   distance(bell2010, along = 1, normalize = TRUE)
   
   # between elements
   distance(bell2010, along = 2)
 
   # several distance methods
   distance(bell2010, dm = "man")           # manhattan distance
   distance(bell2010, dm = "mink", p = 3)   # minkowski metric to the power of 3

   # to save the results without printing to the console
   d <- distance(bell2010, trim = 7)
   d
   
   # some more options when printing the distance matrix
   print(d, digits = 5)
   print(d, col.index = FALSE)
   print(d, upper = FALSE)
   
   # accessing entries from the matrix
   d[1,3]


## End(Not run)


OpenRepGrid documentation built on May 31, 2023, 5:33 p.m.