dc.PlotLogLikelihoodContour: Plot Log-Likelihood Contour

Description Usage Arguments Details See Also Examples

View source: R/dc.R

Description

Makes a contour plot of a loglikelihood function that varies over two designated parameters, centered around a set of previously estimated parameters.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
dc.PlotLogLikelihoodContour(
  loglikelihood.fcn,
  vary.or.fix.param,
  predicted.params,
  ...,
  n.divs = 3,
  new.dev = FALSE,
  num.contour.lines = 10,
  zoom.percent = 0.9,
  allow.neg.params = FALSE,
  param.names = c("param 1", "param 2", "param 3", "param 4")
)

Arguments

loglikelihood.fcn

log-likelihood function to plot.

vary.or.fix.param

a vector of strings containing either "vary" or "fix". The parameters in the same indices as "vary" will be plotted while the other parameters will remain fixed at the estimated values. See details.

predicted.params

estimated parameters.

...

all additional arguments required by the log-likelihood function. For example, bgbb.rf.matrix.LL requires rf.matrix; pnbd.cbs.LL requires cal.cbs and hardie (defaults to TRUE); and bgnbd.cbs.LL requires cal.cbs.

n.divs

integer representing how fine-grained the contour plot is. A higher value will produce a higher resolution plot with smoother contour lines, but will take longer to plot. n.divs also affects the boundaries of the contour plot; see details.

new.dev

if TRUE, makes a new window for each contour plot.

num.contour.lines

number of contour lines to plot in the window.

zoom.percent

determines boundaries of contour plot. See details.

allow.neg.params

if FALSE, the contour plot will not include negative values (see details). This should be set to false for the BG/BB and Pareto/NBD models.

param.names

a vector containing parameter names.

Details

The contour plot will have the first parameter labelled "vary" on the x-axis, and the second parameter labelled "vary" on the y-axis. It will extend out by (n.divs * zoom.percent) in both directions and both dimensions from the estimated parameter values. The exception is if allow.neg.params is FALSE. In this case, the contour plot will end at zero if it would have extended into negative parameter values.

The estimated parameter values will be indicated by the intersection of two red lines.

See Also

dc.PlotLogLikelihoodContours

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# **Examples for BG/BB model:
data(donationsSummary)
rf.matrix <- donationsSummary$rf.matrix

# starting-point parameters
bgbb.startingparams <- c(1, 1, 0.5, 3)
# estimated parameters
bgbb.est.params <- bgbb.EstimateParameters(rf.matrix, bgbb.startingparams)

# set up parameter names for a more descriptive result
bgbb.param.names <- c("alpha", "beta", "gamma", "delta")

# plot a log-likelihood contour of alpha and beta, the unobserved
# parameters for the beta-Bernoulli transaction process of the BG/BB.
# Note that allow.neg.params has been set to false as BG/BB parameters
# cannot be negative:
dc.PlotLogLikelihoodContour(bgbb.rf.matrix.LL, 
                            c("vary", "vary", "fix", "fix"), 
                            bgbb.est.params, 
                            rf.matrix = rf.matrix, 
                            n.divs = 15, 
                            num.contour.lines = 15, 
                            zoom.percent = 0.2, 
                            allow.neg.params = FALSE, 
                            param.names = bgbb.param.names)

# plot a log-likelihood contour of gamma and delta, the unobserved
# parameters for the beta-geometric dropout process of the BG/BB.
# Note that allow.neg.params has been set to false as BG/BB parameters
# cannot be negative:
dc.PlotLogLikelihoodContour(bgbb.rf.matrix.LL, 
                            c("fix", "fix", "vary", "vary"), 
                            bgbb.est.params, 
                            rf.matrix = rf.matrix, 
                            n.divs = 15, 
                            num.contour.lines = 15, 
                            zoom.percent = 0.2, 
                            allow.neg.params = FALSE, 
                            param.names = bgbb.param.names)

# **Example for Pareto/NBD model:
data(cdnowSummary)
cbs <- cdnowSummary$cbs

# Speed up calculations:
cbs <- dc.compress.cbs(cbs)

# parameters estimated using pnbd.EstimateParameters
pnbd.est.params <- cdnowSummary$est.params

# set up parameter names for a more descriptive result
pnbd.param.names <- c("r", "alpha", "s", "beta")

# plot a log-likelihood contour of r and s, the shape parameters
# of the transaction and dropout process models (respectively).
# Note that allow.neg.params has been set to false as Pareto/NBD
# parameters cannot be negative:
dc.PlotLogLikelihoodContour(pnbd.cbs.LL, 
                            c("vary", "fix", "vary", "fix"), 
                            pnbd.est.params, 
                            cal.cbs = cbs, 
                            hardie = TRUE,
                            n.divs = 20, 
                            num.contour.lines = 20, 
                            zoom.percent = 0.1, 
                            allow.neg.params = FALSE, 
                            param.names = pnbd.param.names)

# **Example for BG/NBD model:
data(cdnowSummary)
cbs <- cdnowSummary$cbs

# parameters estimated using bgnbd.EstimateParameters
bgnbd.est.params <- cdnowSummary$est.params

# set up parameter names for a more descriptive result
bgnbd.param.names <- c("r", "alpha", "s", "beta")

# plot a log-likelihood contour of r and s, the shape parameters
# of the transaction and dropout process models (respectively).
# Note that allow.neg.params has been set to false as BG/NBD
# parameters cannot be negative:
dc.PlotLogLikelihoodContour(bgnbd.cbs.LL, 
                            c("vary", "fix", "vary", "fix"), 
                            bgnbd.est.params, 
                            cal.cbs = cbs, 
                            n.divs = 20, 
                            num.contour.lines = 20, 
                            zoom.percent = 0.1, 
                            allow.neg.params = FALSE, 
                            param.names = bgnbd.param.names)

BTYD documentation built on Nov. 18, 2021, 1:10 a.m.