spreg.likratiotest¶
-
spreg.
likratiotest
(reg0, reg1)[source]¶ Likelihood ratio test statistic [Gre03]
- Parameters
- reg0regression object
for constrained model (H0)
- reg1regression object
for unconstrained model (H1)
- Returns
- likratiodictionary
contains the statistic (likr), the degrees of freedom (df) and the p-value (pvalue)
- likrfloat
likelihood ratio statistic
- dfinteger
degrees of freedom
- p-valuefloat
p-value
Examples
>>> import numpy as np >>> import libpysal >>> from libpysal import examples >>> import scipy.stats as stats >>> from spreg import ML_Lag, OLS >>> from spreg import likratiotest
Use the baltim sample data set
>>> db = libpysal.io.open(examples.get_path("baltim.dbf"),'r') >>> y_name = "PRICE" >>> y = np.array(db.by_col(y_name)).T >>> y.shape = (len(y),1) >>> x_names = ["NROOM","NBATH","PATIO","FIREPL","AC","GAR","AGE","LOTSZ","SQFT"] >>> x = np.array([db.by_col(var) for var in x_names]).T >>> ww = libpysal.io.open(examples.get_path("baltim_q.gal")) >>> w = ww.read() >>> ww.close() >>> w.transform = 'r'
OLS regression
>>> ols1 = OLS(y,x)
ML Lag regression
>>> mllag1 = ML_Lag(y,x,w)
>>> lr = likratiotest(ols1,mllag1)
>>> print("Likelihood Ratio Test: {0:.4f} df: {1} p-value: {2:.4f}".format(lr["likr"],lr["df"],lr["p-value"])) Likelihood Ratio Test: 44.5721 df: 1 p-value: 0.0000