Week 2 Flashcards
Write one line of code that would simulate three dice rolls
np.random.choice(arange (1,7), 3)
Write a line of code that would decide whether this is a ‘poker’
if np.std(x) == 0:
What does the following lines of code denote?
stats. norm.rvs(0, 1, 100)
stats. binom.rvs(1, .5, 100)
stats. norm.rvs(0, 1, 100) generates a normal distribution with a mean of 0, std of 1 and n of 100
stats. binom.rvs(1, .5, 100) generates a binomial distribution with a probability of 0.5 and an n of 100
What do the following lines of code denote:
stats. norm.ppf(0.946)
stats. norm.rvs(0, 1, 50)
stats. norm.cdf(2)
stats. norm.pdf(2)
stats. norm.cdf(2) = the probability of being at the left side of the distribution at a z value of 2
stats. norm.pdf(2) = the height of the distribution at a z value of 2
stats. norm.ppf(0.946) = gets a z value for the probability area from the left of that z value
stats. norm.rvs(0, 1, 50) = generates data from the distribution
How to get a pvalue using a t test in python
alpha = 0.05 n = 100 x = stats.norm.rvs(loc=0.0, scale=1.0, size=n)
pg. ttest(x, 0)
pg. ttest(x, 0)[‘p-val’][0] pg.ttest(x, 0)[‘p-val’][0] < alpha
Show a code which computes the power of the simulated t test
Add effect to the values at the start:
n=100;effect=.3;std=1; alpha=.05;replications=500
rejections = np.zeros(replications)
for i in range(0, replications): x = stats.norm.rvs(loc=effect, scale=std, size=n) if pg.ttest(x, 0)[‘p-val’][0] < alpha: rejections[i] = 1
print(np.mean(rejections)) # power
essentially the mean of the rejections with the location as the effect size
How can you compute the power analytically?
df=99;ncp=effect/(std/np.sqrt(n))
print(1 - stats.t.cdf(stats.t.ppf(1-alpha/2, df), df, loc=ncp))
or:
pg.power_ttest(effect, n, alpha=alpha, contrast=’one-sample’)
What is the power to detect an effect = 0?
Alpha! (0.05)
The Z value for 95% confidence is Z=1.96.
Some students answered qnorm(.95) or stats.norm.ppf(.95). What goes wrong?
We need 2.5 % on both sides to calculate a two-sided confidence interval, thus use qnorm(.975) in R and stats.norm.ppf(.975) in Python.
What is the relationship between power and assumptions?
The more assumptions you have, the higher the power
Compare the wilcox test to the t test
It carries out the same task but is based on ranks (no normal distribution assumed, non parametric). It just requires that the data is symmetrical
wilcox.test(x,mu=0)
Name a similar technique to the t test and wilcox test and how it differs
proportion test - nominal with no assumptions at all!
prop.test(sum(x>0),n)
Checks whether each value is larger than 0 or not, if it is then it adds a 1
For asssignment 6 we compared the power of the parametric, non parametric and nominal test in a solution for n=100,effect=3,std=1.
What was concluded?
power Parametric (t test) and nonparametric (wilcox) comparable but power nominal test (proportion test) seriously lower
How is the cusp catastrophe related to Jaap’s research?
When people start smoking, relapse in depression, fall asleep etc
How does Jaap relate a catastrophe to perception?
visual illusions e.g the cube which jumps in how you perceive it. Made a mathematical formula for it.