-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
5,412 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,259 @@ | ||
{ | ||
"metadata": { | ||
"name": "", | ||
"signature": "sha256:3553b4d32a81fccc226a15ae64a44b3c949003587ff480af92bf3e64fc69edcc" | ||
}, | ||
"nbformat": 3, | ||
"nbformat_minor": 0, | ||
"worksheets": [ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"%matplotlib inline\n", | ||
"from IPython.display import display\n", | ||
"from math import log1p, sqrt\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import networkx as nx\n", | ||
"import numpy as np\n", | ||
"import pandas as pd\n", | ||
"import scipy.stats as sps\n", | ||
"\n", | ||
"\n", | ||
"#pylab.rcParams['figure.figsize'] = (14.0, 6.0)\n", | ||
"\n", | ||
"COLORS = ['#eff3ff', '#bdd7e7', '#6baed6', '#3182bd', '#08519c']\n", | ||
"\n", | ||
"\n", | ||
"DATA_SHARING_CREDIT_ANSWERS = [\"Authorship on paper\",\n", | ||
" \"Acknowledgement in the paper\",\n", | ||
" \"Data cited in the reference list\",\n", | ||
" \"Data cited informally in the text of the paper\",\n", | ||
" \"Not credited\",\n", | ||
" \"Not applicable\"]" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [], | ||
"prompt_number": 4 | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"EXCLUDE = {'role' : 'Librarian', 'discipline' : 'Information science', 'highest_degree' : 'Highschool', 'generated_data' : 'No'}\n", | ||
"\n", | ||
"responses = pd.read_csv('../Tables/DataPubSurvey_anon.csv')\n", | ||
"\n", | ||
"for column, value in EXCLUDE.iteritems():\n", | ||
" responses = responses[responses[column] != value]" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [], | ||
"prompt_number": 5 | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"You have quite a few non-significant findings reported, and it is not clear whether that is merely due to low power of detecting true findings.\n", | ||
"\n", | ||
"My gut feeling is that 250 researcher responses should be enough for adequate power, but since many readers will be skeptical, better that you demonstrate clearly and concretely what the limits of your sensitivity and power are in this particular survey." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"PAPER_DISCIPLINE_MAP = {'Anthropology' : 'Social science',\n", | ||
" 'Archaeology' : 'Archaeology',\n", | ||
" 'Area studies' : 'Social science',\n", | ||
" 'Economics' : 'Social science',\n", | ||
" 'Political science' : 'Social science',\n", | ||
" 'Psychology' : 'Social science',\n", | ||
" 'Sociology' : 'Social science',\n", | ||
" 'Astronomy' : 'Space science',\n", | ||
" 'Astrophysics' : 'Space science',\n", | ||
" 'Environmental Science' : 'Environmental science',\n", | ||
" 'Geology' : 'Earth science',\n", | ||
" 'Oceanography' : 'Environmental science',\n", | ||
" 'Planetary science' : 'Earth science',\n", | ||
" 'Biochemistry' : 'Biology',\n", | ||
" 'Bioinformatics' : 'Biology',\n", | ||
" 'Biology' : 'Biology',\n", | ||
" 'Evolutionary Biology' : 'Biology',\n", | ||
" 'Neurobiology' : 'Biology',\n", | ||
" 'Social science' : 'Social science',\n", | ||
" 'Space science' : 'Space science',\n", | ||
" 'Earth science' : 'Earth science',\n", | ||
" 'Life science' : 'Biology',\n", | ||
" 'Chemistry' : 'Physical science',\n", | ||
" 'Physics' : 'Physical science',\n", | ||
" 'Computer science' : 'Computer science',\n", | ||
" 'Mathematics' : 'Mathematics',\n", | ||
" 'Information science' : 'Information science',\n", | ||
" 'Other' : 'Other'} " | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [], | ||
"prompt_number": 6 | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"def checkbox_chi_square(question, answers, responses_ft=responses):\n", | ||
" \n", | ||
" # extract checkbox column and split responses into array\n", | ||
" #split_checkbox = responses[dvar].str.split(\"; \").dropna()\n", | ||
" split_checkbox = responses_ft[question].dropna()\n", | ||
"\n", | ||
"\n", | ||
" # DF of bools; responders x checkbox (checked = True) \n", | ||
" checkbox_responses = pd.DataFrame({name : split_checkbox.apply(lambda x: name in x) for name in answers})\n", | ||
"\n", | ||
" \n", | ||
" # DF of pairwise p-values\n", | ||
" pvalues = pd.DataFrame(index=answers, columns=answers)\n", | ||
"\n", | ||
" # DF of all the counts to test for overall significance\n", | ||
" total_square = pd.DataFrame(index=[True, False], columns=answers)\n", | ||
"\n", | ||
" i=0\n", | ||
" for a in answers:\n", | ||
" i +=1 \n", | ||
" # fill in T and F counts for this answer \n", | ||
" total_square[a] = checkbox_responses[a].value_counts()\n", | ||
"\n", | ||
" # separate series \n", | ||
"\n", | ||
" for b in answers[i:]:\n", | ||
"\n", | ||
" # initialize pairwise count table\n", | ||
" square = pd.DataFrame({ 0 : 0, 0 : 0}, index=[True, False], columns=[True, False]) \n", | ||
"\n", | ||
" # fill in counts\n", | ||
" square[True] = (checkbox_responses[checkbox_responses[a] == True][b].value_counts())\n", | ||
" square[False] = (checkbox_responses[checkbox_responses[a] == False][b].value_counts())\n", | ||
" \n", | ||
"\n", | ||
" count_table = square.as_matrix()\n", | ||
" \n", | ||
" \n", | ||
" if ~np.isnan(count_table).any():\n", | ||
" oddsratio, p = sps.fisher_exact(count_table)\n", | ||
" pvalues.ix[a, b] = p\n", | ||
"\n", | ||
" \n", | ||
" \n", | ||
" #t_chi2, t_p, t_df, t_expected = sps.chi2_contingency(total_square.as_matrix())\n", | ||
"\n", | ||
" #print \"total chi2= \" + str(t_chi2) + \", p= \" + str(t_p)\n" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [], | ||
"prompt_number": 9 | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"[15] -- Thursday, November 13, 2014 -- 13:33:31\n", | ||
"Exact - Proportions: Inequality, two independent groups (Fisher's exact test) \n", | ||
"\n", | ||
"Options:\tExact distribution\n", | ||
"\n", | ||
"Analysis:\tSensitivity: Compute required effect size \n", | ||
"Input:\t\tTail(s) \t=\tTwo\n", | ||
"\t\t\tEffect direction \t=\tp1\u2264p2\n", | ||
"\t\t\tProportion p2 \t=\t0.5\n", | ||
"\t\t\t\u03b1 err prob \t=\t0.05\n", | ||
"\t\t\tPower (1-\u03b2 err prob) \t=\t.8\n", | ||
"\t\t\tSample size group 1 \t=\t175\n", | ||
"\t\t\tSample size group 2 \t=\t175\n", | ||
"Output:\t\tProportion p1 \t=\t0.3468388\n", | ||
"\t\t\tActual power \t=\t0.7963223\n", | ||
"\t\t\tActual \u03b1 \t=\t0.0369551\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"len(set(PAPER_DISCIPLINE_MAP.values()))" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"metadata": {}, | ||
"output_type": "pyout", | ||
"prompt_number": 12, | ||
"text": [ | ||
"11" | ||
] | ||
} | ||
], | ||
"prompt_number": 12 | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"G\\*Power calculation of the effect size we can hope to see with 80% power and 11 disciplines" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"[16] -- Thursday, November 13, 2014 -- 13:36:44\n", | ||
"\u03c7\u00b2 tests - Goodness-of-fit tests: Contingency tables\n", | ||
"\n", | ||
"Analysis:\tSensitivity: Compute required effect size \n", | ||
"Input:\t\t\u03b1 err prob \t=\t0.05\n", | ||
"\t\t\tPower (1-\u03b2 err prob) \t=\t0.8\n", | ||
"\t\t\tTotal sample size \t=\t249\n", | ||
"\t\t\tDf \t=\t10\n", | ||
"Output:\t\tNoncentrality parameter \u03bb \t=\t16.2411103\n", | ||
"\t\t\tCritical \u03c7\u00b2 \t=\t18.3070381\n", | ||
"\t\t\tEffect size w \t=\t0.2553925" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"checkbox_chi_square('data_sharing_credit', DATA_SHARING_CREDIT_ANSWERS)" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"stream": "stdout", | ||
"text": [ | ||
"total chi2= nan, p= nan\n" | ||
] | ||
} | ||
], | ||
"prompt_number": 13 | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
} | ||
], | ||
"metadata": {} | ||
} | ||
] | ||
} |
Oops, something went wrong.