View source: R/inference_median.R
riem.median | R Documentation |
Given N observations X_1, X_2, …, X_N \in \mathcal{M}, compute Fréchet median and variation with respect to the geometry by minimizing
\textrm{min}_x ∑_{n=1}^N w_n ρ (x, x_n),\quad x\in\mathcal{M}
where
ρ (x, y) is a distance for two points x,y\in\mathcal{M}.
If non-uniform weights are given, normalized version of the mean is computed
and if weight=NULL
, it automatically sets equal weights for all observations.
riem.median( riemobj, weight = NULL, geometry = c("intrinsic", "extrinsic"), ... )
riemobj |
a S3 |
weight |
weight of observations; if |
geometry |
(case-insensitive) name of geometry; either geodesic ( |
... |
extra parameters including
|
a named list containing
a median matrix on \mathcal{M}.
sum of (weighted) distances.
#------------------------------------------------------------------- # Example on Sphere : points near (0,1) on S^1 in R^2 #------------------------------------------------------------------- ## GENERATE DATA ndata = 50 mydat = array(0,c(ndata,2)) for (i in 1:ndata){ tgt = c(stats::rnorm(1, sd=2), 1) mydat[i,] = tgt/sqrt(sum(tgt^2)) } myriem = wrap.sphere(mydat) ## COMPUTE TWO MEANS med.int = as.vector(riem.median(myriem, geometry="intrinsic")$median) med.ext = as.vector(riem.median(myriem, geometry="extrinsic")$median) ## VISUALIZE opar <- par(no.readonly=TRUE) plot(mydat[,1], mydat[,2], pch=19, xlim=c(-1.1,1.1), ylim=c(0,1.1), main="BLUE-extrinsic vs RED-intrinsic") arrows(x0=0,y0=0,x1=med.int[1],y1=med.int[2],col="red") arrows(x0=0,y0=0,x1=med.ext[1],y1=med.ext[2],col="blue") par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.