class_docstr: Descriptive statistics and tests with weights for case weights
  
  Assumes that the data is 1d or 2d with (nobs, nvars) observations in rows,
  variables in columns, and that the same weight applies to each column.
  
  If degrees of freedom correction is used, then weights should add up to the
  number of observations. ttest also assumes that the sum of weights
  corresponds to the sample size.
  
  This is essentially the same as replicating each observations by its
  weight, if the weights are integers, often called case or frequency weights.
  
  Parameters
  ----------
  data : array_like, 1-D or 2-D
      dataset
  weights : None or 1-D ndarray
      weights for each observation, with same length as zero axis of data
  ddof : int
      default ddof=0, degrees of freedom correction used for second moments,
      var, std, cov, corrcoef.
      However, statistical tests are independent of `ddof`, based on the
      standard formulas.
  
  Examples
  --------
  
  >>> import numpy as np
  >>> np.random.seed(0)
  >>> x1_2d = 1.0 + np.random.randn(20, 3)
  >>> w1 = np.random.randint(1, 4, 20)
  >>> d1 = DescrStatsW(x1_2d, weights=w1)
  >>> d1.mean
  array([ 1.42739844,  1.23174284,  1.083753  ])
  >>> d1.var
  array([ 0.94855633,  0.52074626,  1.12309325])
  >>> d1.std_mean
  array([ 0.14682676,  0.10878944,  0.15976497])
  
  >>> tstat, pval, df = d1.ttest_mean(0)
  >>> tstat; pval; df
  array([  9.72165021,  11.32226471,   6.78342055])
  array([  1.58414212e-12,   1.26536887e-14,   2.37623126e-08])
  44.0
  
  >>> tstat, pval, df = d1.ttest_mean([0, 1, 1])
  >>> tstat; pval; df
  array([ 9.72165021,  2.13019609,  0.52422632])
  array([  1.58414212e-12,   3.87842808e-02,   6.02752170e-01])
  44.0
  
  # if weights are integers, then asrepeats can be used
  
  >>> x1r = d1.asrepeats()
  >>> x1r.shape
  ...
  >>> stats.ttest_1samp(x1r, [0, 1, 1])
  ...
docstr: z-test of Null hypothesis that mean is equal to value.
  
  The alternative hypothesis H1 is defined by the following
  'two-sided': H1: mean not equal to value
  'larger' :   H1: mean larger than value
  'smaller' :  H1: mean smaller than value
  
  Parameters
  ----------
  value : float or array
      the hypothesized value for the mean
  alternative : str
      The alternative hypothesis, H1, has to be one of the following
  
        'two-sided': H1: mean not equal to value (default)
        'larger' :   H1: mean larger than value
        'smaller' :  H1: mean smaller than value
  
  Returns
  -------
  tstat : float
      test statistic
  pvalue : float
      pvalue of the t-test
  
  Notes
  -----
  This uses the same degrees of freedom correction as the t-test in the
  calculation of the standard error of the mean, i.e it uses
  `(sum_weights - 1)` instead of `sum_weights` in the denominator.
  See Examples below for the difference.
  
  Examples
  --------
  
  z-test on a proportion, with 20 observations, 15 of those are our event
  
  >>> import statsmodels.api as sm
  >>> x1 = [0, 1]
  >>> w1 = [5, 15]
  >>> d1 = sm.stats.DescrStatsW(x1, w1)
  >>> d1.ztest_mean(0.5)
  (2.5166114784235836, 0.011848940928347452)
  
  This differs from the proportions_ztest because of the degrees of
  freedom correction:
  >>> sm.stats.proportions_ztest(15, 20.0, value=0.5)
  (2.5819888974716112, 0.009823274507519247).
  
  We can replicate the results from ``proportions_ztest`` if we increase
  the weights to have artificially one more observation:
  
  >>> sm.stats.DescrStatsW(x1, np.array(w1)*21./20).ztest_mean(0.5)
  (2.5819888974716116, 0.0098232745075192366)
docstr_tok: ["z-test","of","Null","hypothesis","that","mean","is","equal","to","value",".","The","alternative","hypothesis","H1","is","defined","by","the","following","'two-sided","'",":","H1",":","mean","not","equal","to","value","'larger","'",":","H1",":","mean","larger","than","value","'smaller","'",":","H1",":","mean","smaller","than","value","Parameters","--","--","--","--","--","value",":","float","or","array","the","hypothesized","value","for","the","mean","alternative",":","str","The","alternative","hypothesis",",","H1",",","has","to","be","one","of","the","following","'two-sided","'",":","H1",":","mean","not","equal","to","value","(","default",")","'larger","'",":","H1",":","mean","larger","than","value","'smaller","'",":","H1",":","mean","smaller","than","value","Returns","--","--","--","-","tstat",":","float","test","statistic","pvalue",":","float","pvalue","of","the","t-test","Notes","--","--","-","This","uses","the","same","degrees","of","freedom","correction","as","the","t-test","in","the","calculation","of","the","standard","error","of","the","mean",",","i.e","it","uses","`","(","sum_weights","-","1",")","`","instead","of","`","sum_weights","`","in","the","denominator",".","See","Examples","below","for","the","difference",".","Examples","--","--","--","--","z-test","on","a","proportion",",","with","20","observations",",","15","of","those","are","our","event",">",">",">","import","statsmodels.api","as","sm",">",">",">","x1","=","[","0",",","1","]",">",">",">","w1","=","[","5",",","15","]",">",">",">","d1","=","sm.stats.DescrStatsW","(","x1",",","w1",")",">",">",">","d1.ztest_mean","(","0.5",")","(","2.5166114784235836",",","0.011848940928347452",")","This","differs","from","the","proportions_ztest","because","of","the","degrees","of","freedom","correction",":",">",">",">","sm.stats.proportions_ztest","(","15",",","20.0",",","value=0.5",")","(","2.5819888974716112",",","0.009823274507519247",")",".","We","can","replicate","the","results","from","``","proportions_ztest","``","if","we","increase","the","weights","to","have","artificially","one","more","observation",":",">",">",">","sm.stats.DescrStatsW","(","x1",",","np.array","(","w1",")","*","21.\/20",")",".ztest_mean","(","0.5",")","(","2.5819888974716116",",","0.0098232745075192366",")"]
code: def ztest_mean(self, value=0, alternative="two-sided"):
      """z-test of Null hypothesis that mean is equal to value.
  
      The alternative hypothesis H1 is defined by the following
      'two-sided': H1: mean not equal to value
      'larger' :   H1: mean larger than value
      'smaller' :  H1: mean smaller than value
  
      Parameters
      ----------
      value : float or array
          the hypothesized value for the mean
      alternative : str
          The alternative hypothesis, H1, has to be one of the following
  
            'two-sided': H1: mean not equal to value (default)
            'larger' :   H1: mean larger than value
            'smaller' :  H1: mean smaller than value
  
      Returns
      -------
      tstat : float
          test statistic
      pvalue : float
          pvalue of the t-test
  
      Notes
      -----
      This uses the same degrees of freedom correction as the t-test in the
      calculation of the standard error of the mean, i.e it uses
      `(sum_weights - 1)` instead of `sum_weights` in the denominator.
      See Examples below for the difference.
  
      Examples
      --------
  
      z-test on a proportion, with 20 observations, 15 of those are our event
  
      >>> import statsmodels.api as sm
      >>> x1 = [0, 1]
      >>> w1 = [5, 15]
      >>> d1 = sm.stats.DescrStatsW(x1, w1)
      >>> d1.ztest_mean(0.5)
      (2.5166114784235836, 0.011848940928347452)
  
      This differs from the proportions_ztest because of the degrees of
      freedom correction:
      >>> sm.stats.proportions_ztest(15, 20.0, value=0.5)
      (2.5819888974716112, 0.009823274507519247).
  
      We can replicate the results from ``proportions_ztest`` if we increase
      the weights to have artificially one more observation:
  
      >>> sm.stats.DescrStatsW(x1, np.array(w1)*21./20).ztest_mean(0.5)
      (2.5819888974716116, 0.0098232745075192366)
      """
      tstat = (self.mean - value) / self.std_mean
      # TODO: use outsourced
      if alternative == "two-sided":
          pvalue = stats.norm.sf(np.abs(tstat)) * 2
      elif alternative == "larger":
          pvalue = stats.norm.sf(tstat)
      elif alternative == "smaller":
          pvalue = stats.norm.cdf(tstat)
  
      return tstat, pvalue
  
imports: import numpy
  from scipy import stats
  from statsmodels.tools.decorators import cache_readonly
label_desc: Use image node_id 22 for calling the DescrStatsW obj's underlying member method code with example usage: obj.ztest_mean(value, alternative) and returns: tstat,  pvalue