regression - Julia contrast coding -


having trouble assigning custom contrasts categorical variables in regression. looks 1 can assign effectscoding or dummycoding using contrast parameter

    model = fit!(lmm(@formula(response ~ 1 + factor + (1|sub)), data,               contrasts = dict(:factor => effectscoding()) )) 

but how assign custom contrasts?

for instance, in r can do

contrasts(data$factor) <- cbind("a_vs_b"= c(0.5, -0.5, 0), "ab_vs_c"= c(-0.25, -0.25, 0.5))  > contrasts(data$factor)        a_vs_b   ab_vs_c        0.5     -0.25 b       -0.5     -0.25 c        0.0      0.50 

in addition effectscoding(), dataframes supports other contrast specifications. , in general, can supply contrast matrix (of right size, k-by-(k-1) k categories) in r. example:

using rdatasets        # install pkg.add("rdatasets") using mixedmodels      # install pkg.add("mixedmodels")  iris = dataset("datasets", "iris")  contrast_matrix = [0.5 -0.25; -0.5 -0.25; 0.0 0.5] fit!(lmm(@formula(sepallength ~ 1 + species + (1|petalwidth)), iris,    contrasts = dict(:species => contrastscoding(contrast_matrix)) )) 

the specific contrast matrix in question helmert coding matrix ordering of categories. in case, simpler do:

fit!(lmm(@formula(sepallength ~ 1 + species + (1|petalwidth)), iris,    contrasts = dict(:species => helmertcoding()) )) 

helmertcoding takes optional arguments base , levels (not named, see docs) switch around category orderings.

hope helps, actual code gave few problems on v0.7 julia, on v0.5 should work.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -