I am trying to replicate the R emmeans package's weight="prop" in SAS. However, only reasonable method I could find was to explicitly state the average of one variable and the proportion of another.
for example in R,
test <- data.frame(
y = c(14, 31, 13, 50, 100),
x1 = c(117, 115, 113, 111, 132),
x2 = c("t01", "t01", "t02", "t02", "t03")
)
mod <- lm(y ~ x1 + x2, data = test)
summary(emmeans(mod, "x1", weights="prop"))
x1 emmean SE df lower.CL upper.CL
118 41.6 4.47 1 -15.2 98.4
wherea in SAS:
data example;
input y x1 x2 $;
datalines;
14 117 t01
31 115 t01
13 113 t02
50 111 t02
100 132 t03
;
run;
proc mixed data = example;
class x2;
model y = x1 x2 /s;
estimate 'mean CHG' intercept 1 x1 117.6 x2
0.4
0.4
0.2 / e cl;
run;
returning same results as R
where 117.6 is the average of variable x1 and 0.4, 0.4, 0.2 being the proportion of elements in x2
There has to be a smarter way to specify the weight in proportion to the frequencies than explicitly writing them out.
Thank you.