Update on r codes

This commit is contained in:
mhjensen
2017-12-08 11:32:08 +01:00
parent 3eaf9e4578
commit dd90513eb3
30 changed files with 1431 additions and 206 deletions
@@ -176,7 +176,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
<br>
<p>
@@ -168,10 +168,13 @@ either Python or C++ as programming languages.
To add more entropy, <b>cython</b> can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing. For example, convert to latex as
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>jupyter nbconvert filename<span style="color: #666666">.</span>ipynb <span style="color: #666666">--</span>to latex
</pre></div>
<p>
This never ends.
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
@@ -163,26 +163,26 @@ MathJax.Hub.Config({
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read<span style="color: #666666">.</span>csv(<span style="color: #BA2121">&quot;src/Hudson_Bay.csv&quot;</span>,header<span style="color: #666666">=</span>T)
<!-- code=r (!bc r) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read.csv(<span style="color: #BA2121">&quot;src/Hudson_Bay.csv&quot;</span>,header<span style="color: #666666">=</span><span style="color: #008000">T</span>)
fix(HudsonBay)
dim(HudsonBay)
names(HudsonBay)
plot(HudsonBay$Year, HudsonBay$Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
attach(HudsonBay)
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>, col<span style="color: #666666">=</span><span style="color: #BA2121">&quot;red&quot;</span>, varwidth<span style="color: #666666">=</span>T, xlab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Years&quot;</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Haresx 1000&quot;</span>)
summary(HudsonBay)
summary(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
library(MASS)
library(ISLR)
scatter<span style="color: #666666">.</span>smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
linearMod <span style="color: #666666">=</span> lm(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span> <span style="color: #666666">~</span> Year)
<span style="color: #008000; font-weight: bold">print</span>(linearMod)
summary(linearMod)
<span style="color: #008000">dim</span>(HudsonBay)
<span style="color: #008000">names</span>(HudsonBay)
plot(HudsonBay<span style="color: #666666">$</span>Year, HudsonBay<span style="color: #666666">$</span>Hares..x1000.)
<span style="color: #008000; font-weight: bold">attach</span>(HudsonBay)
plot(Year, Hares..x1000.)
plot(Year, Hares..x1000., col<span style="color: #666666">=</span><span style="color: #BA2121">&quot;red&quot;</span>, varwidth<span style="color: #666666">=</span><span style="color: #008000">T</span>, xlab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Years&quot;</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Haresx 1000&quot;</span>)
<span style="color: #008000">summary</span>(HudsonBay)
<span style="color: #008000">summary</span>(Hares..x1000.)
<span style="color: #008000; font-weight: bold">library</span>(MASS)
<span style="color: #008000; font-weight: bold">library</span>(ISLR)
scatter.smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares..x1000.)
linearMod <span style="color: #666666">=</span> lm(Hares..x1000. <span style="color: #666666">~</span> Year)
<span style="color: #008000">print</span>(linearMod)
<span style="color: #008000">summary</span>(linearMod)
plot(linearMod)
confint(linearMod)
predict(linearMod,data<span style="color: #666666">.</span>frame(Year<span style="color: #666666">=</span>c(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">&quot;confidence&quot;</span>)
predict(linearMod,<span style="color: #B00040">data.frame</span>(Year<span style="color: #666666">=</span><span style="color: #B00040">c</span>(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">&quot;confidence&quot;</span>)
</pre></div>
<p>
</div>
@@ -163,26 +163,26 @@ MathJax.Hub.Config({
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set</span><span style="color: #666666">.</span>seed(<span style="color: #666666">1485</span>)
<span style="color: #008000">len</span> <span style="color: #666666">=</span> <span style="color: #666666">24</span>
x <span style="color: #666666">=</span> runif(<span style="color: #008000">len</span>)
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(<span style="color: #008000">len</span>, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
ds <span style="color: #666666">=</span> data<span style="color: #666666">.</span>frame(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
<span style="color: #008000">str</span>(ds)
<!-- code=r (!bc r) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set.seed</span>(<span style="color: #666666">1485</span>)
len <span style="color: #666666">=</span> <span style="color: #666666">24</span>
x <span style="color: #666666">=</span> runif(len)
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(len, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
ds <span style="color: #666666">=</span> <span style="color: #B00040">data.frame</span>(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
str(ds)
plot( y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span><span style="color: #BA2121">&quot;Known cubic with noise&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
s <span style="color: #666666">=</span> <span style="color: #008000">seq</span>(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=2</span>, col <span style="color: #666666">=</span><span style="color: #BA2121">&quot;green&quot;</span>)
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> I(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #008000">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> T)
class(m)
summary(m)
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
power<span style="color: #666666">.</span>se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> <span style="color: #008000">I</span>(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #B00040">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> <span style="color: #008000">T</span>)
<span style="color: #008000">class</span>(m)
<span style="color: #008000">summary</span>(m)
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(<span style="color: #008000">summary</span>(m)<span style="color: #666666">$</span>coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
power.se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(<span style="color: #008000">summary</span>(m)<span style="color: #666666">$</span>coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
plot(y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Fitted power model&quot;</span>, sub <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Blue: fit; green: known&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
s <span style="color: #666666">=</span> <span style="color: #008000">seq</span>(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=</span> <span style="color: #666666">2</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;green&quot;</span>)
lines(s, predict(m, <span style="color: #008000">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;blue&quot;</span>)
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, paste(<span style="color: #BA2121">&quot;y =x^ (&quot;</span>, power, <span style="color: #BA2121">&quot; +/- &quot;</span>, power<span style="color: #666666">.</span>se, <span style="color: #BA2121">&quot;)&quot;</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;&quot;</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
lines(s, predict(m, <span style="color: #B00040">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;blue&quot;</span>)
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, <span style="color: #008000">paste</span>(<span style="color: #BA2121">&quot;y =x^ (&quot;</span>, power, <span style="color: #BA2121">&quot; +/- &quot;</span>, power.se, <span style="color: #BA2121">&quot;)&quot;</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;&quot;</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
</pre></div>
<p>
</div>
@@ -176,7 +176,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
<br>
<p>
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>&nbsp;<br>
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
<br>
<p>
@@ -305,10 +305,13 @@ either Python or C++ as programming languages.
To add more entropy, <b>cython</b> can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing. For example, convert to latex as
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>jupyter nbconvert filename.ipynb --to latex
</pre></div>
<p>
This never ends.
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
</section>
@@ -806,26 +809,26 @@ plt.show()
<b></b>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>HudsonBay = read.csv(<span style="color: #CD5555">&quot;src/Hudson_Bay.csv&quot;</span>,header=T)
<!-- code=r (!bc r) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>HudsonBay = read.csv(<span style="color: #CD5555">&quot;src/Hudson_Bay.csv&quot;</span>,header=<span style="color: #658b00">T</span>)
fix(HudsonBay)
dim(HudsonBay)
names(HudsonBay)
plot(HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Year, HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Hares..x1000.)
attach(HudsonBay)
<span style="color: #8B008B; font-weight: bold">dim</span>(HudsonBay)
<span style="color: #8B008B; font-weight: bold">names</span>(HudsonBay)
plot(HudsonBay$Year, HudsonBay$Hares..x1000.)
<span style="color: #8B008B; font-weight: bold">attach</span>(HudsonBay)
plot(Year, Hares..x1000.)
plot(Year, Hares..x1000., col=<span style="color: #CD5555">&quot;red&quot;</span>, varwidth=T, xlab=<span style="color: #CD5555">&quot;Years&quot;</span>, ylab=<span style="color: #CD5555">&quot;Haresx 1000&quot;</span>)
summary(HudsonBay)
summary(Hares..x1000.)
library(MASS)
library(ISLR)
plot(Year, Hares..x1000., col=<span style="color: #CD5555">&quot;red&quot;</span>, varwidth=<span style="color: #658b00">T</span>, xlab=<span style="color: #CD5555">&quot;Years&quot;</span>, ylab=<span style="color: #CD5555">&quot;Haresx 1000&quot;</span>)
<span style="color: #8B008B; font-weight: bold">summary</span>(HudsonBay)
<span style="color: #8B008B; font-weight: bold">summary</span>(Hares..x1000.)
<span style="color: #8B008B; font-weight: bold">library</span>(MASS)
<span style="color: #8B008B; font-weight: bold">library</span>(ISLR)
scatter.smooth(x=Year, y = Hares..x1000.)
linearMod = lm(Hares..x1000. ~ Year)
<span style="color: #8B008B; font-weight: bold">print</span>(linearMod)
summary(linearMod)
<span style="color: #8B008B; font-weight: bold">summary</span>(linearMod)
plot(linearMod)
confint(linearMod)
predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">&quot;confidence&quot;</span>)
predict(linearMod,<span style="color: #00688B; font-weight: bold">data.frame</span>(Year=<span style="color: #00688B; font-weight: bold">c</span>(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">&quot;confidence&quot;</span>)
</pre></div>
</div>
@@ -838,26 +841,26 @@ predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<sp
<b></b>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #658b00">set</span>.seed(<span style="color: #B452CD">1485</span>)
<span style="color: #658b00">len</span> = <span style="color: #B452CD">24</span>
x = runif(<span style="color: #658b00">len</span>)
y = x^<span style="color: #B452CD">3</span>+rnorm(<span style="color: #658b00">len</span>, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
ds = data.frame(x = x, y = y)
<span style="color: #658b00">str</span>(ds)
<!-- code=r (!bc r) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">set.seed</span>(<span style="color: #B452CD">1485</span>)
len = <span style="color: #B452CD">24</span>
x = runif(len)
y = x^<span style="color: #B452CD">3</span>+rnorm(len, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
ds = <span style="color: #00688B; font-weight: bold">data.frame</span>(x = x, y = y)
str(ds)
plot( y ~ x, main =<span style="color: #CD5555">&quot;Known cubic with noise&quot;</span>)
s = seq(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
s = <span style="color: #8B008B; font-weight: bold">seq</span>(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
lines(s, s^<span style="color: #B452CD">3</span>, lty =<span style="color: #B452CD">2</span>, col =<span style="color: #CD5555">&quot;green&quot;</span>)
m = nls(y ~ I(x^power), data = ds, start = <span style="color: #658b00">list</span>(power=<span style="color: #B452CD">1</span>), trace = T)
class(m)
summary(m)
power = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
power.se = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
m = nls(y ~ <span style="color: #8B008B; font-weight: bold">I</span>(x^power), data = ds, start = <span style="color: #00688B; font-weight: bold">list</span>(power=<span style="color: #B452CD">1</span>), trace = <span style="color: #658b00">T</span>)
<span style="color: #8B008B; font-weight: bold">class</span>(m)
<span style="color: #8B008B; font-weight: bold">summary</span>(m)
power = <span style="color: #8B008B; font-weight: bold">round</span>(<span style="color: #8B008B; font-weight: bold">summary</span>(m)$coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
power.se = <span style="color: #8B008B; font-weight: bold">round</span>(<span style="color: #8B008B; font-weight: bold">summary</span>(m)$coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
plot(y ~ x, main = <span style="color: #CD5555">&quot;Fitted power model&quot;</span>, sub = <span style="color: #CD5555">&quot;Blue: fit; green: known&quot;</span>)
s = seq(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
s = <span style="color: #8B008B; font-weight: bold">seq</span>(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
lines(s, s^<span style="color: #B452CD">3</span>, lty = <span style="color: #B452CD">2</span>, col = <span style="color: #CD5555">&quot;green&quot;</span>)
lines(s, predict(m, <span style="color: #658b00">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">&quot;blue&quot;</span>)
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, paste(<span style="color: #CD5555">&quot;y =x^ (&quot;</span>, power, <span style="color: #CD5555">&quot; +/- &quot;</span>, power.se, <span style="color: #CD5555">&quot;)&quot;</span>, sep = <span style="color: #CD5555">&quot;&quot;</span>), pos = <span style="color: #B452CD">4</span>)
lines(s, predict(m, <span style="color: #00688B; font-weight: bold">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">&quot;blue&quot;</span>)
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, <span style="color: #8B008B; font-weight: bold">paste</span>(<span style="color: #CD5555">&quot;y =x^ (&quot;</span>, power, <span style="color: #CD5555">&quot; +/- &quot;</span>, power.se, <span style="color: #CD5555">&quot;)&quot;</span>, sep = <span style="color: #CD5555">&quot;&quot;</span>), pos = <span style="color: #B452CD">4</span>)
</pre></div>
</div>
@@ -140,7 +140,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -282,10 +282,13 @@ either Python or C++ as programming languages.
To add more entropy, <b>cython</b> can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing. For example, convert to latex as
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span>jupyter nbconvert filename.ipynb --to latex
</pre></div>
<p>
This never ends.
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
@@ -799,26 +802,26 @@ plt.show()
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span>HudsonBay = read.csv(<span style="color: #CD5555">&quot;src/Hudson_Bay.csv&quot;</span>,header=T)
<!-- code=r (!bc r) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span>HudsonBay = read.csv(<span style="color: #CD5555">&quot;src/Hudson_Bay.csv&quot;</span>,header=<span style="color: #658b00">T</span>)
fix(HudsonBay)
dim(HudsonBay)
names(HudsonBay)
plot(HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Year, HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Hares..x1000.)
attach(HudsonBay)
<span style="color: #8B008B; font-weight: bold">dim</span>(HudsonBay)
<span style="color: #8B008B; font-weight: bold">names</span>(HudsonBay)
plot(HudsonBay$Year, HudsonBay$Hares..x1000.)
<span style="color: #8B008B; font-weight: bold">attach</span>(HudsonBay)
plot(Year, Hares..x1000.)
plot(Year, Hares..x1000., col=<span style="color: #CD5555">&quot;red&quot;</span>, varwidth=T, xlab=<span style="color: #CD5555">&quot;Years&quot;</span>, ylab=<span style="color: #CD5555">&quot;Haresx 1000&quot;</span>)
summary(HudsonBay)
summary(Hares..x1000.)
library(MASS)
library(ISLR)
plot(Year, Hares..x1000., col=<span style="color: #CD5555">&quot;red&quot;</span>, varwidth=<span style="color: #658b00">T</span>, xlab=<span style="color: #CD5555">&quot;Years&quot;</span>, ylab=<span style="color: #CD5555">&quot;Haresx 1000&quot;</span>)
<span style="color: #8B008B; font-weight: bold">summary</span>(HudsonBay)
<span style="color: #8B008B; font-weight: bold">summary</span>(Hares..x1000.)
<span style="color: #8B008B; font-weight: bold">library</span>(MASS)
<span style="color: #8B008B; font-weight: bold">library</span>(ISLR)
scatter.smooth(x=Year, y = Hares..x1000.)
linearMod = lm(Hares..x1000. ~ Year)
<span style="color: #8B008B; font-weight: bold">print</span>(linearMod)
summary(linearMod)
<span style="color: #8B008B; font-weight: bold">summary</span>(linearMod)
plot(linearMod)
confint(linearMod)
predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">&quot;confidence&quot;</span>)
predict(linearMod,<span style="color: #00688B; font-weight: bold">data.frame</span>(Year=<span style="color: #00688B; font-weight: bold">c</span>(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">&quot;confidence&quot;</span>)
</pre></div>
</div>
@@ -833,26 +836,26 @@ predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<sp
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span><span style="color: #658b00">set</span>.seed(<span style="color: #B452CD">1485</span>)
<span style="color: #658b00">len</span> = <span style="color: #B452CD">24</span>
x = runif(<span style="color: #658b00">len</span>)
y = x^<span style="color: #B452CD">3</span>+rnorm(<span style="color: #658b00">len</span>, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
ds = data.frame(x = x, y = y)
<span style="color: #658b00">str</span>(ds)
<!-- code=r (!bc r) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">set.seed</span>(<span style="color: #B452CD">1485</span>)
len = <span style="color: #B452CD">24</span>
x = runif(len)
y = x^<span style="color: #B452CD">3</span>+rnorm(len, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
ds = <span style="color: #00688B; font-weight: bold">data.frame</span>(x = x, y = y)
str(ds)
plot( y ~ x, main =<span style="color: #CD5555">&quot;Known cubic with noise&quot;</span>)
s = seq(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
s = <span style="color: #8B008B; font-weight: bold">seq</span>(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
lines(s, s^<span style="color: #B452CD">3</span>, lty =<span style="color: #B452CD">2</span>, col =<span style="color: #CD5555">&quot;green&quot;</span>)
m = nls(y ~ I(x^power), data = ds, start = <span style="color: #658b00">list</span>(power=<span style="color: #B452CD">1</span>), trace = T)
class(m)
summary(m)
power = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
power.se = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
m = nls(y ~ <span style="color: #8B008B; font-weight: bold">I</span>(x^power), data = ds, start = <span style="color: #00688B; font-weight: bold">list</span>(power=<span style="color: #B452CD">1</span>), trace = <span style="color: #658b00">T</span>)
<span style="color: #8B008B; font-weight: bold">class</span>(m)
<span style="color: #8B008B; font-weight: bold">summary</span>(m)
power = <span style="color: #8B008B; font-weight: bold">round</span>(<span style="color: #8B008B; font-weight: bold">summary</span>(m)$coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
power.se = <span style="color: #8B008B; font-weight: bold">round</span>(<span style="color: #8B008B; font-weight: bold">summary</span>(m)$coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
plot(y ~ x, main = <span style="color: #CD5555">&quot;Fitted power model&quot;</span>, sub = <span style="color: #CD5555">&quot;Blue: fit; green: known&quot;</span>)
s = seq(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
s = <span style="color: #8B008B; font-weight: bold">seq</span>(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
lines(s, s^<span style="color: #B452CD">3</span>, lty = <span style="color: #B452CD">2</span>, col = <span style="color: #CD5555">&quot;green&quot;</span>)
lines(s, predict(m, <span style="color: #658b00">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">&quot;blue&quot;</span>)
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, paste(<span style="color: #CD5555">&quot;y =x^ (&quot;</span>, power, <span style="color: #CD5555">&quot; +/- &quot;</span>, power.se, <span style="color: #CD5555">&quot;)&quot;</span>, sep = <span style="color: #CD5555">&quot;&quot;</span>), pos = <span style="color: #B452CD">4</span>)
lines(s, predict(m, <span style="color: #00688B; font-weight: bold">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">&quot;blue&quot;</span>)
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, <span style="color: #8B008B; font-weight: bold">paste</span>(<span style="color: #CD5555">&quot;y =x^ (&quot;</span>, power, <span style="color: #CD5555">&quot; +/- &quot;</span>, power.se, <span style="color: #CD5555">&quot;)&quot;</span>, sep = <span style="color: #CD5555">&quot;&quot;</span>), pos = <span style="color: #B452CD">4</span>)
</pre></div>
</div>
+40 -37
View File
@@ -145,7 +145,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<center><h4>Dec 8, 2017</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -287,10 +287,13 @@ either Python or C++ as programming languages.
To add more entropy, <b>cython</b> can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing. For example, convert to latex as
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>jupyter nbconvert filename<span style="color: #666666">.</span>ipynb <span style="color: #666666">--</span>to latex
</pre></div>
<p>
This never ends.
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
@@ -804,26 +807,26 @@ plt<span style="color: #666666">.</span>show()
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read<span style="color: #666666">.</span>csv(<span style="color: #BA2121">&quot;src/Hudson_Bay.csv&quot;</span>,header<span style="color: #666666">=</span>T)
<!-- code=r (!bc r) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read.csv(<span style="color: #BA2121">&quot;src/Hudson_Bay.csv&quot;</span>,header<span style="color: #666666">=</span><span style="color: #008000">T</span>)
fix(HudsonBay)
dim(HudsonBay)
names(HudsonBay)
plot(HudsonBay$Year, HudsonBay$Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
attach(HudsonBay)
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>, col<span style="color: #666666">=</span><span style="color: #BA2121">&quot;red&quot;</span>, varwidth<span style="color: #666666">=</span>T, xlab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Years&quot;</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Haresx 1000&quot;</span>)
summary(HudsonBay)
summary(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
library(MASS)
library(ISLR)
scatter<span style="color: #666666">.</span>smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
linearMod <span style="color: #666666">=</span> lm(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span> <span style="color: #666666">~</span> Year)
<span style="color: #008000; font-weight: bold">print</span>(linearMod)
summary(linearMod)
<span style="color: #008000">dim</span>(HudsonBay)
<span style="color: #008000">names</span>(HudsonBay)
plot(HudsonBay<span style="color: #666666">$</span>Year, HudsonBay<span style="color: #666666">$</span>Hares..x1000.)
<span style="color: #008000; font-weight: bold">attach</span>(HudsonBay)
plot(Year, Hares..x1000.)
plot(Year, Hares..x1000., col<span style="color: #666666">=</span><span style="color: #BA2121">&quot;red&quot;</span>, varwidth<span style="color: #666666">=</span><span style="color: #008000">T</span>, xlab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Years&quot;</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Haresx 1000&quot;</span>)
<span style="color: #008000">summary</span>(HudsonBay)
<span style="color: #008000">summary</span>(Hares..x1000.)
<span style="color: #008000; font-weight: bold">library</span>(MASS)
<span style="color: #008000; font-weight: bold">library</span>(ISLR)
scatter.smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares..x1000.)
linearMod <span style="color: #666666">=</span> lm(Hares..x1000. <span style="color: #666666">~</span> Year)
<span style="color: #008000">print</span>(linearMod)
<span style="color: #008000">summary</span>(linearMod)
plot(linearMod)
confint(linearMod)
predict(linearMod,data<span style="color: #666666">.</span>frame(Year<span style="color: #666666">=</span>c(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">&quot;confidence&quot;</span>)
predict(linearMod,<span style="color: #B00040">data.frame</span>(Year<span style="color: #666666">=</span><span style="color: #B00040">c</span>(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">&quot;confidence&quot;</span>)
</pre></div>
</div>
@@ -838,26 +841,26 @@ predict(linearMod,data<span style="color: #666666">.</span>frame(Year<span style
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set</span><span style="color: #666666">.</span>seed(<span style="color: #666666">1485</span>)
<span style="color: #008000">len</span> <span style="color: #666666">=</span> <span style="color: #666666">24</span>
x <span style="color: #666666">=</span> runif(<span style="color: #008000">len</span>)
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(<span style="color: #008000">len</span>, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
ds <span style="color: #666666">=</span> data<span style="color: #666666">.</span>frame(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
<span style="color: #008000">str</span>(ds)
<!-- code=r (!bc r) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set.seed</span>(<span style="color: #666666">1485</span>)
len <span style="color: #666666">=</span> <span style="color: #666666">24</span>
x <span style="color: #666666">=</span> runif(len)
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(len, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
ds <span style="color: #666666">=</span> <span style="color: #B00040">data.frame</span>(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
str(ds)
plot( y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span><span style="color: #BA2121">&quot;Known cubic with noise&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
s <span style="color: #666666">=</span> <span style="color: #008000">seq</span>(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=2</span>, col <span style="color: #666666">=</span><span style="color: #BA2121">&quot;green&quot;</span>)
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> I(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #008000">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> T)
class(m)
summary(m)
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
power<span style="color: #666666">.</span>se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> <span style="color: #008000">I</span>(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #B00040">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> <span style="color: #008000">T</span>)
<span style="color: #008000">class</span>(m)
<span style="color: #008000">summary</span>(m)
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(<span style="color: #008000">summary</span>(m)<span style="color: #666666">$</span>coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
power.se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(<span style="color: #008000">summary</span>(m)<span style="color: #666666">$</span>coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
plot(y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Fitted power model&quot;</span>, sub <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Blue: fit; green: known&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
s <span style="color: #666666">=</span> <span style="color: #008000">seq</span>(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=</span> <span style="color: #666666">2</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;green&quot;</span>)
lines(s, predict(m, <span style="color: #008000">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;blue&quot;</span>)
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, paste(<span style="color: #BA2121">&quot;y =x^ (&quot;</span>, power, <span style="color: #BA2121">&quot; +/- &quot;</span>, power<span style="color: #666666">.</span>se, <span style="color: #BA2121">&quot;)&quot;</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;&quot;</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
lines(s, predict(m, <span style="color: #B00040">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;blue&quot;</span>)
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, <span style="color: #008000">paste</span>(<span style="color: #BA2121">&quot;y =x^ (&quot;</span>, power, <span style="color: #BA2121">&quot; +/- &quot;</span>, power.se, <span style="color: #BA2121">&quot;)&quot;</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;&quot;</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
</pre></div>
</div>