Fitting a variogram model with the pairwise distance matrix supplied I'm trying to fit a variogram to my data, however the spatial points are confined by an irregular polygon. So I'd like to supply a variogram model function with the distance matrix of the points.
I've looked through gstat, geoR and vardiag but I can't figure out how to specify the distance matrix, as each of these requires the coordinates of the points. 
So I'm really just looking for a way to supply these distances to a variogram model fitting function, any help is appreciated!
 A: I don't know if there is a "proper" way to do this without changing the code, as you suggest in your comment; I haven't looked. But here's a useful hack: just make up points whose distances are the same as the distance matrix, and pass those.


*

*Let your squared distance matrix be $D$, of shape $n \times n$. We're looking for an embedding $\{ x_i \}_{i=1}^n$, with $x \in \mathbb R^d$ for some $d$, such that $D_{ij} = \lVert x_i - x_j \rVert^2$.

*Find a corresponding Gram matrix $G_{ij} = x_i^T x_j$. Note that $D_{ij} = \lVert x_i \rVert^2 + \lVert x_j \rVert^2 - 2 G_{ij}$. Defining $H$ to be the centering matrix $I - \mathbf 1 \mathbf 1^T / n$, $G = - \frac12 H D H$ works.

*Take the eigendecomposition $G = Q \Lambda Q^T$. All the eigenvalues will be nonnegative, since Gram matrices are positive semidefinite; if an exact embedding into dimension $d$ is possible, there will be at most $d$ nonzero entries. Otherwise, truncating it to the highest $d$ entries gives the best (in a certain sense) embedding into dimension $d$. Let $\Lambda_d$ be the diagonal matrix of the $d$ highest eigenvalue, and $Q_d$ be the corresponding eigenvectors (columns of $Q$); thus (assuming an exact embedding is possible) $G = Q_d \Lambda_d Q_d^T$. But then we can just use the embedding $X = Q_d \Lambda_d^{1/2}$, where since $\Lambda_d$ is diagonal the square root is just elementwise: then $X X^T = Q_d \Lambda_d^{1/2} \Lambda_d^{1/2} Q_d^T = G$.

