goodfit                 package:vcd                 R Documentation

_G_o_o_d_n_e_s_s-_o_f-_f_i_t _T_e_s_t_s _f_o_r _D_i_s_c_r_e_t_e _D_a_t_a

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

     Fits a discrete (count data) distribution for goodness-of-fit
     tests.

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

     goodfit(x, type = c("poisson", "binomial", "nbinomial"),
       method = c("ML", "MinChisq"), par = NULL)
     ## S3 method for class 'goodfit':
     predict(object, newcount = NULL, type = c("response", "prob"), ...)

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

       x: either a vector of counts, a 1-way table of frequencies of
          counts or a data frame or matrix with frequencies in the
          first column and the corresponding counts in the second
          column.

    type: a character string indicating which distribution should be
          fit (for 'goodfit') or  indicating the type of prediction
          (fitted response or probabilities in 'predict') respectively.

  method: a character string indicating whether the distribution should
          be fit via ML (Maximum Likelihood) or Minimum Chi-squared.

     par: a named list giving the distribution parameters (named as in
          the corresponding density function), if set to 'NULL', the
          default, the parameters are estimated.  If the parameter
          'size' is not specified if 'type' is '"binomial"' it is taken
          to be the maximum count.

  object: an object of class '"goodfit"'.

newcount: a vector of counts.  By default the counts stored in 'object'
          are used, i.e., the fitted values are computed.  These can
          also be extracted by 'fitted(object)'.

     ...: _currently not used_.

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

     'goodfit' essentially computes the fitted values of a discrete
     distribution (either poisson, binomial or negative binomial) to
     the count data given in 'x'.  If the parameters are not specified
     they are estimated either by ML or Minimum Chi-squared. 

     'par' should be a named list specifying the parameters 'lambda'
     for '"poisson"' and 'prob' and 'size' for '"binomial"' or
     '"nbinomial"', respectively. If for '"binomial"' 'size' is not
     specified it is not estimated but taken as the maximum count.

     The corresponding Pearson Chi-squared or likelihood ratio
     statistic respectively is computed and given with their p values
     by the 'summary' method.  The 'plot' method produces a 'rootogram'
     of the observed and fitted values.

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

     A list of class '"goodfit"' with elements: 

observed: observed frequencies.

   count: corresponding counts.

  fitted: expected frequencies (fitted by ML).

    type: a character string indicating the distribution fitted.

  method: a character string indicating the fitting method (can be
          either '"ML"', '"MinChisq"' or '"fixed"' if the parameters
          were specified).

      df: degrees of freedom.

     par: a named list of the (estimated) distribution parameters.

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

     Achim Zeileis Achim.Zeileis@R-project.org

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

     M. Friendly (2000), _Visualizing Categorical Data_. SAS Institute,
     Cary, NC.

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

     ## Simulated data examples:
     dummy <- rnbinom(200, size = 1.5, prob = 0.8)
     gf <- goodfit(dummy, type = "nbinomial", method = "MinChisq")
     summary(gf)
     plot(gf)

     dummy <- rbinom(100, size = 6, prob = 0.5)
     gf1 <- goodfit(dummy, type = "binomial", par = list(size = 6))
     gf2 <- goodfit(dummy, type = "binomial", par = list(prob = 0.6, size = 6))
     summary(gf1)
     plot(gf1)
     summary(gf2)
     plot(gf2)

     ## Real data examples:
     data(HorseKicks)
     HK.fit <- goodfit(HorseKicks)
     summary(HK.fit)
     plot(HK.fit)

     data(Federalist)
     F.fit <- goodfit(Federalist, type = "nbinomial")
     summary(F.fit)
     plot(F.fit)

