Update on r codes
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
"<!-- Author: --> \n",
|
||||
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
|
||||
"\n",
|
||||
"Date: **Dec 6, 2017**\n",
|
||||
"Date: **Dec 8, 2017**\n",
|
||||
"\n",
|
||||
"Copyright 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
|
||||
"\n",
|
||||
@@ -125,9 +125,24 @@
|
||||
"To add more entropy, **cython** can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook \n",
|
||||
"setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility, \n",
|
||||
"including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook \n",
|
||||
"can easily be converted into a nicely rendered **PDF** file or a Latex file for further processing.\n",
|
||||
"\n",
|
||||
"This never ends.\n",
|
||||
"can easily be converted into a nicely rendered **PDF** file or a Latex file for further processing. For example, convert to latex as"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"jupyter nbconvert filename.ipynb --to latex"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If you use the light mark-up language **doconce** you can convert a standard ascii text file into various HTML \n",
|
||||
"formats, ipython notebooks, latex files, pdf files etc. \n",
|
||||
"\n",
|
||||
@@ -138,7 +153,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -173,7 +188,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -283,7 +298,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -540,7 +555,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -614,7 +629,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 6,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -648,32 +663,28 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"HudsonBay = read.csv(\"src/Hudson_Bay.csv\",header=T)\n",
|
||||
"fix(HudsonBay)\n",
|
||||
"dim(HudsonBay)\n",
|
||||
"names(HudsonBay)\n",
|
||||
"plot(HudsonBay$Year, HudsonBay$Hares..x1000.)\n",
|
||||
"attach(HudsonBay)\n",
|
||||
"plot(Year, Hares..x1000.)\n",
|
||||
"plot(Year, Hares..x1000., col=\"red\", varwidth=T, xlab=\"Years\", ylab=\"Haresx 1000\")\n",
|
||||
"summary(HudsonBay)\n",
|
||||
"summary(Hares..x1000.)\n",
|
||||
"library(MASS)\n",
|
||||
"library(ISLR)\n",
|
||||
"scatter.smooth(x=Year, y = Hares..x1000.)\n",
|
||||
"linearMod = lm(Hares..x1000. ~ Year)\n",
|
||||
"print(linearMod)\n",
|
||||
"summary(linearMod)\n",
|
||||
"plot(linearMod)\n",
|
||||
"confint(linearMod)\n",
|
||||
"predict(linearMod,data.frame(Year=c(1910,1914,1920)),interval=\"confidence\")"
|
||||
" HudsonBay = read.csv(\"src/Hudson_Bay.csv\",header=T)\n",
|
||||
" fix(HudsonBay)\n",
|
||||
" dim(HudsonBay)\n",
|
||||
" names(HudsonBay)\n",
|
||||
" plot(HudsonBay$Year, HudsonBay$Hares..x1000.)\n",
|
||||
" attach(HudsonBay)\n",
|
||||
" plot(Year, Hares..x1000.)\n",
|
||||
" plot(Year, Hares..x1000., col=\"red\", varwidth=T, xlab=\"Years\", ylab=\"Haresx 1000\")\n",
|
||||
" summary(HudsonBay)\n",
|
||||
" summary(Hares..x1000.)\n",
|
||||
" library(MASS)\n",
|
||||
" library(ISLR)\n",
|
||||
" scatter.smooth(x=Year, y = Hares..x1000.)\n",
|
||||
" linearMod = lm(Hares..x1000. ~ Year)\n",
|
||||
" print(linearMod)\n",
|
||||
" summary(linearMod)\n",
|
||||
" plot(linearMod)\n",
|
||||
" confint(linearMod)\n",
|
||||
" predict(linearMod,data.frame(Year=c(1910,1914,1920)),interval=\"confidence\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -684,32 +695,28 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"set.seed(1485)\n",
|
||||
"len = 24\n",
|
||||
"x = runif(len)\n",
|
||||
"y = x^3+rnorm(len, 0,0.06)\n",
|
||||
"ds = data.frame(x = x, y = y)\n",
|
||||
"str(ds)\n",
|
||||
"plot( y ~ x, main =\"Known cubic with noise\")\n",
|
||||
"s = seq(0,1,length =100)\n",
|
||||
"lines(s, s^3, lty =2, col =\"green\")\n",
|
||||
"m = nls(y ~ I(x^power), data = ds, start = list(power=1), trace = T)\n",
|
||||
"class(m)\n",
|
||||
"summary(m)\n",
|
||||
"power = round(summary(m)$coefficients[1], 3)\n",
|
||||
"power.se = round(summary(m)$coefficients[2], 3)\n",
|
||||
"plot(y ~ x, main = \"Fitted power model\", sub = \"Blue: fit; green: known\")\n",
|
||||
"s = seq(0, 1, length = 100)\n",
|
||||
"lines(s, s^3, lty = 2, col = \"green\")\n",
|
||||
"lines(s, predict(m, list(x = s)), lty = 1, col = \"blue\")\n",
|
||||
"text(0, 0.5, paste(\"y =x^ (\", power, \" +/- \", power.se, \")\", sep = \"\"), pos = 4)"
|
||||
" set.seed(1485)\n",
|
||||
" len = 24\n",
|
||||
" x = runif(len)\n",
|
||||
" y = x^3+rnorm(len, 0,0.06)\n",
|
||||
" ds = data.frame(x = x, y = y)\n",
|
||||
" str(ds)\n",
|
||||
" plot( y ~ x, main =\"Known cubic with noise\")\n",
|
||||
" s = seq(0,1,length =100)\n",
|
||||
" lines(s, s^3, lty =2, col =\"green\")\n",
|
||||
" m = nls(y ~ I(x^power), data = ds, start = list(power=1), trace = T)\n",
|
||||
" class(m)\n",
|
||||
" summary(m)\n",
|
||||
" power = round(summary(m)$coefficients[1], 3)\n",
|
||||
" power.se = round(summary(m)$coefficients[2], 3)\n",
|
||||
" plot(y ~ x, main = \"Fitted power model\", sub = \"Blue: fit; green: known\")\n",
|
||||
" s = seq(0, 1, length = 100)\n",
|
||||
" lines(s, s^3, lty = 2, col = \"green\")\n",
|
||||
" lines(s, predict(m, list(x = s)), lty = 1, col = \"blue\")\n",
|
||||
" text(0, 0.5, paste(\"y =x^ (\", power, \" +/- \", power.se, \")\", sep = \"\"), pos = 4)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user