forked from statsmodels/statsmodels
-
Notifications
You must be signed in to change notification settings - Fork 25
Scratch Notes
josef-pkt edited this page Jun 2, 2012
·
5 revisions
>>> import os >>> import json >>> import statsmodels.stats.tests >>> cur_dir = statsmodels.stats.tests.__path__[0] >>> fp = open(os.path.join(cur_dir, "results", "influence_lsdiag_R.json")) >>> lsdiag = json.load(fp) >>> fp.close() >>> lsdiag.keys() [u'cooks', u'std.res', u'dfits', u'std.err', u'std.dev', u'correlation', u'cov.unscaled', u'stud.res', u'hat', u'cov.scaled']
used in statsmodels\stats\tests\test_diagnostic.py
example : export results from R using json
library(lmtest) library(sandwich) library(rjson) options(digits=20) mkhtest <- function(ht, name, distr="f") { cat(name); cat(" = dict("); cat("statistic="); cat(ht$statistic); cat(", "); cat("pvalue="); cat(ht$p.value); cat(", "); cat("parameters=("); cat(ht$parameter, sep=","); cat(",), "); cat("distr='"); cat(distr); cat("'"); cat(")"); cat("\n\n") } d = read.csv("path_to\\statsmodels\\datasets\\macrodata\\macrodata.csv", header=TRUE) names(d) dinv <- diff(d$realinvs) dgdp = diff(d$realgdp) lint = d$realint[1:202] tbilrate = d$tbilrate[1:202] ginv <- 400 * diff(log(d$realinv)) ggdp <- 400 * diff(log(d$realgdp)) d2 = data.frame(ginv, ggdp, lint, tbilrate) fm_level <- lm(realinv ~ realgdp + realint, data = d) fm <- lm(ginv ~ ggdp + lint, data=d2) nw = NeweyWest(fm, lag = 4, prewhite = FALSE, verbose=TRUE) nw nw2 = NeweyWest(fm, prewhite = FALSE, verbose=TRUE) nw2 rt = raintest(fm) mkhtest(rt, 'raintest', 'f') jt = jtest(fm, lm(ginv ~ ggdp + tbilrate)) toJSON(jt)