Questions tagged [patsy]

A Python library for describing statistical models and building design matrices, aimed at bringing the convenience of R “formulas” to Python.

113 questions
0
votes
0 answers

Python statsmodels 2 way ANOVA PatsyError and ValueError problems

Trying to use statsmodels in Python for a 2 way ANOVA and getting a PatsyError (Tried using pingouin as well, also posted about that issue in another post). Here is my code where param is a variable I define earlier and data_rostral is my data…
Kat
  • 1
0
votes
1 answer

PatsyError: model is missing required outcome variables

When I try to run this model y, X =dmatrices('price - area + bedrooms + bathrooms', df, return_type='dataframe') vif=pd.DataFrame() vif["VIF Factor"]=[variance_inflation_factor(X.values, i) for i in…
0
votes
1 answer

Pandas Time (not Date) differences and not as object

I would like to convert my timestamp columns into a regressor for the ML model. I need it to be a spline - one continuous variable (one column in the design matrix X), as opposed to a one-hot codded discretized intervals. In my original data, I have…
Petr
  • 1,606
  • 2
  • 14
  • 39
0
votes
1 answer

PatsyError: Number of rows mismatch between data argument and type (29 versus 1)

I am trying to Construct a Poisson regression model and while doing the below code it turning out an Patsy error as Number of rows mismatch between data argument and type (29 versus 1): import pandas as pd from patsy import dmatrices import numpy as…
Zerone
  • 127
  • 1
  • 12
0
votes
1 answer

Obtaining error in PLY that doesn't make sense: `Syntax error at '('`

I'm writing a string parser to do something akin to Patsy I've got the operators working (:, +, -, /, etc.) but I can't seem to get functions working. I'm only copy-pasting the functions directly related from ply import yacc, lex em_data = {'a':…
IanQ
  • 1,831
  • 5
  • 20
  • 29
0
votes
0 answers

How to use the smoothed line with patsy cr in production?

I smooth a set of features using patsy cr (with natural splines) however confused with something looking very basic. Here is a sample raw data points and corresponding smoothed points by patsy. x = df[feature] y = np.log(df['varTarget']) x_val…
mlee_jordan
  • 772
  • 4
  • 18
  • 50
0
votes
0 answers

Patsy Dmatrices X, y split

Using patsy.dmatrices to split my data into y,x and I am losing observations. Ex: formula = 'target ~ v1 + v2 + v3' y, x = patsy.dmatrices(formula, df, return_type = 'dataframe') My df.shape is ~ 54,000,000 length, however following x/y split, my…
0
votes
1 answer

Value Error using Patsy for a Logistic Regression Model

I have made an extremely simple logistic model for the purpose of my question. Here is the code below; import patsy import pandas as pd import statsmodels.api as sm df = pd.DataFrame() for i in range(5): df.at[i, 'response'] = 1 if i ==…
Jim White
  • 13
  • 3
0
votes
0 answers

Patsy equivalent for the Fixed effects model

I am trying to create a Fixed Effects model on Python using the following Python code - t = time model = feols(y ~ g1*p + t + geo + indus| geo^t + indus^t , data=data) What would be its patsy equivalent? How can we create this on PanelOLS?
K. K.
  • 552
  • 1
  • 11
  • 20
0
votes
1 answer

TypeError: 'DesignMatrix' object is not callable

I am trying to create B-splines with the patsy package on a ipynb notebook on JupyterLab: from patsy import dmatrix bs = dmatrix("bs(x, df=50, degree=1) - 1", {"x": x}) axes[0].plot(x, bs) axes[0].set_title("Basis functions") plt.show() This…
SOFe
  • 7,867
  • 4
  • 33
  • 61
0
votes
0 answers

Multiple Categorical Variables in Patsy Formula

I have some data, with multiple Categorical elements. I'd like to model them using regression, using the patsy formula used with statsmodels for convinience. When only using one categorical variable, as in the formula 'C(Weekday, Treatment) - 1', it…
JoshuaO
  • 33
  • 1
  • 3
0
votes
1 answer

Converting a simple regression to a logarithmic scale with patsy, statsmodels

I am following an online econometrics course and learning stats models while I go. I know from the instructor that this regression will have a better fit on a logarithmic scale, but I don't know how or where to convert my data / formula. I am using…
0
votes
1 answer

How to test if regression coefficients in SLR are equal using statsmodels.formula?

the title already defined my problem so let me start by giving an example: import statsmodels.formula.api as smf import numpy as np import pandas as pd data = pd.DataFrame( {'x1' : np.arange(1,10) , 'x2' : np.random.normal(scale=2,size=9) , 'x3' :…
crabnebul
  • 124
  • 1
  • 7
0
votes
0 answers

How do I get raw coefficients from bspline when using Patsy in pystatsmodels

I'm running a GLM and have to hand over discrete values that come from the variable*coefficient to our IT department. That said, I'm not sure how to calculate the slopes in a piecewise regression model using the bs() function from patsy. Let's…
Jordan
  • 1,415
  • 3
  • 18
  • 44
0
votes
0 answers

How to properly use new version of a Package in Python (patsy)? Have already Installed, but it continues to use the old version

On my Python 3.7.2, I need the package patsy 0.5.1 -pip install patsy (led to 0.5.1) being installed The following code still shows patsy 0.5.0 import patsy patsy.__version__ pip uninstall patsy AND pip uninstall patsy==0.5.0 lead to only 0.5.1…
Shaner
  • 73
  • 1
  • 10