# How is the SAS REPLICATE statement in PROC NLMIXED different from a FREQ statement?

Note: I do not have access to SAS to work this out for myself.

I'm trying to work out the difference between the FREQ statement in PROC GENMOD (for example) and the REPLICATE statement in PROC NLMIXED.

The SAS explanation is not illuminating the practical mathematical difference for me. The explanatory test for REPLICATE is (Documentation link here):

The REPLICATE statement provides a way to accommodate models in which different subjects have identical data. This occurs most commonly when the dependent variable is binary. When you specify a REPLICATE variable, PROC NLMIXED assumes that its value indicates the number of subjects having data identical to those for the current value of the SUBJECT= variable (specified in the RANDOM statement). Only the last observation of the REPLICATE variable for each subject is used, and the replicate variable must have only positive integer values. Note that the REPLICATE mechanism is different from using a FREQ statement in other statistical modeling procedures, such as PROC GLM, GENMOD, GLIMMIX, and LOGISTIC. A FREQ variable is used to identify grouped values for observations, essentially multiplying the log likelihood or sum of squares contribution for the observation. A REPLICATE variable is used to multiply the contribution of a subject that comprises one or more observations.

The explanatory text for FREQ in PROC GENMOD is (Documentation link here):

The variable in the FREQ statement identifies a variable in the input data set containing the frequency of occurrence of each observation. PROC GENMOD treats each observation as if it appears n times, where n is the value of the FREQ variable for the observation. If it is not an integer, the frequency value is truncated to an integer. If it is less than 1 or missing, the observation is not used. In the case of models fit with generalized estimating equations (GEEs), the frequencies apply to the subject/cluster and therefore must be the same for all observations within each subject.

Assuming the replicate variable contains only integer values, that sounds like the REPLICATE statement in PROC NLMIXED is just a FREQ statement. But the SAS documentation says otherwise. What have I missed with how the commands affect the number of observations used, and the flow on effects to estimates? In particular, how does this affect repeated measures studies?

Update: could the answer lie with differences in treatment of the degrees of freedom? I don't understand how SAS uses these commands to figure this out for myself.

TL;DR: The key distinction lies in their level of operation (subject-level vs observation-level) and how they contribute to the likelihood estimation. Understanding this difference is crucial in model choice, particularly in complex models handled by PROC NLMIXED, and affects model estimates, standard errors, and degrees of freedom.

REPLICATE is used when different subjects have identical data, which often happens when the dependent variable is binary. In PROC NLMIXED, REPLICATE indicates the number of subjects with data identical to the current SUBJECT= variable value. It only uses the last observation of the REPLICATE variable for each subject. The crucial aspect here is that the REPLICATE statement multiplies the log likelihood contribution of each subject rather than each individual observation which is particularly relevant for models where the subject-level replication is important, such as in clinical trials with subjects having identical binary responses.

FREQ identifies the frequency of occurrence of each observation. PROC GENMOD treats each observation as if it appears a number of times equal to the FREQ variable's value. This means the contribution of each observation to the log likelihood or sum of squares is multiplied by its frequency value. It's typically used to simplify datasets with repeated observations.

REPLICATE in PROC NLMIXED is suitable for situations where repeated observations across subjects are identical, focusing on subject-level replication. FREQ in PROC GENMOD is more observation-level focused.

As for degrees of freedom, I believePROC NLMIXED defaults to the number of subjects minus the number of random effects for random effects models, and the number of observations otherwise. How REPLICATE and FREQ affect degrees of freedom depends on whether they increase the effective sample size at the subject or observation level, respectively.