Astrophysicist. Data scientist. Professor. Research Scientist. Team Leader. Curious person.
My website: rodrigonemmen.com
My Research Team’s website: blackholegroup.org
- Email: [email protected] (this is an alias to minimize spam)
- LinkedIn: nemmen
Miscellaneous methods for Astronomy and Data Science. Array methods, statistical distributions, computing goodness-of-fit, numerical simulations and much more
License: MIT License
Astrophysicist. Data scientist. Professor. Research Scientist. Team Leader. Curious person.
My website: rodrigonemmen.com
My Research Team’s website: blackholegroup.org
I was calculating some linear regression using BSCES and wanted to plot the prediction limits.
The module nmmn.stats.predbandnl raises a NameError exception saying that the function evalfun is not defined.
looking at the code under stats.py suggest that we are just missing a import section and import names
from . import misc
I have fixed this myself on my installation but this is just an FYI
Thanks for making these nice tools!
NameError Traceback (most recent call last)
in
23 lci_fb, uci_fb, xarray_fb = nmmn.stats.confbandnl(lir_fb, lx_fb, func, fitm_fb, covm_fb, 2, 0.95, xarray)
24
---> 25 lpi_sb, upi_sb, xarray_sb = nmmn.stats.predbandnl(lir_sb, lx_sb, func, fitm_sb, covm_sb, 2, 0.95, xarray)
26 #lpi_hb, upi_hb, xarray_hb = nmmn.stats.predbandnl(lir_hb, lx_hb, func, fitm_hb, covm_hb, 2, 0.95, xarray)
27 #lpi_fb, upi_fb, xarray_fb = nmmn.stats.predbandnl(lir_fb, lx_fb, func, fitm_fb, covm_fb, 2, 0.95, xarray)
~/.local/lib/python3.8/site-packages/nmmn/stats.py in predbandnl(xd, yd, fun, par, varcov, deg, conf, x)
540
541 # Residual sum of squares
--> 542 rss=residual(yd, evalfun(fun,xd,par) )
543
544 grad,p=[],[]
NameError: name 'evalfun' is not defined
I have been using BCES in conjunction with nmmn for weighted linear regression and bootstrapping. It has been working fantastically so far. I have a question on usage between confband and confbandl. The documentation mentioned confband is for linear, while confbandl is nonlinear, the latter of which is used in the BCES example and modified for a weighted LR based on the function. I have been testing both stats modules, and I was surprised to see such a difference even when using BCES as my LR in both for the same dataset. Am I using one of these incorrectly? I originally thought to use stats.confbandl, but it seems from the documentation that stats.confband is more appropriate.
Edit: I also did this test with a random Gaussian distribution dataset, where the confbandl gave CI that were 2 orders of mag larger than expected, and the confband ones were within %5 of expectations. That's why I ultimately decided on utilizing confband. https://github.com/jrcooper91/van_der_Wel_size-mass/blob/master/Testing_bootstraps_BCES%20.ipynb
stats.confband
x = np.array([ 0.0630552 ,0.138341,0.150978,1.509820,2.83197654,6.79663764,10.445637])
y = np.array([ 1.48, 1.14, 1.16, 1.15, 1.43, 1.43, 1.22])
yer = np.array([ 1.395, 0.1 , 0.275, 0.12 , 0.235, 0.135, 0.155])
sort = np.argsort(x)
x = x[sort]
x = np.array(x)
y = y[sort]
y = np.array(y)
yer = yer[sort]
yer = np.array(yer)
xer=zeros(len(x))
cov=zeros(len(x)) # no correlation between error measurements
i=0
nboot = 10000
a,b,erra,errb,covab=bces.bces.bcesp(x,xer,y,yer,cov,nboot)
ybces=a[3]*x+b[3]
# Gets lower and upper bounds on the confidence band
lcb1,ucb1,x=nmmn.stats.confband(x, y, a[i], b[i], 0.68, x)
lcb2,ucb2,x2=nmmn.stats.confband(x, y, a[i], b[i], 0.95, x)
lcb3,ucb3,x3=nmmn.stats.confband(x, y, a[i], b[i], 0.997, x)
errorbar(x,y,yerr=yer,fmt='o')
ax = plot(x,ybces,'-k')
ax = fill_between(x, lcb1, ucb1, alpha=0.6, facecolor='purple')
ax = fill_between(x, lcb2, ucb2, alpha=0.3, facecolor='blue')
ax = fill_between(x, lcb3, ucb3, alpha=0.4, facecolor='grey')
ax = xlabel('x')
ax = ylabel('y')
plt.show()
x = np.array([ 0.0630552 , 0.13834198, 0.15097889, 1.50982026, 2.83197654, 6.79663764, 10.44563709])
y = np.array([ 1.48, 1.14, 1.16, 1.15, 1.43, 1.43, 1.22])
yer = np.array([ 1.395, 0.1 , 0.275, 0.12 , 0.235, 0.135, 0.155])
sort = np.argsort(x)
x = x[sort]
x = np.array(x)
y = y[sort]
y = np.array(y)
yer = yer[sort]
yer = np.array(yer)
xer=zeros(len(x))
cov=zeros(len(x)) # no correlation between error measurements
i=0
nboot = 10000
def func(x): return x[1]*x[0]+x[2]
a,b,erra,errb,covab=bces.bces.bcesp(x,xer,y,yer,cov,nboot)
ybces=a[3]*x+b[3] # the integer corresponds to the desired BCES method for plotting (3-ort, 0-y|x, 1-x|y, don't use bissector)
# array with best-fit parameters
fitm=np.array([ a[i],b[i] ])
# covariance matrix of parameter uncertainties
covm=np.array([ (erra[i]**2,covab[i]), (covab[i],errb[i]**2) ])
# Gets lower and upper bounds on the confidence band
lcb1,ucb1,xcb1=nmmn.stats.confbandnl(x,y,func,fitm,covm,2,0.68,x)
lcb2,ucb2,xcb2=nmmn.stats.confbandnl(x,y,func,fitm,covm,2,0.95, x)
lcb3,ucb3,xcb3=nmmn.stats.confbandnl(x,y,func,fitm,covm,2,0.997, x)
errorbar(xcb1,y,yerr=yer,fmt='o')
ax = plot(x,ybces,'-k')
ax = fill_between(x, lcb1, ucb1, alpha=0.6, facecolor='purple')
ax = fill_between(x, lcb2, ucb2, alpha=0.3, facecolor='blue')
ax = fill_between(x, lcb3, ucb3, alpha=0.4, facecolor='grey')
ax = xlabel('x')
ax = ylabel('y')
plt.show()
I recently updated my version of nmmn,
and found that the wa.reconstruction() method called from
https://gist.github.com/rsnemmen/baea0541c6cc23ae2fbe48421ffc838e
is now inconsistent.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.