Is it possible to make glmm in Python?

Is it possible to make glmm in Python (e.g. GENLINMIXED analysis in SPSS)? I am a big fan of statsmodels, but this library does not seem to support glmm ... Are there any alternatives?

-edit -

Decided to do it with R and r2py ...

def RunAnalyseMLMlogit(dataset, outcomevars, meeneemvars, randintercept, randslope):

    from rpy2.robjects import pandas2ri
    from rpy2.robjects.packages import importr
    base = importr('base')
    stats = importr('stats')
    lme4 = importr('lme4')

    #data
    with SavReaderNp(dataset) as reader_np:
        array = reader_np.to_structured_array()

    df = pd.DataFrame(array)

    variabelen = ' '.join(outcomevars) + ' ~ ' + '+'.join(meeneemvars)
    randintercept2 = ['(1|'+i+')' for i in randintercept]
    intercept = '+'.join(randintercept2)
    randslope2 = ['(1+'+meeneemvars[0]+'|'+i+')' for i in randslope]
    slope = ' '.join(randslope2)

    pandas2ri.activate()
    r_df = pandas2ri.py2ri(df)

    #model
    #random intercepts + random slopes
    if len(randslope) > 0:
        formula = variabelen + '+' + intercept + '+' + slope

    #only random intercepts
    else:
        formula = variabelen + '+' + intercept

    model = lme4.glmer(formula, data=r_df, family= 'binomial')
    resultaat = base.summary(model).rx2('coefficients')
    uitkomst = base.summary(model)

    return uitkomst
+4
source share
1 answer

According to this (though not so recently) post, it is still not a good solution to run glmms in Python. However, if you are just looking for a free (and much more flexible!) Alternative to running tests in SPSS, take a look at the lme4 package for R. You could even use a package such as rpy2 and call R directly from Python, but that might be a bit a mistake.

+3

Source: https://habr.com/ru/post/1673294/


All Articles