Skip to contents

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


# between constructs
distance(bell2010, along = 1)
#> 
#> ############################
#> Distances between constructs
#> ############################
#> 
#> Distance method:  euclidean
#> Normalized: FALSE
#>                                  1    2    3    4    5    6    7    8    9
#> (1) relaxed - worried &     1      8.00 6.86 8.94 6.71 5.29 6.71 5.00 6.86
#> (2) not so sma - smart (aca 2           8.89 4.69 7.94 7.87 5.20 5.92 4.80
#> (3) dislikes s - loves spor 3                7.68 6.00 6.24 6.00 7.75 6.63
#> (4) not intera - loves peop 4                     5.39 6.63 4.80 6.08 4.12
#> (5) not transp - transparen 5                          5.39 5.48 5.83 4.69
#> (6) insensitiv - sensitive  6                               6.24 5.00 6.56
#> (7) fearful&ti - fearless   7                                    6.48 3.16
#> (8) rough - gentle          8                                         6.16
#> (9) accept as  - loves to a 9                                             
#> 
distance(bell2010, along = 1, normalize = TRUE)
#> 
#> ############################
#> Distances between constructs
#> ############################
#> 
#> Distance method:  euclidean
#> Normalized: TRUE
#>                                  1    2    3    4    5    6    7    8    9
#> (1) relaxed - worried &     1      0.42 0.36 0.47 0.35 0.28 0.35 0.26 0.36
#> (2) not so sma - smart (aca 2           0.47 0.25 0.42 0.41 0.27 0.31 0.25
#> (3) dislikes s - loves spor 3                0.40 0.32 0.33 0.32 0.41 0.35
#> (4) not intera - loves peop 4                     0.28 0.35 0.25 0.32 0.22
#> (5) not transp - transparen 5                          0.28 0.29 0.31 0.25
#> (6) insensitiv - sensitive  6                               0.33 0.26 0.35
#> (7) fearful&ti - fearless   7                                    0.34 0.17
#> (8) rough - gentle          8                                         0.32
#> (9) accept as  - loves to a 9                                             
#> 

# between elements
distance(bell2010, along = 2)
#> 
#> ##########################
#> Distances between elements
#> ##########################
#> 
#> Distance method:  euclidean
#> Normalized: FALSE
#>                                 1    2    3    4    5    6    7    8    9   10
#> (1) self                   1      4.58 3.32 3.00 4.00 5.20 4.80 5.10 3.00 5.66
#> (2) closest friend of th   2           5.29 6.32 3.32 5.48 3.46 5.57 5.66 5.57
#> (3) the unhappiest perso   3                4.24 5.57 4.90 5.48 7.42 5.48 5.74
#> (4) A person of the oppo   4                     6.24 6.16 5.48 5.39 4.24 6.86
#> (5) A teacher you respec   5                          6.86 5.20 4.69 5.00 4.47
#> (6) Mother (or the perso   6                               4.47 8.77 6.16 7.00
#> (7) A person of the oppo   7                                    5.92 6.00 5.20
#> (8) The most confident p   8                                         5.39 6.63
#> (9) A person you work we   9                                              7.55
#> (10) A teacher you did no 10                                                  
#> 

# several distance methods
distance(bell2010, dm = "man") # manhattan distance
#> 
#> ############################
#> Distances between constructs
#> ############################
#> 
#> Distance method:  manhattan
#> Normalized: FALSE
#>                                   1     2     3     4     5     6     7     8
#> (1) relaxed - worried &     1       20.00 19.00 24.00 17.00 12.00 17.00 13.00
#> (2) not so sma - smart (aca 2             23.00 10.00 21.00 20.00 15.00 15.00
#> (3) dislikes s - loves spor 3                   19.00 14.00 17.00 16.00 20.00
#> (4) not intera - loves peop 4                         13.00 18.00 13.00 17.00
#> (5) not transp - transparen 5                               15.00 14.00 16.00
#> (6) insensitiv - sensitive  6                                     17.00 11.00
#> (7) fearful&ti - fearless   7                                           16.00
#> (8) rough - gentle          8                                                
#> (9) accept as  - loves to a 9                                                
#>                                 9
#> (1) relaxed - worried &     17.00
#> (2) not so sma - smart (aca 11.00
#> (3) dislikes s - loves spor 16.00
#> (4) not intera - loves peop 11.00
#> (5) not transp - transparen 12.00
#> (6) insensitiv - sensitive  17.00
#> (7) fearful&ti - fearless    8.00
#> (8) rough - gentle          14.00
#> (9) accept as  - loves to a      
#> 
distance(bell2010, dm = "mink", p = 3) # minkowski metric to the power of 3
#> 
#> ############################
#> Distances between constructs
#> ############################
#> 
#> Distance method:  minkowski
#> Power p: 3
#> Normalized: FALSE
#>                                  1    2    3    4    5    6    7    8    9
#> (1) relaxed - worried &     1      6.23 5.18 6.87 5.16 4.38 5.16 3.80 5.57
#> (2) not so sma - smart (aca 2           6.64 3.87 5.92 6.18 3.85 4.72 3.76
#> (3) dislikes s - loves spor 3                5.95 4.79 4.56 4.55 6.02 5.29
#> (4) not intera - loves peop 4                     4.18 5.01 3.66 4.66 3.07
#> (5) not transp - transparen 5                          3.98 4.41 4.34 3.63
#> (6) insensitiv - sensitive  6                               4.66 4.25 5.08
#> (7) fearful&ti - fearless   7                                    4.99 2.41
#> (8) rough - gentle          8                                         4.96
#> (9) accept as  - loves to a 9                                             
#> 

# to save the results without printing to the console
d <- distance(bell2010, trim = 7)
d
#> 
#> ############################
#> Distances between constructs
#> ############################
#> 
#> Distance method:  euclidean
#> Normalized: FALSE
#>                      1    2    3    4    5    6    7    8    9
#> (1) rela - worr 1      8.00 6.86 8.94 6.71 5.29 6.71 5.00 6.86
#> (2) not  - smar 2           8.89 4.69 7.94 7.87 5.20 5.92 4.80
#> (3) disl - love 3                7.68 6.00 6.24 6.00 7.75 6.63
#> (4) not  - love 4                     5.39 6.63 4.80 6.08 4.12
#> (5) not  - tran 5                          5.39 5.48 5.83 4.69
#> (6) inse - sens 6                               6.24 5.00 6.56
#> (7) fear - fear 7                                    6.48 3.16
#> (8) roug - gent 8                                         6.16
#> (9) acce - love 9                                             
#> 

# some more options when printing the distance matrix
print(d, digits = 5)
#> 
#> ############################
#> Distances between constructs
#> ############################
#> 
#> Distance method:  euclidean
#> Normalized: FALSE
#>                         1       2       3       4       5       6       7
#> (1) rela - worr 1         8.00000 6.85565 8.94427 6.70820 5.29150 6.70820
#> (2) not  - smar 2                 8.88819 4.69042 7.93725 7.87401 5.19615
#> (3) disl - love 3                         7.68115 6.00000 6.24500 6.00000
#> (4) not  - love 4                                 5.38516 6.63325 4.79583
#> (5) not  - tran 5                                         5.38516 5.47723
#> (6) inse - sens 6                                                 6.24500
#> (7) fear - fear 7                                                        
#> (8) roug - gent 8                                                        
#> (9) acce - love 9                                                        
#>                       8       9
#> (1) rela - worr 5.00000 6.85565
#> (2) not  - smar 5.91608 4.79583
#> (3) disl - love 7.74597 6.63325
#> (4) not  - love 6.08276 4.12311
#> (5) not  - tran 5.83095 4.69042
#> (6) inse - sens 5.00000 6.55744
#> (7) fear - fear 6.48074 3.16228
#> (8) roug - gent         6.16441
#> (9) acce - love                
#> 
print(d, col.index = FALSE)
#> 
#> ############################
#> Distances between constructs
#> ############################
#> 
#> Distance method:  euclidean
#> Normalized: FALSE
#>                    1    2    3    4    5    6    7    8    9
#> (1) rela - worr      8.00 6.86 8.94 6.71 5.29 6.71 5.00 6.86
#> (2) not  - smar           8.89 4.69 7.94 7.87 5.20 5.92 4.80
#> (3) disl - love                7.68 6.00 6.24 6.00 7.75 6.63
#> (4) not  - love                     5.39 6.63 4.80 6.08 4.12
#> (5) not  - tran                          5.39 5.48 5.83 4.69
#> (6) inse - sens                               6.24 5.00 6.56
#> (7) fear - fear                                    6.48 3.16
#> (8) roug - gent                                         6.16
#> (9) acce - love                                             
#> 
print(d, upper = FALSE)
#> 
#> ############################
#> Distances between constructs
#> ############################
#> 
#> Distance method:  euclidean
#> Normalized: FALSE
#>                      1    2    3    4    5    6    7    8    9
#> (1) rela - worr 1 0.00 8.00 6.86 8.94 6.71 5.29 6.71 5.00 6.86
#> (2) not  - smar 2 8.00 0.00 8.89 4.69 7.94 7.87 5.20 5.92 4.80
#> (3) disl - love 3 6.86 8.89 0.00 7.68 6.00 6.24 6.00 7.75 6.63
#> (4) not  - love 4 8.94 4.69 7.68 0.00 5.39 6.63 4.80 6.08 4.12
#> (5) not  - tran 5 6.71 7.94 6.00 5.39 0.00 5.39 5.48 5.83 4.69
#> (6) inse - sens 6 5.29 7.87 6.24 6.63 5.39 0.00 6.24 5.00 6.56
#> (7) fear - fear 7 6.71 5.20 6.00 4.80 5.48 6.24 0.00 6.48 3.16
#> (8) roug - gent 8 5.00 5.92 7.75 6.08 5.83 5.00 6.48 0.00 6.16
#> (9) acce - love 9 6.86 4.80 6.63 4.12 4.69 6.56 3.16 6.16 0.00
#> 

# accessing entries from the matrix
d[1, 3]
#> [1] 6.855655