foldnormal.RdFits a (generalized) folded (univariate) normal distribution.
foldnormal(lmean = "identitylink", lsd = "loglink", imean = NULL,
isd = NULL, a1 = 1, a2 = 1, nsimEIM = 500, imethod = 1,
zero = NULL)Link functions for the mean and standard
deviation parameters of the usual univariate normal distribution.
They are \(\mu\) and \(\sigma\) respectively.
See Links for more choices.
Optional initial values for \(\mu\)
and \(\sigma\).
A NULL means a value is computed internally.
See CommonVGAMffArguments.
Positive weights, called \(a_1\) and \(a_2\) below. Each must be of length 1.
If a random variable has an ordinary univariate normal distribution then the absolute value of that random variable has an ordinary folded normal distribution. That is, the sign has not been recorded; only the magnitude has been measured.
More generally, suppose \(X\) is normal with
mean mean and
standard deviation sd.
Let \(Y=\max(a_1 X, -a_2 X)\)
where \(a_1\) and \(a_2\) are positive weights.
This means that \(Y = a_1 X\) for \(X > 0\),
and \(Y = a_2 X\) for \(X < 0\).
Then \(Y\) is said to have a
generalized folded normal distribution.
The ordinary folded normal distribution corresponds to the
special case \(a_1 = a_2 = 1\).
The probability density function of the ordinary
folded normal distribution
can be written
dnorm(y, mean, sd) + dnorm(y, -mean, sd) for
\(y \ge 0\).
By default, mean and log(sd) are the
linear/additive
predictors.
Having mean=0 and sd=1 results in the
half-normal distribution.
The mean of an ordinary folded normal distribution is
$$E(Y) = \sigma \sqrt{2/\pi} \exp(-\mu^2/(2\sigma^2)) +
\mu [1-2\Phi(-\mu/\sigma)] $$
and these are returned as the fitted values.
Here, \(\Phi()\) is the cumulative distribution
function of a
standard normal (pnorm).
An object of class "vglmff"
(see vglmff-class).
The object is used by modelling functions such
as vglm
and vgam.
Lin, P. C. (2005). Application of the generalized folded-normal distribution to the process capability measures. International Journal of Advanced Manufacturing Technology, 26, 825–830.
Johnson, N. L. (1962). The folded normal distribution: accuracy of estimation by maximum likelihood. Technometrics, 4, 249–256.
The response variable for this family function is the same as
uninormal except positive values are required.
Reasonably good initial values are needed.
Fisher scoring using simulation is implemented.
See CommonVGAMffArguments for
general information about
many of these arguments.
Yet to do: implement the results of Johnson (1962) which gives expressions for the EIM, albeit, under a different parameterization. Also, one element of the EIM appears to require numerical integration.
Under- or over-flow may occur if the data is ill-conditioned. It is recommended that several different initial values be used to help avoid local solutions.
if (FALSE) m <- 2; SD <- exp(1)
fdata <- data.frame(y = rfoldnorm(n <- 1000, m = m, sd = SD))
#> Error: object 'm' not found
hist(with(fdata, y), prob = TRUE, main = paste("foldnormal(m = ",
m, ", sd = ", round(SD, 2), ")"))
#> Error: object 'fdata' not found
fit <- vglm(y ~ 1, foldnormal, data = fdata, trace = TRUE)
#> Error in eval(mf, parent.frame()): object 'fdata' not found
coef(fit, matrix = TRUE)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'coef': object 'fit' not found
(Cfit <- Coef(fit))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'Coef': object 'fit' not found
# Add the fit to the histogram:
mygrid <- with(fdata, seq(min(y), max(y), len = 200))
#> Error: object 'fdata' not found
lines(mygrid, dfoldnorm(mygrid, Cfit[1], Cfit[2]), col = "orange")
#> Error: object 'mygrid' not found
# \dontrun{}