% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/amoment.R
\name{local_moment}
\alias{local_moment}
\title{Calculate Moments of Neighborhood}
\usage{
local_moment(
image,
window = NULL,
nvoxels = NULL,
moment,
mask = NULL,
only.mask = FALSE,
center = is.null(mean_image),
invert = FALSE,
mean_image = NULL,
na.rm = TRUE,
remask = TRUE,
...
)
}
\arguments{
\item{image}{input image}
\item{window}{window (in width) for the neighborhood}
\item{nvoxels}{window (in voxels) for the neighborhood 1 results in a 3x3 cube}
\item{moment}{vector moments taken (1- mean, 2-sd, 3-skew)}
\item{mask}{array or object of class nifti of same size as image}
\item{only.mask}{Should objects outside the mask (i.e. zeros) be
counted the moment? Default is FALSE so edges are weighted to 0}
\item{center}{vector of indicator of central moment.
if TRUE mean image is subtracted. Same length as moment}
\item{invert}{Standardize the values by the power: 1/moment}
\item{mean_image}{mean image to be subtracted. If not supplied, and central = TRUE, local_moment_edge is run with mom = 1}
\item{na.rm}{remove NAs from the moment image calculation}
\item{remask}{set areas outside of mask to 0}
\item{...}{Arguments passed to \code{\link{get_neighbors}}}
}
\value{
List of arrays same lenght as moment
}
\description{
This function calculates Local Moments (mean, standard deviation, skew) for an array.
}
\examples{
x = array(rnorm(1000), dim=c(10, 10, 10))
mask = abs(x) < 1
mean.x = local_moment(x, nvoxels=1, moment = 1, mask=mask,
center = FALSE,
remask = FALSE)[[1]]
var.x = local_moment(x, nvoxels=1, moment = 2, mask=mask, center = TRUE,
mean_image = mean.x, remask=FALSE)[[1]]
### check that x[2,2,2] mean is correct
check = x[1:3,1:3,1:3]
## masking
vals = check[abs(check) < 1]
m = mean(vals)
all.equal(m, mean.x[2,2,2])
n = length(vals)
v = var(vals) * (n-1)/n
var.x[2,2,2]
all.equal(v, var.x[2,2,2])
}