newscaleunit_ function(S,c=log(10),k2=200,tol=1e-4,M=1e6,mu1pen=-0.5,mu2pen=0.5,sig2pen=0.75,pi1pen=0.5,pi2pen=0.5) { # Scale a data set so that the presumption of unit variance for # the mixture components is tenable. This can be done prior to # invocation of normal.S, so that the tests performed therein # are meaningful. # # More specifically, after centering the data, we apply the EM # algorithm (using the penalized maximum likelihood estimation # framework of Chen, Chen, and Kalbfleisch) to the model # p_1 f(x | mu_1, sigma^2) + p_2 f(x | mu_2, sigma^2). # Then we scale the data using the resulting estimate of sigma^2. # # Required Input: # S is a vector of data # # Optional Inputs: # mu1pen, mu2pen are multiplied by the sample standard # deviation to produce initial values. # sig2pen is multiplied by the sample variance to produce # an initial value. # pi1pen, pi2pen are initial values. # k2 is the maximum number of EM iterations allowed. # c, tol, M are as described in normal.S. # # Outputs: # S is a vector of scaled data S_ S - mean(S) n_ length(S) mu1pen_ mu1pen*sqrt(var(S)) mu2pen_ mu2pen*sqrt(var(S)) sig2pen_ sig2pen*var(S) nit2_ 0 storage.mode(S)_"double" storage.mode(mu1pen)_"double" storage.mode(mu2pen)_"double" storage.mode(sig2pen)_"double" storage.mode(pi1pen)_"double" storage.mode(pi2pen)_"double" storage.mode(c)_"double" storage.mode(M)_"double" storage.mode(tol)_"double" w_.Fortran("newscaleunit", S=as.double(S), n=as.integer(n), nit2=as.integer(nit2), c=as.double(c), M=as.double(M), k2=as.integer(k2), tol=as.double(tol), pi1pen=as.double(pi1pen), pi2pen=as.double(pi2pen), mu1pen=as.double(mu1pen), mu2pen=as.double(mu2pen), sig2pen=as.double(sig2pen)) S_ S/sqrt(w$sig2pen) return(S) result }