##// END OF EJS Templates
Moved more code to Strings utilities file
Moved more code to Strings utilities file

File last commit:

r10386:6416b524
r10434:855e7b47
Show More
test_display.ipynb
336 lines | 84.4 KiB | text/plain | TextLexer
In [3]:
from IPython.core.displaypub import publish_display_data
%load_ext rmagic

publish_display_data('Assignment1', {'text/html':'<h2>Question 1</h2>'})

Question 1

In [4]:
%%R 
X = rnorm(40)
Y = rnorm(40)
plot(X,Y, pch=24, bg='red', cex=2)
No description has been provided for this image
In [5]:
publish_display_data('Assignment1',{'text/latex':r'''What is the correlation, $\rho$?  We could also have plotted with matplotlib...'''})
What is the correlation, $\rho$? We could also have plotted with matplotlib...
In [6]:
import pylab
%Rpull X Y
pylab.scatter(X, Y, c='r')
pylab.gca().set_xlabel('X')
pylab.gca().set_ylabel('Y')
Out[6]:
<matplotlib.text.Text at 0xba0dfd0>
In [7]:
publish_display_data('Assignment1',{'text/html':r'''We might include some other html stuff, too. 

<iframe width="560" height="315" src="http://www.youtube.com/embed/sf49cw0134U" 
frameborder="0" allowfullscreen></iframe>'''})
We might include some other html stuff, too.
In [8]:
publish_display_data('Assignment1',{'text/html':'<h2>Answer</h2>'})

Answer

In [9]:
publish_display_data('Assignment', {'text/html': '''<input type="radio" name="group1" value="Milk"> Milk<br>
<input type="radio" name="group1" value="Butter" checked> Butter<br>'''})
Milk
Butter

Magics

In [10]:
run magics/homework.py
In [11]:
%%MultipleChoiceSetup 1

X = rnorm(200)
Y = rnorm(200)
plot(X,Y)

Question 1

No description has been provided for this image
In [12]:
%%MultipleChoiceQuestion 1

question_text = 'Is the correlation:'
choices = ['positive', 'negative', 'zero']
Is the correlation:
zero
negative
positive
In [23]:
%%MultipleChoiceSetup 2

X = rnorm(20)
Y = rnorm(20) + Y
print(summary(lm(Y~X)))

true_corr = cor(X,Y)

Question 2

Call:
lm(formula = Y ~ X)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.9189 -0.9845 -0.5326  1.1005  2.5939 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.3573     0.3301   1.082    0.293
X             0.5617     0.4137   1.358    0.191

Residual standard error: 1.445 on 18 degrees of freedom
Multiple R-squared: 0.09288,	Adjusted R-squared: 0.04248 
F-statistic: 1.843 on 1 and 18 DF,  p-value: 0.1914 

In [24]:
true_corr = %R cor(X,Y)
In [27]:
%%MultipleChoiceQuestion 2

question_text = r'Up to 1 significant digit, what is the correlation between $X$ and $Y$?'

while True:
    choices = ['%0.1f' % c for c in list(np.random.random(size=(3,))*2-1) + [true_corr]]
    if len(set(choices)) == 4 :
        break
Up to 1 significant digit, what is the correlation between $X$ and $Y$?
0.1
-0.8
0.3
-0.2
In [14]: