Coder Social home page Coder Social logo

pymer4's Introduction

Tests Build PyPI version Anaconda Version Anaconda Platforms Downloads DOI DOI Python Versions contributions welcome

Pymer4

❗️⚠️ Contributors wanted ⚠️❗️

Pymer4 is a statistics library for estimating various regression and multi-level models in Python. Love lme4 in R, but prefer to work in the scientific Python ecosystem? This package has got you covered!

pymer4 provides a clean interface that hides the back-and-forth code required when moving between R and Python. In other words, you can work completely in Python, never having to deal with R, but get (most) of lme4’s goodness. This is accomplished using rpy2 to interface between langauges.

Additionally pymer4 can fit various additional regression models with some bells, such as robust standard errors, and two-stage regression (summary statistics) models. See the features page for more information.

TL;DR this package is your new simple Pythonic drop-in replacement for lm() or glmer() in R.

For example:

# Assuming you have a pandas dataframe in tidy/long format
# with DV and IV columns for dependent/outcome vars and
# independent/predictor vars 

model = Lmer('DV ~ IV1 + IV2 + (IV+IV2|Group)', data=dataframe)

# Fit and print an R/statsmodels style summary 
# with t/z-tests, CIs, and p-values
model.fit()

# Access model attributes
model.BIC
model.residuals

# Get fitted parameters
model.coef # population parameters
model.fixef # group/cluster estimates (BLUPs)
model.ranef # group/cluster deviates

Documentation

Check out the documentation site for detailed tutorial examples, API documentation, and installation instructions!

Installation

Installing via Anaconda is the preferred installation method. Follow the directions here.

Local build

conda create -n build python=3.8 pip conda-build
conda activate build
conda-build ./conda --python=3.8 -c https://conda.anaconda.org/conda-forge --output-folder ./conda/build --output ./conda/build
tarball=$(conda-build ./conda --python=3.8 --output | tail -1)
conda convert -p linux-64 -p win-64 $tarball -o ./conda/build

Local upload

# after
# conda install anaconda-client
# anaconda login

# pre-release
anaconda upload ./conda/build/**/pymer4*.tar.bz2 -l "pre-release"

# main
anaconda upload ./conda/build/**/pymer4*.tar.bz2 -l "main"

Contributing

Contributions are always welcome!
If you are interested in contributing feel free to check out the open issues, development roadmap on Trello, or submit pull requests for additional features or bug fixes. If you do make a pull request, please do so by forking the development branch and taking note of the contribution guidelines.

Contributors

pymer4's People

Contributors

arose13 avatar dramanica avatar ejolly avatar jcheong0428 avatar shotgunosine avatar turbach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pymer4's Issues

AttributeError: 'DataFrame' object has no attribute 'copy'

I'm not sure if this is an error or just a misunderstanding on my part. Is there a limitation for permute that primarily requires continuous independent variables? The following corresponds to a split plot repeated measures ANOVA which contains all categorical measures. When running the code below using all categorical measures, I get the error:

AttributeError: 'DataFrame' object has no attribute 'copy'

import os
import pandas as pd
import seaborn as sns
from pymer4.models import Lm, Lmer
from pymer4.utils import get_resource_path
import pymer4

dat = pd.read_csv('C:/Dropbox/Codes/Repeated Measures ANOVA/R/HeartRate.csv', index_col='Obs')

drugs=list(dat['drug'].unique())
times=list(dat['time'].unique())
patients=list(dat['patient'].unique())

model = Lmer('HR ~ drug + time + drug:time + (1|drug:patient)',data=dat)
model.fit(factors={"drug": drugs,
"time": times,
"patient": patients}, permute=1000)

model.anova(force_orthogonal=True)

HeartRate.zip

Empty models with pymer4 to calculate the ICC

How can I specify an empty model using pymer4 ?

The R lme4 version of the empty model I am talking about is this: "target ~ 1 + (1|group)" . No features; just the target, the fixed intercept, and the random intercept. This will allow to calculate the Intra-Class Correlation.

I have tried the following specifications on pymer4

  1. "target ~ 1 + (1|group)"
  2. "target ~ 0 + (1|group)"
  3. "target ~ (1|group)"
  4. "target ~ dummyIntercept + (1|group)" , where dummyIntercept is a variable with a fixed value of 1 for all the cases.

The error I get is the following:

"Error in names(x) <- value :
'names' attribute [2] must be the same length as the vector [1]"

Any help with this would be greatly appreciated.

Thanks so much,
Giuseppe

installation issue for pymer4

base) C:\Users\j.siddaramanna>conda install pymer4
Collecting package metadata: done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  • pymer4

Current channels:

To search for alternate channels that may provide the conda package you're
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.

(base) C:\Users\j.siddaramanna>pip install pymer4
Collecting pymer4
Using cached https://files.pythonhosted.org/packages/fe/81/a5a639614c22b901905418f1f7f5364ae23c97ae4b081904665308ff233a/pymer4-0.6.0-py2.py3-none-any.whl
Requirement already satisfied: patsy>=0.4.1 in c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages (from pymer4) (0.5.1)
Requirement already satisfied: pandas>=0.19.1 in c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages (from pymer4) (0.23.4)
Requirement already satisfied: matplotlib>=2.0 in c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages (from pymer4) (3.0.2)
Collecting rpy2>=2.9.4 (from pymer4)
Using cached https://files.pythonhosted.org/packages/9c/81/86f9ba26b4fb27c17a143c064301f4928681c96c09c59edb23a44767c3d6/rpy2-3.0.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\cparser.py", line 276, in _parse
ast = _get_parser().parse(fullcsource)
File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\pycparser\c_parser.py", line 152, in parse
debug=debuglevel)
File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\pycparser\ply\yacc.py", line 331, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\pycparser\ply\yacc.py", line 1199, in parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\pycparser\ply\yacc.py", line 193, in call_errorfunc
r = errorfunc(token)
File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\pycparser\c_parser.py", line 1848, in p_error
column=self.clex.find_tok_column(p)))
File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\pycparser\plyparser.py", line 67, in _parse_error
raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: :23:5: before: blah1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\JA6F5~1.SID\AppData\Local\Temp\pip-install-sj6qv50w\rpy2\setup.py", line 185, in <module>
    'rpy2': ['doc/source/rpy2_logo.png', ]}
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\setuptools\__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\distutils\core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\setuptools\dist.py", line 447, in __init__
    k: v for k, v in attrs.items()
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\distutils\dist.py", line 292, in __init__
    self.finalize_options()
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\setuptools\dist.py", line 739, in finalize_options
    ep.load()(self, ep.name, value)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\setuptools_ext.py", line 204, in cffi_modules
    add_cffi_module(dist, cffi_module)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\setuptools_ext.py", line 49, in add_cffi_module
    execfile(build_file_name, mod_vars)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\setuptools_ext.py", line 25, in execfile
    exec(code, glob, glob)
  File "rpy/_rinterface_cffi_build.py", line 546, in <module>
    """ if os.name == 'nt' else ''
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\api.py", line 107, in cdef
    self._cdef(csource, override=override, packed=packed)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\api.py", line 121, in _cdef
    self._parser.parse(csource, override=override, **options)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\cparser.py", line 315, in parse
    self._internal_parse(csource)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\cparser.py", line 320, in _internal_parse
    ast, macros, csource = self._parse(csource)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\cparser.py", line 278, in _parse
    self.convert_pycparser_error(e, csource)
  File "c:\users\j.siddaramanna\appdata\local\continuum\anaconda3\lib\site-packages\cffi\cparser.py", line 307, in convert_pycparser_error
    raise CDefError(msg)
cffi.error.CDefError: cannot parse "blah1 ReadConsole;"
<cdef source string>:23:5: before: blah1

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\JA6F5~1.SID\AppData\Local\Temp\pip-install-sj6qv50w\rpy2\

Pass in lmer control options during function call

This one seems uncessarily tricky based on how rpy2 works, because the call is lmer(formula, data, lmerControl(optControl=list(maxfun=20000))) in R, and it's unclear how to parse the optControl part in python.

Should happen here for linear models and here for generalized models.

AttributeError: module 'rpy2.robjects.pandas2ri' has no attribute 'py2ri'

Hi, I am testing basic usage code from http://eshinjolly.com/pymer4/usage.html

model = Lmer('DV ~ IV2 + (IV2|Group)',data=df)
model.fit()

and get AttributeError: module 'rpy2.robjects.pandas2ri' has no attribute 'py2ri' , though there is no issue when running Lm on top of modularfrom pymer4.models import Lm, Lmer

I am using rpy2=3.0.5, R version 3.6.0, and Python 3.6.5 (pandas 0.23.1) on the operating system used: MacOS Mojave 10.14.6. Are there any versions listed need update?

Potential install issues on macOS

Some users are reporting install issues on the latest version of macOS with certain versions of R.
This seems to be related to failures to install rpy2 not pymer4. The reason seems to be because of the C-compilers that rpy2 requires, which it pulls from R. Apparently later versions of R require certain compiler flags not available on the default compilers that ship with macOS.

If this is a pervasive problem I'll try to write a guide for handling this. For now a potential solution is to use homebrew to install more recent compilers on macOS.

Follow the directions at the link above if you don't have homebrew already. You can check with which brew in your terminal. If nothing pops up it's not installed. Once installed use brew install gcc to get different compilers. If you run into permissions issues on (typically on macOS High Sierra) you'll need to sudo chown -R $(whoami) $(brew --prefix)/*. Then retry installation of rpy2 to see if that works: pip install rpy2. If that still doesn't work you might need to do some more fishing around...

Here are a few threads documenting the issues and some potential work arounds:

Installation error when pip updates rpy2

I just tried installing pymer4 on windows 7 in a newly created conda environment using the follwing commands:

conda create --name pymer4
activate pymer4
conda install pip
conda install -c conda-forge r r-base r-lmertest r-lsmeans rpy2
pip install pymer4

The final command gave the following error:

(pymer4) C:\Users\takam>pip install pymer4
Collecting pymer4
  Using cached https://files.pythonhosted.org/packages/fe/81/a5a639614c22b901905
418f1f7f5364ae23c97ae4b081904665308ff233a/pymer4-0.6.0-py2.py3-none-any.whl
Collecting numpy>=1.12.0 (from pymer4)
  Downloading https://files.pythonhosted.org/packages/00/0e/5a8c34adb97fc1cd6636
d78050e575945e874c8516d501421d5a0f377a6c/numpy-1.15.4-cp37-none-win_amd64.whl (1
3.5MB)
    100% |████████████████████████████████| 13.5MB 1.5MB/s
Collecting rpy2>=2.9.4 (from pymer4)
  Using cached https://files.pythonhosted.org/packages/02/d1/074ffbbe7b4bf74c60b
75d74c8e67a1e4515b0d85f85cd6540e39610754a/rpy2-2.9.5.tar.gz
    Complete output from command python setup.py egg_info:
    R version 3.5.1 (2018-07-02) -- "Feather Spray"
    Copyright (C) 2018 The R Foundation for Statistical Computing
    Platform: x86_64-w64-mingw32/x64 (64-bit)

    R is free software and comes with ABSOLUTELY NO WARRANTY.
    You are welcome to redistribute it under the terms of the
    GNU General Public License versions 2 or 3.
    For more information about these matters see
    http://www.gnu.org/licenses/.

    'sh' is not recognized as an internal or external command,
    operable program or batch file.
    R version 3.5.1 (2018-07-02) -- "Feather Spray"
    C:\Users\takam\Anaconda3\envs\pymer4\lib\R\bin\x64\R CMD config --ldflags
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\takam\AppData\Local\Temp\pip-install-li1spxm4\rpy2\setup.py
", line 374, in <module>
        ri_ext = getRinterface_ext()
      File "C:\Users\takam\AppData\Local\Temp\pip-install-li1spxm4\rpy2\setup.py
", line 269, in getRinterface_ext
        ldf = shlex.split(' '.join(rexec.cmd_config('--ldflags')))
      File "C:\Users\takam\AppData\Local\Temp\pip-install-li1spxm4\rpy2\setup.py
", line 222, in cmd_config
        universal_newlines = True)
      File "C:\Users\takam\Anaconda3\envs\pymer4\lib\subprocess.py", line 389, i
n check_output
        **kwargs).stdout
      File "C:\Users\takam\Anaconda3\envs\pymer4\lib\subprocess.py", line 481, i
n run
        output=stdout, stderr=stderr)
    subprocess.CalledProcessError: Command '('C:\\Users\\takam\\Anaconda3\\envs\
\pymer4\\lib\\R\\bin\\x64\\R', 'CMD', 'config', '--ldflags')' returned non-zero
exit status 1.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\takam\Ap
pData\Local\Temp\pip-install-li1spxm4\rpy2\

As the error occured when pip was trying to upgrade rpy2 to, I tried upgrading rpy2 using conda before trying to install pymer4:

conda install rpy2=2.9.4

I was then able to install pymer4 successfully with pip, but am posting this here in case anyone encounters the same issue.

Package updates for dependencies compatibility

Opening this issue to try to consolidate what updates need to be made in order to ensure compatibility with the latest versions of rpy2, pandas, and R.

rpy2 changelog
pandas 1.x.x milestone and beyond changelog
R version changes

Known working versions

rpy2 minimum: 3.0.0 latest: 3.2.2 <- but see #60
pandas minimum: 0.23.x latest: 0.25.x
R minimum 3.0.0 latest: 3.6.3

Most recent package versions

as of (5/5/20)
rpy2==3.3.1
R==4.0.0
pandas==1.0.3

Open Reference Issues

#57
#59
#60

Closed Reference Issues

#36
#42
#41
#25
#33
#38

Not python3 compatible

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-5741212cebfc> in <module>()
     10 from __future__ import division
     11 from rpy2.robjects import pandas2ri
---> 12 from pymer4 import Lmer
     13 
     14 base_dir = '/Users/lukechang/Dropbox/DoctorPatientPlacebo/'

/usr/local/lib/python3.6/site-packages/pymer4-0.0.1-py3.6.egg/pymer4/__init__.py in <module>()
      1 __all__ = ["models", "utils"]
----> 2 from models import Lmer

ModuleNotFoundError: No module named 'models'

Allow Lm and Lm2 to auto-ignore NaNs

Currently a user needs to manually deal with NaNs, e.g. by dropping the rows or filling them with some values in pandas (e.g. .fillna(0)).

Would be nice to have a boolean flag that defaults to ignoring NaNs but prints a warning if they exist, or errors out if set to False

Refactor plot and predict methods

Right now model.plot() essentially makes predictions using it's own internal data. Predict does the same, but just using population level parameters and R's predict() function which conveniently can handle rfx scaling.

Refactor so that predict can take in new data, or use it's own data (i.e. when it's called via plot). Also add flag that it can make group level predictions using group level parameter fits.

Lm() fails when data is perfectly fit

In the incredibly rare case (or mistaken case) that the data are perfectly fit by a model, the standard deviation of the residuals is return as inf which causes standard-error calculation to fail and the internal summary method of the class to crash.

Should handle this case by checking residuals and seeing if standard deviation is essentially 0, and then returning estimates like R does, but with a warning.

Install issue not covered in installation page

I'm running into an issue when trying to an issue when checking my install of pymer4. Below is the output of the line: python -c "from pymer4.test_install import test_install; test_install()"
Screen Shot 2019-11-06 at 6 39 38 PM

I went through the entire installation guide, from installing Anaconda all the way through the issues section with no errors or issues so far as I can tell. Please let me know what other info is needed!
Also, great work on the package! I hope I can get it working :)

[BUG] pymer4.Lmer() doesn't seem to work with rpy2=2.9

pymer 0.4.0 does not seem to be working with most recent version of rpy2. Recommend using rpy2=2.8.5 until this is resolved.

model = Lmer('Spent ~ Endowment + (1|SubID)',data=data)
model.fit()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-149-a49b34291503> in <module>()
      1 model = Lmer('Spent ~ Endowment + (1|SubID)',data=data)
----> 2 model.fit()
~/anaconda3/lib/python3.6/site-packages/pymer4/models.py in fit(self, conf_int, factors, ordered, summarize, verbose)
    323         else:
    324             self.fixef = pandas2ri.ri2py(fixefs[0])
--> 325             self.fixef = self.fixef[list(self.coefs.index)+[elem for elem in self.fixef.columns if elem not in self.coefs.index]]
    326 
    327         #Sort column order to match population coefs
~/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in __getitem__(self, key)
   2131         if isinstance(key, (Series, np.ndarray, Index, list)):
   2132             # either boolean or fancy integer index
-> 2133             return self._getitem_array(key)
   2134         elif isinstance(key, DataFrame):
   2135             return self._getitem_frame(key)
~/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in _getitem_array(self, key)
   2175             return self._take(indexer, axis=0, convert=False)
   2176         else:
-> 2177             indexer = self.loc._convert_to_indexer(key, axis=1)
   2178             return self._take(indexer, axis=1, convert=True)
   2179 
~/anaconda3/lib/python3.6/site-packages/pandas/core/indexing.py in _convert_to_indexer(self, obj, axis, is_setter)
   1267                 if mask.any():
   1268                     raise KeyError('{mask} not in index'
-> 1269                                    .format(mask=objarr[mask]))
   1270 
   1271                 return _values_from_object(indexer)
KeyError: '[0 1] not in index'

can't find dll

Windows 7 running Anaconda, python 2.7, 32-bit with Spyder IDE. All packages satisfy the requirements.
The DLL is in the distribution's path.

Any suggestions would be appreciated. Thanks.

from pymer4.models import Lmer
Traceback (most recent call last):

File "", line 1, in
from pymer4.models import Lmer

File "C:\Program Files (x86)\Anaconda2\Lib\site-packages\pymer4_init_.py", line 2, in
from models import Lmer

File "C:\Program Files (x86)\Anaconda2\Lib\site-packages\pymer4\models.py", line 1, in
import rpy2.robjects as robjects

File "C:\Program Files (x86)\Anaconda2\Lib\site-packages\rpy2\robjects_init_.py", line 16, in
import rpy2.rinterface as rinterface

File "C:\Program Files (x86)\Anaconda2\Lib\site-packages\rpy2\rinterface_init_.py", line 87, in
_load_r_dll(R_HOME)

File "C:\Program Files (x86)\Anaconda2\Lib\site-packages\rpy2\rinterface_init_.py", line 64, in _load_r_dll
ctypes.CDLL(r_dll)

File "C:\Program Files (x86)\Anaconda2\lib\ctypes_init_.py", line 362, in init
self._handle = _dlopen(self._name, mode)

WindowsError: [Error 126] The specified module could not be found

image

Add logistic regression

It would be great to add this without making sklearn a dependency...not sure if that's avoidable or not

Latest lme4 with rpy2 on conda-forge gives slightly different estimates

Noticed this when trying to fiddle with Travis failed tests vs local testing. Installing lme4 using R/RStudio up to version 1.1-23, vs installing thru conda-forge and calling it via rpy2 produce slightly different estimates when fits are close to singular. This is likely due to the different optimizer settings and updates to warnings made in recent version of lme4. It seems as tho the rpy2 call, runs lme4/lmerTest with a different optimizer/optimizer settings by default...not quite sure why.

One option to handle this is to deal with #13 such that optimizer settings can be adjusted during each .fit() call. Overall, this shouldn't be a huge issue as the differences are relatively minor (within +/- .01), but can cause certain tests to fail which have stricter threshold as in test_models.

[joss-review] Paper issues

A few minor issues with the paper:

  • in the example, get_resource_path is never defined, I believe you're missing the import statement from pymer4.utils import get_resource_path
  • the line model.plot('IV2') from your paper throws a NotImplementedError
  • replace langauge with language in the first paragraph
  • references have no DOIs

Suppress printing

I was wondering if I could make a PR with a verbose flag in .fit() that turns this print("Fitting linear model using... on and off.

I'm making 100,000's of calls to this function and I think it would be better not to print this.

rpy2>3.2.4 returns empty random effects

Hello, I've been using pymer4 for a few months now but only recently encountered this issue:
the Lmer module seems to be returning empty random effects variances. Not sure if this is due to R/rpy2/pymer4/pandas version incompatibility (3.6.3, 3.3.1, 0.7.0, 1.0.0, respectively) but even this simple example fails:

import seaborn as sns
import pymer4

data = sns.load_dataset('mpg')
model = pymer4.Lmer('mpg ~ weight + (1 | origin)', data)
model.fit()

Aggregate Lm2 model using first-level t-stats

Should add an option to use t-statistics from first-level OLS models instead of just coefficients. This has the effect if implicitly down-weighting noisy first-level estimates based on their standard-errors. However, it only makes sense if the dataset is balanced with respect to each first-level group (e.g. each individual has the same number of observations at the first level).

Update travis config pending dep fixes

Just opening an issue keep track of 2 bugs making testing on travis annoying right now:

  1. conda update conda tries to uninstall setuptools for some reason and fails because setuptools is a conda dependency....weird. Here's an example of other folks encountering this. For the time being conda update conda has been removed form the before_install section of the .travis.yml since we create a new environment for testing anyway.

  2. cffi a dependency of rpy2 was updated to 1.13 on conda-forge and is breaking rpy2>3. This is the the rpy2 bug for this, and conda-forge/rpy2-feedstock#35 is the issue tracking the proposed fix

Added basic OLS model

Would be nice to just have another model class e.g. Lm() to obviate the need to jump to other packages like statsmodels or sklearn.

I wrote the matrix math, including for robust standard error estimation already here so should be trivial to implement. Integration with patsy would be nice to preserve model formula specification.

rpy2 and pandas 0.24.2 compatibility

Looks like there's currently a type conversion issue where newer version of pandas expect categorical types and rpy2 may not automatically convert them. Keeping note of the error here to revisit in the future. For now we're fixing the pandas requirement to version 0.23.4

TypeError: Parameter 'categories' must be list-like, was <rpy2.rinterface.StrSexpVector - Python:0x7fca505dcd38 / R:0x564cb91259a8>

Occurs at self.marginal_estimates = pandas2ri.ri2py(base.summary(res)[0]) in Lmer.post_hoc

Add ANOVA table

Most of the code is there to perform this, but it would be convenient to force check of orthogonal contrasts, and auto-reparameterize if not. Maybe not worth it?

[joss-review] Installation instructions

I just tried to install this and failed brew install gcc installed gcc-8 rather than gcc-7.

Is it possible to fix the recommend bash command that sets the CC environment variable to use either?

Also, it may make sense to provide conda specific installation instructions: for users with no R installation, installing rpy2 from conda-forge is likely the most frictionless way of installing R; by the looks of it, lmerTest and lsmeans are also on conda-forge.

If you're not so familiar with conda I can take a stab at that.

Update docs for installation on new mac OS

The installation issues section providing info about using homebrew to install gcc should be moved to the core installation section, because this appears necessary on all recent mac OS versions trying to install rpy2

installation failed on ubuntu 16.04

Hi Eshin Jolly,

I tried to install with both methods

pip3 install pymer4
pip3 install git+https://github.com/ejolly/pymer4

cannot import name 'main'

Is this because of the missing R packages? (if so, a more helpful error message would be nice)
I installed all R packages and created a seperate virtualenv, now it seems to install.

PyPi refresh

Dear Eshin,

Would you mind uploading the updated version of pymer4 to PyPi so it can be pip installed?

Question about fixef, ranef, and coefs

Hi ejolly, thanks for the project. I've been running mixed effect logistic regression in python and this library is really helpful. I have one question about the outputs:

Seems like mode.fixef actually refers to the coef(model) in R. Model.coefs refers to the output in the summary(model) in R, which is correspondent to fixef(model) in lme4. Wanted to confirm that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.