
# the derivative of this function is: f'(x) = a(x - p)^2 + q
# a should be positive
# p and q should be zero or positive
# the point for x=p is were the function starts getting steaper again
# q determins the steapnes at x=p, horizontal for q=0
contrast <- function(x, a, p, q) {
  a/3.0*x*x*x - a*p*x*x + a*p*p*x + q*x
}

cplot <- function(a, p, q) {
  x <- seq(0, 50, by = .1)
  plot(x, contrast(x, a, p, q),
       type = 'l',
       main = sprintf('a = %g   p = %g   q = %g', a, p, q),
       xlab = 'distance in points',
       ylab = 'inverse influence')
}

opar <- par(mfrow=c(3,2))
cplot(1, 0, 0)
cplot(1, 1000, 0)
cplot(1, 20, 0)
cplot(1, 20, 100)
cplot(1, 10, 100)
cplot(1, 5, 100)
par(opar)
