Formal Simulated Inference

  1. Define F (i.e. your model and assumptions)
  2. Formalize test
  3. Describe test statistic
  4. A. Sample data from F∈ℱ0 B. Sample data from F∈ℱA
  5. A. Plot power vs n (i.e. perspective power analysis) B. Plot power vs n (i.e. perspective power analysis)
  6. Apply to data

Step 1: Define model and assumptions

Model

F(X,Y) | ~ Histogram Data

a) $F(I,k) = \{ F(I|k)*F(k) \}$

$F(k)= \{0,1\}$

  • 0 = Control Image
  • 1 = Cocaine Image

b) $F(I,k) = \{ F(I|k)*F(k) \}$

$F(k)= \{0,1\}$

Assumption

Step 2: Formalize test

H0:

  1. $F(I,0) > || = F(I,1)$
  2. $F(I,0) < ||= F(I,1)$

  3. The maximum gray value for Cocaine stimulated brain is equal to the control brain.

  4. The maximum gray value for fear induced brain is equal the control brain.

HA:

  1. $F(I,0) < || != F(I,1)$
  2. $F(I,0) > || != F(I,1)$

  3. The maximum gray value for Cocaine stimulated brain is greater than the control brain.

  4. The maximum gray value for fear induced brain is lower than the control brain.

Step 3. Test Statistic

$$F(i,j) = floor((L-1)sum_{n=0}^{F(i,j)} {P_n} )$$

$P_n$ = Number of pixels of intensity n / Total number of pixels

$F(I) = mean (F(i,j))$ % mean gray value in the image

Requirements to run the program

In order to run the program, we need to install the packages in python

PyQt4 install from tar file

SIP install from tar file

matplotlib,numpy,jgraph,vispy,nibabel (use pip install or pip2 install)

If you have trouble downloading PyQt please try to pip install pyglet


In [1]:
import os
PATH="/Users/david/Desktop/CourseWork/TheArtOfDataScience/claritycontrol/code/scripts/" # use your own path
os.chdir(PATH)

import clarity as cl  # I wrote this module for easier operations on data

import matplotlib.pyplot as plt
import jgraph as ig
%matplotlib inline

In [2]:
# create a instance
c = cl.Clarity("Fear199")
# load image, to points # takes a while to process the data
# * threshold rate is used to cut off some noise data.
# * sample is sampling rate
# show histogram
c.loadImg().imgToPoints(threshold=0.02,sample=0.3).showHistogram(bins=256)


Image Loaded: ../data/raw/Fear199.img
Coverting to points...
token=Fear199
total=600735744
max=10950.000000
threshold=0.020000
sample=0.300000
(This will take couple minutes)
Above threshold=7494125
Samples=2248985
Finished

In [3]:
b = cl.Clarity("Cocaine174")
b.loadImg(info=False).imgToPoints(threshold=0.08,sample=0.1).showHistogram(bins=256)


Image Loaded: ../data/raw/Cocaine174.img
Coverting to points...
token=Cocaine174
total=751091775
max=3693.000000
threshold=0.080000
sample=0.100000
(This will take couple minutes)
Above threshold=24213169
Samples=2421829
Finished

In [4]:
a = cl.Clarity("Control239")
a.loadImg(info=False).imgToPoints(threshold=0.04,sample=0.3).showHistogram(bins=256)


Image Loaded: ../data/raw/Control239.img
Coverting to points...
token=Control239
total=675840000
max=3742.000000
threshold=0.040000
sample=0.300000
(This will take couple minutes)
Above threshold=81211864
Samples=24367078
Finished

In [ ]:
# save points to csv file
# load directly from points data, instead of the origin data
c.loadImg().imgToPoints(threshold=0.04,sample=0.5).savePoints()

# load from points data file
# show on 3D graph, GPU intensive
c.loadPoints().show()

In [5]:
# A screen shot
from IPython.display import Image
from IPython.core.display import HTML 
Image(url= "https://raw.githubusercontent.com/Upward-Spiral-Science/claritycontrol/master/figs/a04/3dvisualdemo.png")


Out[5]:

Reflect

We can infer from the histogram plots that the maximum gray values in cocaine stimulated brain is higher than the control brain. This is conclusive with the alternative hypothesis. This also agrees with literature that indicates that the brain is more active when stimulated by cocaine, thereby lighting up more than the control brain.