Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate an n-sized centering matrix
ResourceFunction["CenteringMatrix"][n] generates an n-sized centering matrix. |
Generate the 3×3 centering matrix:
| In[1]:= |
| Out[1]= |
Center a vector:
| In[2]:= |
| Out[3]= |
Confirm the vector is centered:
| In[4]:= |
| Out[4]= |
Center a matrix column-wise:
| In[5]:= | ![]() |
| Out[4]= | ![]() |
Confirm the matrix is centered:
| In[6]:= |
| Out[6]= |
Center a matrix row-wise:
| In[7]:= | ![]() |
| Out[8]= | ![]() |
Confirm the matrix is centered:
| In[9]:= |
| Out[9]= |
Double center a matrix:
| In[10]:= | ![]() |
| Out[11]= |
Confirm the matrix is double centered:
| In[12]:= |
| Out[12]= |
By default WorkingPrecision is set to MachinePrecision:
| In[13]:= |
| Out[13]= |
Compute the 3×3 centering matrix with 2-digit precision:
| In[14]:= |
| Out[14]= |
Compute the 3×3 centering matrix with machine precision:
| In[15]:= |
| Out[15]= |
Compute the 3×3 centering matrix with exact values:
| In[16]:= |
| Out[16]= | ![]() |
By default, CenteringMatrix will return a SparseArray:
| In[17]:= |
| Out[17]= |
Explicitly request a dense matrix from CenteringMatrix:
| In[18]:= |
| Out[18]= |
Define a fictional tabular dataset of species observations by site:
| In[19]:= | ![]() |
| Out[19]= | ![]() |
Double center the dataset:
| In[20]:= | ![]() |
| Out[20]= | ![]() |
Confirm the dataset is double centered:
| In[21]:= |
| Out[21]= |
Define a function to perform PCoA (Classical Multidimensional Scaling) that uses CenteringMatrix:
| In[22]:= | ![]() |
Load the Iris dataset, and create a distance matrix from the data:
| In[23]:= |
Perform PCoA on the distance matrix, and group the reprojected data by species:
| In[24]:= |
Plot the data in sPCoA coordinate space:
| In[25]:= |
| Out[25]= | ![]() |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License