cd_plot                 package:vcd                 R Documentation

_C_o_n_d_i_t_i_o_n_a_l _D_e_n_s_i_t_y _P_l_o_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     Computes and plots conditional densities describing how the
     distribution of a categorical variable 'y' changes over a
     numerical variable 'x'.

_U_s_a_g_e:

     cd_plot(x, ...)
     ## Default S3 method:
     cd_plot(x, y,
       plot = TRUE, ylab_tol = 0.05,
       bw = "nrd0", n = 512, from = NULL, to = NULL,
       main = "", xlab = NULL, ylab = NULL, margins = c(5.1, 4.1, 4.1, 3.1),
       gp = gpar(), name = "cd_plot", newpage = TRUE, pop = TRUE,
       ...)
     ## S3 method for class 'formula':
     cd_plot(formula, data = list(),
       plot = TRUE, ylab_tol = 0.05,
       bw = "nrd0", n = 512, from = NULL, to = NULL,
       main = "", xlab = NULL, ylab = NULL, margins = c(5.1, 4.1, 4.1, 3.1),
       gp = gpar(), name = "cd_plot", newpage = TRUE, pop = TRUE,
       ...)

_A_r_g_u_m_e_n_t_s:

       x: an object, the default method expects either a single
          numerical variable.

       y: a '"factor"' interpreted to be the dependent variable

 formula: a '"formula"' of type 'y ~ x' with a single dependent
          '"factor"' and a single numerical explanatory variable.

    data: an optional data frame.

    plot: logical. Should the computed conditional densities be
          plotted?

ylab_tol: convenience tolerance parameter for y-axis annotation. If the
          distance between two labels drops under this threshold, they
          are plotted equidistantly.

bw, n, from, to, ...: arguments passed to 'density'

main, xlab, ylab: character strings for annotation

 margins: margins when calling 'plotViewport'

      gp: a '"gpar"' object controlling the grid graphical parameters
          of the rectangles. It should specify in particular a vector
          of 'fill' colors of the same length as 'levels(y)'. The
          default is to call 'gray.colors'.

    name: name of the plotting viewport.

 newpage: logical. Should 'grid.newpage' be called  before plotting?

     pop: logical. Should the viewport created be popped?

_D_e_t_a_i_l_s:

     'cd_plot' computes the conditional densities of 'x' given the
     levels of 'y' weighted by the marginal distribution of 'y'. The
     densities are derived cumulatively over the levels of 'y'.

     This visualization technique is similar to spinograms (see
     'spine') but they do not discretize the explanatory variable, but
     rather use a smoothing approach. Furthermore, the original x axis
     and not a distorted x axis (as for spinograms) is used. This
     typically results in conditional densities that are based on very
     few observations in the margins: hence, the estimates are less
     reliable there.

_V_a_l_u_e:

     The conditional density functions (cumulative over the levels of
     'y') are returned invisibly.

_A_u_t_h_o_r(_s):

     Achim Zeileis Achim.Zeileis@R-project.org

_R_e_f_e_r_e_n_c_e_s:

     Hofmann, H., Theus, M. (2005), _Interactive graphics for
     visualizing conditional distributions_, Unpublished Manuscript.

_S_e_e _A_l_s_o:

     'spine', 'density'

_E_x_a_m_p_l_e_s:

     ## Arthritis data
     data("Arthritis")
     cd_plot(Improved ~ Age, data = Arthritis)
     cd_plot(Improved ~ Age, data = Arthritis, bw = 3)
     cd_plot(Improved ~ Age, data = Arthritis, bw = "SJ")
     ## compare with spinogram
     spine(Improved ~ Age, data = Arthritis, breaks = 3)

     ## Space shuttle data
     data("SpaceShuttle")
     cd_plot(Fail ~ Temperature, data = SpaceShuttle, bw = 2)

     ## scatter plot with conditional density
     cdens <- cd_plot(Fail ~ Temperature, data = SpaceShuttle, bw = 2, plot = FALSE)
     plot(I(-1 * (as.numeric(Fail) - 2)) ~ jitter(Temperature, factor = 2), data = SpaceShuttle,
       xlab = "Temperature", ylab = "Failure")
     lines(53:81, cdens[[1]](53:81), col = 2)

