Learn R Programming

desire (version 1.0.7)

ddesire: Generic Distribution functions for desirabilities

Description

Generic density, distribution, quantile and random number generation functions for desirability functions.

Usage

"ddesire"(x, f, mean = 0, sd = 1) "pdesire"(q, f, mean = 0, sd = 1) "qdesire"(p, f, mean = 0, sd = 1) "rdesire"(n, f, mean = 0, sd = 1) "edesire"(f, mean, sd) "vdesire"(f, mean, sd)

Arguments

x,q
Vector of quantiles.
p
vector of probabilies.
n
number of observations.
f
desirability function
mean
vector of means.
sd
vector of standard deviations.

Value

'ddesire' gives the density, 'pdesire' gives the distribution function, 'qdesire' gives the quantile function, and 'rdesire' generates random deviates.'edesire' and 'vdesire' return the expectation and variance of the function.

See Also

For desirability functions: harrington1 and harrington2

Examples

Run this code
data(Chocolate)

## Fit linear model to data:
m.d90 <- lm(d90 ~ rt + as + I(rt^2) + I(as^2) + rt:as, Chocolate)
m.Fe <- lm(Fe ~ rt + as + I(rt^2) + I(as^2) + rt:as, Chocolate)

## Define desirability functions:
d.d90 <- harrington2(21, 22, 1)
d.Fe <- harrington1(22, 0.8, 28, 0.2)

## Plot density of desirability in rt=30, as=50:
df <- data.frame(rt=30, as=50)
y.Fe <- predict(m.Fe, df)
sigma.Fe <- summary(m.Fe)$sigma

y.d90 <- predict(m.d90, df)
sigma.d90 <- summary(m.d90)$sigma

## Plot curve of density function:
opar <- par(mfrow=c(2,1))
curve(ddesire(x, d.d90, y.d90, sigma.d90), 0, 1, main="d.90", n=202)
curve(ddesire(x, d.Fe, y.Fe, sigma.Fe), 0, 1, main="Fe", n=202)
par(opar)

## Integrate:
integrate(function(x) ddesire(x, d.d90, y.d90, sigma.d90), 0, 1)
integrate(function(x) ddesire(x, d.Fe, y.Fe, sigma.Fe), 0, 1)

Run the code above in your browser using DataLab