strengejacke / sjstats

Effect size measures and significance tests
https://strengejacke.github.io/sjstats
189 stars 21 forks source link

grpmean weights issues #28

Closed cschwem2er closed 6 years ago

cschwem2er commented 6 years ago

Hi,

the following code raises an error:

library(sjmisc)
library(sjstats)
data(efc)
efc$weight <- sample(c(0.5577446,1.2667685), size = nrow(efc), replace = TRUE)
efc$w_ow <- sample(c(0.5577446,1.2667685), size = nrow(efc), replace = TRUE)

grpmean(efc, e42dep, e16sex, weight.by = w_ow)

but this works:

grpmean(efc, e42dep, e16sex, weight.by = weight)

The problem seems to be related to this line: https://github.com/strengejacke/sjstats/blob/aae3248d09198828006d1b6c474687fe8092df79/R/grpmean.R#L68

I'm not sure whether this might affect other functions as well.

cschwem2er commented 6 years ago

Okay I just tested this with another pc and a Stata dataset here and now, weighting does not work regardless of spelling. I also don't quite understand when nonstandard evaluation is supposed to work with weights and when it is not.

cschwem2er commented 6 years ago

Another test: It also works on the other system when passing the weight variable name as a string, e.g. weight.by = 'weight'. Whatever version you would prefer to work at the end: if non standard evaluation does not work for all arguments, it would be very helpful if the argument description for grpmean (and maybe other affected commands?) would include something about that.

At the moment it states "weight.by: Vector of weights that will be applied to weight all cases. Must be a vector of same length as the input vector. Default is NULL, so no weights are used."

This is the same wording as for sjmisc::frq(), but one cannot pass the weight vector name as string to frq(). In a perfect and wonderful world, there would only be one consistent way to pass weight arguments for the entire sjverse and all of its functions =D.

strengejacke commented 6 years ago

This inconsistency had some historical reasons, specifically this issue: https://github.com/strengejacke/sjPlot/commit/5d0be71e3af3aa197a0a832619b7ca7a039fa5b1#diff-9f037f838a5fd66c519d93f0b636b1a3

I needed to treat the weight.by differently. Now I could revise the method and make it consistent with other function.