Я пытаюсь воспроизвести свой код логистической регрессии из SAS в Python
Ниже приведен мой код SAS:
proc logistic data=tempsh.data descending;
class var1
var2(ref='01')
var3(ref='01')
var4(ref='0')
var5(ref='1')
var6(ref='1')
var7(ref='0')
var8(ref='0')
var9(ref='0')
var10(ref='hospital')/ param=ref;
effect Time_spl = spline(Time / basis=tpf(noint) naturalcubic
knotmethod=equal(6));
model Dur = var1 var2 var3 var4 var5 var6
Time_spl
var8*Time_spl var9*Time_spl
var10*Time_spl
effectplot fit(x=Time) / noobs link;
oddsratio var1/ at(time=6 12 18 24 30 36 );
oddsratio var2/ at(time=6 12 18 24 30 36);
run;
quit;
Когда я пытаюсь создать естественные кубические сплайны, я вижу библиотеку под названием «patsy».
Вот мой код для создания натуральных кубических сплайнов;
# # https://patsy.readthedocs.io/en/latest/ ... regression
# # https://patsy.readthedocs.io/en/latest/ ... l#patsy.cr
# # Create the spline basis using Cr() with df=6
# spline_basis = dmatrix("cr(Time, df =6)-1", {"Time": df["Time"]}, return_type='dataframe')
# # Drop the intercept column if it exists
# if 'Intercept' in spline_basis.columns:
# spline_basis = spline_basis.drop(columns='Intercept')
# # Add the spline basis to the DataFrame
# df = pd.concat([df, spline_basis], axis=1)
# # Define the spline terms for the formula
# spline_terms = ' + '.join(spline_basis.columns)
Это правильный подход?
Кроме того, если я хочу указать заранее определенные узлы, я пробую что-то вроде:
# # https://patsy.readthedocs.io/en/latest/ ... regression
# # https://patsy.readthedocs.io/en/latest/ ... l#patsy.cr
# # Create the spline basis using Cr() with df=6
# spline_basis = dmatrix("cr(Time, knots=(8, 16, 24, 32, 40, 48))-1", {"Time": df["Time"]}, return_type='dataframe')
# # Add the spline basis to the DataFrame
# df= pd.concat([df, spline_basis], axis=1)
# # Define the spline terms for the formula
# spline_terms = ' + '.join(spline_basis.columns)
Подробнее здесь: https://stackoverflow.com/questions/789 ... ic-splines
Python — естественные кубические сплайны ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Ошибка интерпретатора PyCharm Python «Нет Python в 'C:\Program Files\Python38\python.exe'
Anonymous » » в форуме Python - 0 Ответы
- 58 Просмотры
-
Последнее сообщение Anonymous
-