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
@@ -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>