nm                   package:klaR                   R Documentation

_N_e_a_r_e_s_t _M_e_a_n _C_l_a_s_s_i_f_i_c_a_t_i_o_n

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

     Function for nearest mean classification.

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

     nm(x, ...)

     ## Default S3 method:
     nm(x, grouping, gamma = 0, ...)
     ## S3 method for class 'data.frame':
     nm(x, ...)
     ## S3 method for class 'matrix':
     nm(x, grouping, ..., subset, na.action = na.fail)
     ## S3 method for class 'formula':
     nm(formula, data = NULL, ..., subset, na.action = na.fail)

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

       x: matrix or data frame containing the explanatory variables 
          (required, if 'formula' is not given).

grouping: factor specifying the class for each observation  (required,
          if 'formula' is not given).

 formula: formula of the form 'groups ~ x1 + x2 + ...'.  That is, the
          response is the grouping factor and the right hand side
          specifies the (non-factor) discriminators.

    data: Data frame from which variables specified in 'formula' are
          preferentially to be taken.

   gamma: gamma parameter for rbf weight of the distance to mean. If
          'gamma=0' the posterior is 1 for the nearest class (mean) and
          0 else.

  subset: An index vector specifying the cases to be used in the
          training sample. (Note: If given, this argument must be
          named.)

na.action: specify the action to be taken if 'NA's are found. The
          default action is for the procedure to fail. An alternative
          is 'na.omit', which leads to rejection of cases with missing
          values on any required variable. (Note: If given, this
          argument must be named.) 

     ...: 

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

     'nm' is calling 'sknn' with the class means as observations. If
     'gamma>0' a gaussian like density is used to weight the distance
     to the class means 'weight=exp(-gamma*distance)'. This is similar
     to an rbf kernel.  If the distances are large it may be useful to
     'scale' the data first.

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

     A list containing the function call and the class means
     ('learn')).

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

     Karsten Luebke, luebke@statistik.uni-dortmund.de

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

     'sknn', 'rda', 'knn'

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

     data(B3)
     x <- nm(PHASEN ~ ., data = B3)
     x$learn
     x <- nm(PHASEN ~ ., data = B3, gamma = 0.1)
     predict(x)$post

