I am trying to port this functionality into python
> x <- 0:10
> y <- x**2
> lm(y ~ ns(x,df=2))
Such as:
import numpy as np
import pandas as pd
import statsmodels.formula.api as smf
x = pd.DataFrame(np.arange(11))
y = x**2
formula="y ~ cr(x, df = 3)"
reg = smf.ols(formula,data=x).fit()
print(res.summary())
However with this python formulation, I cannot set df<3. Any suggestions how I can have a natural spline in python with two degrees of freedom, and use it in patsy as an R style equation?