Created
July 22, 2015 07:01
-
-
Save adamcc/e5d131d069227e2decfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Example of using scikits.bootstrap" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Import all the modules needed" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import scikits.bootstrap as bootstrap\n", | |
"%matplotlib inline" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Create an array" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[[ 0. 1. 2.]\n", | |
" [ nan 4. 5.]\n", | |
" [ 6. 7. 8.]\n", | |
" [ nan 10. 11.]\n", | |
" [ 12. 13. 14.]\n", | |
" [ nan 16. 17.]\n", | |
" [ 18. 19. 20.]\n", | |
" [ nan 22. 23.]\n", | |
" [ 24. 25. 26.]\n", | |
" [ nan 28. 29.]\n", | |
" [ 30. 31. 32.]\n", | |
" [ nan 34. 35.]]\n" | |
] | |
} | |
], | |
"source": [ | |
"ma = np.arange(36.).reshape(12,3)\n", | |
"idx = np.array([False, False, False, True, False, False] * 6).reshape(12,3)\n", | |
"ma[idx] = np.nan\n", | |
"print ma" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[ 1. 4.5 7. 10.5 13. 16.5 19. 22.5 25. 28.5 31. 34.5]\n" | |
] | |
} | |
], | |
"source": [ | |
"medians = np.nanmedian(ma, axis=1)\n", | |
"print medians" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[ 3. , 8.5, 9.5],\n", | |
" [ 27. , 26.5, 27.5]])" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CIzero = bootstrap.ci(data=ma, statfunction=lambda x: np.nanmedian(x,axis = 0), n_samples=1000, method='pi')\n", | |
"CIzero" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[ 0., 4., 6., 10., 12., 16., 18., 22., 24., 28., 30.,\n", | |
" 34.],\n", | |
" [ 2., nan, 8., nan, 14., nan, 20., nan, 26., nan, 32.,\n", | |
" nan]])" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CIT = bootstrap.ci(data=ma.T, statfunction=lambda x: np.nanmedian(x,axis = 0), n_samples=1000, method='pi')\n", | |
"CIT" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[ 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. ,\n", | |
" 1. , 1. , 1. ],\n", | |
" [ 34.5, 34.5, 34.5, 34.5, 34.5, 34.5, 34.5, 34.5, 34.5,\n", | |
" 34.5, 34.5, 34.5]])" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"CIone = bootstrap.ci(data=ma, statfunction=lambda x: np.nanmedian(x,axis = 1), n_samples=1000, method='pi')\n", | |
"CIone" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment