Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_install():
"""
Quick function to test installation by import a lmm object and fitting a quick model.
"""
try:
from pymer4.models import Lmer
from pymer4.utils import get_resource_path
import os
import pandas as pd
import warnings
warnings.filterwarnings("ignore")
df = pd.read_csv(os.path.join(get_resource_path(), "sample_data.csv"))
model = Lmer("DV ~ IV3 + (1|Group)", data=df)
model.fit(summarize=False)
print("Pymer4 installation working successfully!")
except Exception as e:
print("Error! {}".format(e))
This tutorial illustrates how to estimate a simple model with one continuous predictor. We're going to fit a model with random intercepts, slopes and their correlations. 95% confidence intevals will be estimated using the Wald-method assuming a quadratic likelihood surface.
"""
##########################################
# Import module and check out data
# --------------------------------
#
import os
import pandas as pd
import seaborn as sns
from pymer4.models import Lmer
from pymer4.utils import get_resource_path
df = pd.read_csv(os.path.join(get_resource_path(),'sample_data.csv'))
df.head()
print("Hello World!")
#######################################################################
# Estimate a model
# ----------------
#
# Initialize linear model with random intercepts, slopes and their correlation
model = Lmer('DV ~ IV2 + (IV2|Subject)',data=df)
#########################################################################
# Fit it
model.fit()
#%%
# Imports
# -------
import numpy as np
from matplotlib import pyplot as plt
from sklmer import LmerRegressor
import pandas as pd
import os
from pymer4.utils import get_resource_path
#%%
# Load and prepare data
# ---------------------
# split out training and test data
df = pd.read_csv(os.path.join(get_resource_path(), "sample_data.csv"))
df = df.reset_index().rename(columns={'index':'orig_index'})
test = df.groupby('Group').apply(lambda x: x.sample(frac=0.2)).reset_index(drop=True)
train = df.loc[~df.orig_index.isin(test.orig_index), :]
#%%
# Fit and predict with some different estimator options
# -----------------------------------------------------
# First with defaults.
df_estimator = LmerRegressor("DV ~ IV2 + (IV2|Group)", X_cols=df.columns)
df_estimator.fit(data=train)
df_preds = df_estimator.predict(test)
#%%
# Then use random effects information in the prediction.
This tutorial illustrates how to estimate a simple model with one continuous predictor. We're going to fit a model with random intercepts, slopes and their correlations. 95% confidence intevals will be estimated using the Wald-method assuming a quadratic likelihood surface.
"""
##########################################
# Import module and check out data
# --------------------------------
#
import os
import pandas as pd
import seaborn as sns
from pymer4.models import Lmer
from pymer4.utils import get_resource_path
df = pd.read_csv(os.path.join(get_resource_path(),'sample_data.csv'))
df.head()
#######################################################################
# Estimate a model
# ----------------
#
# Initialize linear model with random intercepts, slopes and their correlation
model = Lmer('DV ~ IV2 + (IV2|Subject)',data=df)
#########################################################################
# Fit it
model.fit()
#######################################################################