normalq_ function(n,pi1,pi2,mu1,mu2,mu0=0) { # Test for homogeneity in a two-component normal location mixture, # in which each component has unit variance. This is a QUICK test, # not requiring the underlying data set itself, but estimates of # the mixture parameters must be in hand. # # Scenario: # H_0: There exists mu_0 such that # p_1 f(x | mu_1, sigma^2_1 = 1) + p_2 f(x | mu_2, sigma^2_2 = 1) # may be written as f(x | mu_0, sigma^2_0 = 1). # H_1: There is no such mu_0. # # Required Inputs: # n is the size of the underlying data set ("sample size"). # pi1, pi2, mu1, mu2 are estimates of the mixture parameters, # which could have been obtained in any way (e.g., method # of moments, unpenalized maximum likelihood, penalized # maximum likelihood). # It is assumed that the underlying data set was rescaled (if # necessary) so that the presumption of unit variance within # each component was tenable. Such rescaling can be done # using scaleunit.S or newscaleunit.S . # # Optional Input: # mu0 is an estimate of the overall mean. If no value is # provided by the user, mu0 defaults to 0. # # Outputs: # dk D-Test statistic # pvalue large-sample p-value: Technically speaking, this is # appropriate only when the mixture parameter estimates were # obtained by penalized maximum likelihood, with the penalty # term as indicated in normal.S. If the mixture parameter # estimates were obtained by unpenalized maximum likelihood, # you can use normalc.S to get estimated critical values. dkp1_ (pi1^2 / (2 * sqrt(pi) ) ) + ( pi2^2 / (2 * sqrt(pi) ) ) + 1 / (2 * sqrt(pi)) dkp2a_ 2 * pi1 * exp(-0.5*((mu1^2)+(mu0^2)) + 0.5*((mu1+mu0)^2/(2))) dkp2b_ 2 * pi2 * exp(-0.5*((mu2^2)+(mu0^2)) + 0.5*((mu2+mu0)^2/(2))) dkp3_ 2 * pi1 * pi2 * exp(-0.5*((mu2^2)+(mu1^2)) + 0.5*((mu2+mu1)^2/(2))) dk_ dkp1 - dkp2a/sqrt(4*pi) - dkp2b/sqrt(4*pi) + dkp3/sqrt(4*pi) pvalue_ 'LARGE' sdk_ (16/3)*sqrt(pi)*n*dk if (sdk > .2749959) pvalue_ 0.5-0.5*pchisq(sdk,1) return(dk,pvalue) result }