From 007238daf14f667b5b0c4c64f69edb2b3157e51f Mon Sep 17 00:00:00 2001 From: Saranjeet Kaur Date: Thu, 11 Mar 2021 14:24:08 +0530 Subject: [PATCH 01/10] Getting_Started --- 02-getting_started.Rmd | 56 +++++++++++++++++++++-------------------- rdevguide.rds | Bin 1071 -> 1087 bytes 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/02-getting_started.Rmd b/02-getting_started.Rmd index 4adf735..c8eeb35 100755 --- a/02-getting_started.Rmd +++ b/02-getting_started.Rmd @@ -1,27 +1,29 @@ -# Getting Started - -## Install git - -## Get the source code - -## Compile and build - -### UNIX - -### Windows - -## Install dependencies - -### Linux - -### maxOS and OS X - -## Regenerate `configure` - -## Troubleshoot the build - -### Avoid recreating auto-generated files - -## Editors and Tools - -## Directory structure +# Getting Started + +These instructions cover how to install R in Windows. The tools required to build R and R packages in Windows are also discussed. + +## Install git + +## Get the source code + +## Compile and build + +### UNIX + +### Windows + +## Install dependencies + +### Linux + +### maxOS and OS X + +## Regenerate `configure` + +## Troubleshoot the build + +### Avoid recreating auto-generated files + +## Editors and Tools + +## Directory structure diff --git a/rdevguide.rds b/rdevguide.rds index 2b6bde066936e6e22069ac9b75f5f8e967fe2d20..82dde4182c8e10f9149f3a79ecb9ca2490b9e3fb 100644 GIT binary patch literal 1087 zcmV-F1iA$&YP&dp}yxZ`+z~Bd_BWaP*+Zy4%;c@dPaAL=dPr)M{`}ipB7#9QLYjnQJ+B z0SY=Jc!diB`3xd>gA|_E(p!$5#Fs!+jG5O!EQ3oy>sQj3uHfR5qn~d; z#BeV@?#A-eOY#Lg%E5x?0rk>R^_jT>2xGFSV|8;Ike#EBs%Iu7*TBjFSU2l{nb525 zHg}kO1(=&|QSnMbGv9L&*y+Y@47cHfGzKWk>dwreniD-Qvw}{Cn>}$MxQ)I`6M*N4 z9~)FlJSgCb1oiiM@-*hR?bO#?uEWny}W zCTCQwpu{Mk{fs)Qp1C=RLAGM3q*yajRIDVGYj%cBEeFia9YAguP9{l1iZ!pGMK*$V7tkr^3ZrsS?+kcO zkdkvk0(#o{4xlX;widx>`bHlY+tbZ_Tk&m^^XBMvmz6h%M{X+J2%YX= zyp80C-K^A#Plrm{XKnsxr9>}bv){={uB^OqQK3fUz`~`J6{s$Kf*ERnW F001Y)8BG8H literal 1071 zcmV+~1kn2*iwFP!000001C>{8Z`(EyR+DB}2NdY~>ZDClXK9LIU?Is#zYOEn!=uA~1Nw9n%Nd}B)Rti+0P_7K3MAKQF;KN_yzG?8wSS8)nvL@CN< zP%0!8$@=pgb%5PeZ{iVH&WRvUaj0Q%PVz;6vUi6G9V&I#mGh~W2|5V|h7 zo9;Be0-|Kh>;+;OTnbw4i#~WI`_rC#-MHyb;?ICGEC`YtbBOsJ5okvGv;X1q;wFC| zUjuU*2D7AU4l|C+f-r@`^7ez@k2`=D@fd7u4LIPO2Q8?Z<|6(AB+UuK1TK*Lh=zDyEO89^lwzSY3~WQT36 z=jJ9UP=cb_`Vy=o3%I$Ra5vq%WCW%>&#TjyFe7&)=L?e${W*tjA8z7datRh(tkcd^ zH3S)1!bOhMl#8N2`^64N?hwwCD=_CvgP9P_3!l*v>3yA0+#h<%89dm* zoCoCApau2OTmytLSyX%V{U+eP3|dfM29JT21F&i$AsO5S_hs-GfVrt(B`+m3s$(Vs zYwytQ!%cjY#sFnm)hjqubE0KHmeWap+EbSYH|b%T06a%*wodn4|0;vJ+=;`1CvDOc zkb9k8%Iu6S26v}T3+kr%Jsp8rHqoVjVXkw3lGhEOCsoo*6Hd;>&r(%MREF|^n=o|y z@SWO~wdoS-V&33Dv zpN^t;RlSxFO{X-c>z9BW2yp5<99@d^SUlleVN@)tDF)98QgTj6Kux>Y;b<#_t+D$+ zpXkH5eYP3a*TwfnBQ`TbV@R%-UU$s3_3EH=5VhC4CdYdHy?4Z`?M{8eSZy}+4^6e< z%hse*uYK$@i`3?a-Lpe&@T#r%tqtlF==J)sTTItRXFD`+ZTVrhF10qPB_{2)rUJCT zsY|li-{h26wb5Ib7^+Q<9NNW-vL!g`wdW0;V8!R|={9+H3$_xYyJcFpuG#47rB4Ap p$o|}BMq_+@TF$UB~I}U#-yIGg9{{e1x`b?G-007O`4|M Date: Thu, 11 Mar 2021 14:54:00 +0530 Subject: [PATCH 02/10] Instructions to install R --- 02-getting_started.Rmd | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/02-getting_started.Rmd b/02-getting_started.Rmd index c8eeb35..25e0eed 100755 --- a/02-getting_started.Rmd +++ b/02-getting_started.Rmd @@ -2,7 +2,21 @@ These instructions cover how to install R in Windows. The tools required to build R and R packages in Windows are also discussed. -## Install git +## Installing R + +To install R in Windows follow these steps: + +1. Go to https://cran.r-project.org. + +2. Select `Download R for Windows`. You will be directed to a page which shows `Subdirectories` for installing R on Windows. + +3. Select `base` subdirectory. (Alternatively, you can select `install R for the first time`, it leads to the same page). + + + +## Building R and R packages + + `RTools` subdirectory for ## Get the source code From 83e90a8ea7e0ad07f93bde52318359380ce67592 Mon Sep 17 00:00:00 2001 From: Saranjeet Kaur Date: Fri, 12 Mar 2021 19:43:02 +0530 Subject: [PATCH 03/10] Installing R done --- 02-getting_started.Rmd | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/02-getting_started.Rmd b/02-getting_started.Rmd index 25e0eed..0c9a873 100755 --- a/02-getting_started.Rmd +++ b/02-getting_started.Rmd @@ -10,9 +10,24 @@ To install R in Windows follow these steps: 2. Select `Download R for Windows`. You will be directed to a page which shows `Subdirectories` for installing R on Windows. -3. Select `base` subdirectory. (Alternatively, you can select `install R for the first time`, it leads to the same page). +3. Select `base` subdirectory. (Alternatively, you can select `install R for the first time`, it leads to the same page). The recent stable release distribution of R can be downloaded from here. +4. The distribution is distributed as an installer ($\ge$) `R-4.0.4-win.exe`. +5. This has to be run in the Windows-style installer. + +6. Select the language while installing, read the public license information, and select destination location to the start the installation. You will be prompted to select components at this stage: `User installation`, `32-bit User installation`, `64-bit User installation`, or `Custom installation`. The default option may be opted for the questions from this step onwards. + +7. Complete the installation. + +## General instructions + +1. The R executable downloaded by following the above steps, is the binary distribution of ($\ge$) `R-4.0.4`, which can run on Windows XP and above versions (including 64-bit versions of Windows). It can run on ix86 and x86_64 chips. + +2. There are two versions of the R executable, the 32-bit version (in `R-4.0.4\bin\i386`) and the 64-bit version (in `R-4.0.4\bin\x64`). On the 32-bit versions of Windows, by default only the former gets installed, whereas on the 64-bit versions, both get installed. + +3. If there is already a previous version of R installed in your system and you want to retain the packages installed in it, then: + a) Uninstall R (write here, how to uninstall R) ## Building R and R packages From 0766573c09589deac9dd854ca0aad8030ddd5c81 Mon Sep 17 00:00:00 2001 From: Saranjeet Kaur Date: Sat, 13 Mar 2021 23:59:12 +0530 Subject: [PATCH 04/10] Section on building R --- 02-getting_started.Rmd | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/02-getting_started.Rmd b/02-getting_started.Rmd index 0c9a873..acbf234 100755 --- a/02-getting_started.Rmd +++ b/02-getting_started.Rmd @@ -1,18 +1,18 @@ # Getting Started -These instructions cover how to install R in Windows. The tools required to build R and R packages in Windows are also discussed. +These instructions cover how to install $\textsf{R}$ in Windows. The tools required to build $\textsf{R}$ and $\textsf{R}$ packages in Windows are also discussed. -## Installing R +## Installing $\textsf{R}$ -To install R in Windows follow these steps: +To install $\textsf{R}$ in Windows follow these steps: 1. Go to https://cran.r-project.org. 2. Select `Download R for Windows`. You will be directed to a page which shows `Subdirectories` for installing R on Windows. -3. Select `base` subdirectory. (Alternatively, you can select `install R for the first time`, it leads to the same page). The recent stable release distribution of R can be downloaded from here. +3. Select `base` subdirectory. Alternatively, you can select `install R for the first time`, it leads to the same page. The current official stable release distribution of $\textsf{R}$ can be downloaded from here. (Along with the link to the current official stable release, links to the development snapshot build and to the previous releases, are also available on this page). -4. The distribution is distributed as an installer ($\ge$) `R-4.0.4-win.exe`. +4. This distribution is distributed as an installer `R-x.y.z-win.exe`. The `x.y.z` in the $\textsf{R}$ system version represent the major, minor, and patchlevel version numbers, respectively. 5. This has to be run in the Windows-style installer. @@ -22,16 +22,27 @@ To install R in Windows follow these steps: ## General instructions -1. The R executable downloaded by following the above steps, is the binary distribution of ($\ge$) `R-4.0.4`, which can run on Windows XP and above versions (including 64-bit versions of Windows). It can run on ix86 and x86_64 chips. +1. The $\textsf{R}$ executable downloaded by following the above steps, is the binary distribution of `R-x.y.z`, which can run on Windows XP and above versions (including 64-bit versions of Windows). It can run on ix86 and x86_64 chips. -2. There are two versions of the R executable, the 32-bit version (in `R-4.0.4\bin\i386`) and the 64-bit version (in `R-4.0.4\bin\x64`). On the 32-bit versions of Windows, by default only the former gets installed, whereas on the 64-bit versions, both get installed. +2. There are two versions of the $\textsf{R}$ executable, the 32-bit version (in `R-x.y.z\bin\i386`) and the 64-bit version (in `R-x.y.z\bin\x64`). On the 32-bit versions of Windows, by default only the former gets installed, whereas on the 64-bit versions, both get installed. -3. If there is already a previous version of R installed in your system and you want to retain the packages installed in it, then: - a) Uninstall R (write here, how to uninstall R) +3. If there is already a previous version of R installed in your system and you want to retain the packages installed in it, then uninstall the previous version of $\textsf{R}$ (from the Control Panel) and install the new one. In the new installation, copy any installed packages to the library folder and run `update.packages(checkBuilt=TRUE, ask=FALSE)` in the new $\textsf{R}$. -## Building R and R packages +4. If there are different versions of R installed, then they are present in parallel folders. Hence, earlier versions can also be retained if you wish to keep them. + +5. When there is a change in the minor version of $\textsf{R}$ (say, from 4.0.3 to 4.1.0), then the library names (folder `R\win-library\x.y` of your home directory, `R\win64-library\x.y` on 64-bit builds), will need to be updated too. For doing this, copy (say) `R\win-library\4.0` to `R\win-library\4.1` and then run the `update.packages(checkBuilt=TRUE, ask=FALSE)` command. - `RTools` subdirectory for +## Building $\textsf{R}$ and $\textsf{R}$ packages + +`RTools` is the [subdirectory](https://cran.r-project.org/bin/windows/Rtools/) which you want to build $\textsf{R}$ or your own $\textsf{R}$ package(s) on Windows. + +### What tools you need to build $\textsf{R}$ on Windows? + +1. `RTools` is the [subdirectory](https://cran.r-project.org/bin/windows/Rtools/) which you want to build $\textsf{R}$ or your own $\textsf{R}$ package(s) on Windows. + +2. You also need a distribution of $\LaTeX$ installed for building $\textsf{R}$ and checking packages. The `MiKTeX` distribution of $\LaTeX$ that is used on CRAN can be downloaded from https://miktex.org. + +### How to setup `RTools`? ## Get the source code From b7566bccaf045f10f976eaa9cbf054228ec0e905 Mon Sep 17 00:00:00 2001 From: Saranjeet Kaur Date: Mon, 15 Mar 2021 01:09:55 +0530 Subject: [PATCH 05/10] tools for building included --- .Rhistory | 512 +++++++++++++++++++++++++++++++++++++++++ 02-getting_started.Rmd | 39 ++-- 2 files changed, 534 insertions(+), 17 deletions(-) create mode 100644 .Rhistory diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 0000000..17d7640 --- /dev/null +++ b/.Rhistory @@ -0,0 +1,512 @@ +q <- qt(0.025,11) +q +pnorm() +7.15 - 0.186*5 +1 - (1-10^-4)^500 +pbinom(2,10000,0.0001) +pbinom(96,400,0.2) +pbinom(63,400,0.2) +pbinom(96,400,0.2) - pbinom(63,400,0.2) +z <- (0.49-0.13)/sqrt(0.49*0.51/100);z +x1 <- 60*120/100;x1 +x2 <- 62.5*120/100;x2 +pbinom(x1,120,0.637) +pbinom(x2,120,0.637) +pbinom(x1-1,120,0.637) +pbinom(x2,120,0.637)-pbinom(x1-1,120,0.637) +1.6/3 +0.8+2/3-1.6/3 +(2/3-1.6/3)/(1-0.8) +pbinom(17,250,0.1) +pbinom(18,250,0.1) +pbinom(18,250,0.06) +229-128 +271-242 +101+29 +128+242 +29/271 +120/370 +128/370 +229/500 +242/370 +.3*0.3*0.3*0.7 +dbinom(7,14,0.6) +dpois(8,12) +1-dbinom(0,30,0.22) +1-pbinom(5,30,0.22) +pbinom(5,30,0.22) +qnorm(0.08,lower.tail = FALSE) +s2 <- (76*0.3^2 + 53*0.85^2)/(77+54-2) +s2 +sqrt(s2*(1/77+1/54)) +sqrt(s2*(1/77+1/54))*1.4051 +r1 <- 1-1/10.781 +r1 +r2 <- 1-1/5.2553 +r2 +(r1-r2)/r1 +1-0.4*exp(-0.0001*2000) +#################################################### +x <- c(11,15,20,17,9,12,16,13,8,14,22,10,16,9) +m <- mean(x);m +sum(x*x) +s <- sd(x);s +z0 <- sqrt(12)*(m-12)/s;z0 +qnorm(0.1) +z0 <- sqrt(20)*(30-35)/15;z0 +qnorm(0.05) +qnorm(0.05/2) +s <- sqrt((49*100+59*14*14)/(49+59));s +z <- (-3)/(s*sqrt(1/50+1/60));z +qnorm(0.01/2) +y <- 9.336+9.102;y +qt(0.02,8) +11+9+8+9+10 +##############################################333 +disease <-rep(c("Present","Absent"),each=9) +disease +species <- rep(1:3,each=3) +species +species <- rep(rep(1:3,each=3),2) +species +location <- rep(1:3,6) +location +info <- c(34,12,20,50,44,18,23,31,22,83,97,34,87,75,55,68,48,43) +data <- data.frame(disease,species,location,info) +data +df <- table(data) +df +mantelhaen.test(df) +Table <- xtabs(info~disease+species+location,data=data1) +data1 <- data.frame(disease,species,location,info) +Table <- xtabs(info~disease+species+location,data=data1) +Table +ftable(Table) +mantelhaen.test(Table) +disease <-as.factor(rep(c("Present","Absent"),each=9)) +species <- as.factor(rep(rep(1:3,each=3),2)) +location <- as.factor(rep(1:3,6)) +info <- c(34,12,20,50,44,18,23,31,22,83,97,34,87,75,55,68,48,43) +data1 <- data.frame(disease,species,location,info) +Table <- xtabs(info~disease+species+location,data=data1) +ftable(Table) +# H0: The two nominal variables are conditionally independent in each stratum, assuming that there is no three-way interaction. +# H1: The two nominal variables are not conditionally independent in each stratum, assuming that there is no three-way interaction. +mantelhaen.test(Table) +# Comment: As the p-value = 0.01432 < 0.05, we can easily reject the null hypothesis at 5% level of significance. +# Thus, the tow variables, species and location are not conditionally independent in each of the strata - disease present and disease absent. +44/20 +2.2-0.6*.6 +8/20 +p <- 0.975 + pt(-1.706,27) +p +pt(-1.706,27) +pt(-1.706,27)+0.975->p +p +pt(-1.706,27) +pt(-1.706,27)+0.975->p +49+18 +67/(4*42) +56/67 +p <- (0.85+3*0.15)^2;p +p <- (0.85+3*0.15)^2/16;p +200*0.48 +o <- c(88,102,8) +sum(o) +o <- c(88,102,10) +e <- c(96,96,8) +sum(e) +x <- sum((o-e)^2/o^2) +x +x <- sum((o-e)^2/e^2) +x +x <- sum((o-e)^2/e) +x +qchisq(0.05,2,lower.tail = FALSE) +1.96/2 +s2 <- (45*48^2+46*900)/91 +s2 +t <- (-4)/sqrt(s2*(1/46+1/47)) +t +46+47-2 -> df +df +2*pt(abs(t),df,lower.tail = FALSE) +pt(abs(t),91,lower.tail = FALSE) +pt(abs(t),91,lower.tail = FALSE)*2 +4/7.962 +# (a) +g <- rep(1:20,each = 5) +g +y <- tapply(g,1,FUN = mean) +y +y <- tapply(g,2,FUN = mean) +fac <- factor(g, levels = 1:20) +fac +table(fac) +y <- tapply(table(fac),FUN = mean) +y <- tapply(table(fac),1,FUN = mean) +y <- tapply(table(fac),2,FUN = mean) +tapply(1:n, fac, mean) +# (a) +g <- rep(1:20,each = 5) +fac <- factor(g, levels = 1:20) +fac +fac <- factor(g, ) +fac +table(fac) +tapply(1:n, fac, mean) +y <- tapply(table(fac),2,FUN = mean) +y <- tapply(table(fac),2,FUN = mean) +y <- tapply(fac,2,FUN = mean) +y <- tapply(fac,1,FUN = mean) +g1 <- matrix(g,nrow = 20, byrow = TRUE) +g1 +y <- tapply(g1,1,FUN = mean) +y <- apply(g1,1,FUN = mean) +y +y <- tapply(1:20,g,FUN = mean) +# (a) +g <- as.factors(rep(1:20,each = 5)) +# (a) +g <- as.factorsrep(1:20,each = 5)) +# (a) +g <- as.factor(rep(1:20,each = 5)) +g +y <- tapply(1:20,g,FUN = mean) +y <- tapply(1:100,g,FUN = mean) +y +y <- tapply(1:20,g,FUN = mean) +y <- tapply(1:100,g,FUN = mean) +y +g +# (a) +g <- as.factor(rep(1:20,each = 5),levels = 20) +# (a) +g <- as.factor(rep(1:20,each = 5)) +# (a) +g <- rep(1:20,each = 5) +y <- tapply(1:100,g,FUN = mean) +y +y <- tapply(1:100,t(g),FUN = mean) +y +g +y <- tapply(1:100,g1,FUN = mean) +y +y <- tapply(1:20,g1,FUN = mean) +y +y <- tapply(1:20,g1,FUN = mean) +y +g1 <- matrix(g,ncol = 20) +y <- tapply(1:20,g1,FUN = mean) +y +y <- tapply(1:100,g1,FUN = mean) +y +x1 <- 17;n1 <- 85;x2 <- 24;n2 <- 80 +p1 <- x1/n1;p1 +p2 <- x2/n2;p2 +p <- (x1+x2)/(n1+n2);p +s <- sqrt(p*(1-p)*(1/85+1/80));s +t <- (p1-p2)/s;t +s1 <- sqrt(p1*(1-p1)/n1+p2*(1-p2)/n2) +s1 +0.1/s1 +s <- 683+925+834+204+229+926+374+501 +s +s/10222 +x1 <- (35737-51623)/7943;x1 +x2 <- (67509-51623)/7943;x2 +pnorm(2)-pnorm(-2) +(22+28)/2 +(20+22+26+24+28)/5 +(21+23+22+24+24+23+25+25+27+26)/10 +s2 <- 29*(4.2^2+3.9^2)/58;s2 +t0 <- 6/sqrt(s2/15);t0 +q <- qt(0.05,58,lower.tail = FALSE) +q +pt(t0,58,lower.tail = FALSE) +ppois(3,6) +1-ppois(3,10) +powermat <- function(x,m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +return(mat) +} +powermat(x,m) +######################################################## +powermat <- function(as.vector(x),m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +return(mat) +} +x <- c(1,2,3,4,0);m <- 5 +powermat(x,m) +######################################################## +powermat <- function(as.vector(x),m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +return(mat) +} +######################################################## +powermat <- function(as.vector(x),m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +mat +} +x <- c(1,2,3,4,0);m <- 5 +powermat(x,m) +######################################################## +powermat <- function(as.vector(x),m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +mat +} +x <- c(1,2,3,4,0);m <- 5 +powermat(x,m) +######################################################## +powermat <- function(Vectorize(x),m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +mat +} +x <- c(1,2,3,4,0);m <- 5 +powermat(x,m) +powermat <- function(Vectorize(x),m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +mat +} +######################################################## +powermat <- Vectorize(function(Vectorize(x),m)) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +mat +} +x <- c(1,2,3,4,0);m <- 5 +powermat(x,m) +######################################################## +powermat <- function(x,m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +mat +} +x <- c(1,2,3,4,0);m <- 5 +powermat(x,m) +powermat <- function(x,m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +mat +} +x <- c(1,2,3,4,0);m <- 5 +powermat(x,m) +x <- c(1,2,3,4,0,5);m <- 5 +powermat(x,m) +x <- c(1,2,3,4,0);m <- 5 +powermat(x,m) +powermat <- function(x,m) +{ +l <- length(x) +mat <- matrix(,ncol = m,nrow = l) +for(i in 1:m) mat[,i] <- x^(i-1) +mat +} +x <- c(1,2,3,4,0);m <- 5 +powermat(x,m) +exp(-5/4) +pbinom(3,10,0.2865) +100*25/26.6 +m <- 58; s <- 15 +x <- 40 +pf <- pnorm(x,m,s) +pf +(x-m)/s +pnorm(-1.2) +x1 <- 85 +z1 <- (x1-m)/s;z1 +pnorm(z1,lower.tail = FALSE) +1-pnbinom(5,1,pf) +dnbinom(6,2,0.03593032) +pnorm(z1,lower.tail = FALSE) -> pa +pa +pbinom(2,10,pa) +p <- c(0.645,0.21,0.05,0.095) +p*158 +p*158 -> e +e +qchisq(0.05,3,lower.tail = FALSE) +o <- c(97,33,5,23) +x <- sum((o-e)^2/e) +x +###################################################################### +s <- sqrt(0.83*0.17/100);s +z0 <- (0.86-0.9)/s;z0 +s1 <- sqrt(0.9*0.1/100) +s1 +z0 <- (0.83-0.9)/s;z0 +z1 <- (0.83-0.9)/s1;z1 +plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)") +################################################################### +t <- seq(0,100,length = 100) +p_prime <- -46.645*exp(-0.491*t) +plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)") +plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l") +################################################################### +t <- seq(0,50,length = 100) +p_prime <- -46.645*exp(-0.491*t) +plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l") +################################################################### +t <- seq(0,25,length = 100) +p_prime <- -46.645*exp(-0.491*t) +plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l") +################################################################### +t <- seq(0,20,length = 100) +p_prime <- -46.645*exp(-0.491*t) +plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l") +plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l",col=3,lwd=2) +46.645/0.491 +### (b) Plot for p(t) +p <- 95*exp(-0.491*t) +plot(t,p,xlab = "Time, t", ylab = "p(t)",main = "Plot of p(t)",type="l",col=2,lwd=2) +95*exp(-0.491*0.4) +### (a) Plot for p'(t) +t <- seq(0,20,length = 100) +p_prime <- -46.645*exp(-0.491*t) +plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l",col=3,lwd=2) +### (c) Plot for p(t) +p <- 95*exp(-0.491*t) +plot(t,p,xlab = "Time, t", ylab = "p(t)",main = "Plot of p(t)",type="l",col=2,lwd=2) +### (d) Blood Pressure at time 0.1 second. +95*exp(-0.491*0.4) ## Blood Pressure at time 0.1 second. +############################################################## +x <- c(0.25,0.33,0.35,0.10,0.21,0.10) +sx <- sum(x);sx +sx2 <- sum(x*x);sx2 +m <- sx/6 +m +s2 <- sd(x);sd +s2 <- sd(x);s2 +z <- (m-3)/sqrt(s2/6);z +pnorm(z) +pnorm(abs(z),lower.tail = FALSE) +################################################################ +t <- 10^4; rho <- 0.9 +x <- rep(0,times = t) +x[1] <- rnorm(1,0,1); # x[1] represents X(0) +epsilon <- rnorm(t,0,1) # the error component of the Markov chain +for(i in 2:t) +{ +x[i] <- rho*x[i-1]+epsilon[i-1] +} +hist(x,col=3) +ks.test(x,pnorm,0,1/sqrt(1-rho^2)) +# Comment: The histogram suggess that the dat is normally distributed. +# Comment: p-value for the Kolmogorv-Smirnov test is 0.003081 < 0.05. +# Therefore, we have to reject the null hypothesis. +shapiro.test(x) +t <- 10^4; rho <- 0.9 +x <- rep(0,times = t) +x[1] <- rnorm(1,0,1); # x[1] represents X(0) +epsilon <- rnorm(t,0,1) # the error component of the Markov chain +for(i in 2:t) +{ +x[i] <- rho*x[i-1]+epsilon[i-1] +} +hist(x,col=3) +ks.test(x,pnorm,0,1/sqrt(1-rho^2)) +# Comment: The histogram suggests that the data is normally distributed. +# Comment: p-value for the Kolmogorv-Smirnov test is 0.003081 < 0.05. +# Therefore, we have to reject the null hypothesis. +# Thus, the given normal distribution is not a good fit for the sample data. +t <- 10^4; rho <- 0.9 +x <- rep(0,times = t) +x[1] <- rnorm(1,0,1); # x[1] represents X(0) +epsilon <- rnorm(t,0,1) # the error component of the Markov chain +for(i in 2:t) +{ +x[i] <- rho*x[i-1]+epsilon[i-1] +} +hist(x,col=3) +ks.test(x,pnorm,0,1/sqrt(1-rho^2)) +t <- 10^4; rho <- 0.9 +x <- rep(0,times = t) +x[1] <- rnorm(1,0,1); # x[1] represents X(0) +epsilon <- rnorm(t,0,1) # the error component of the Markov chain +for(i in 2:t) +{ +x[i] <- rho*x[i-1]+epsilon[i-1] +} +hist(x,col=3) +ks.test(x,pnorm,0,1/sqrt(1-rho^2)) +# Comment: The histogram suggests that the data is normally distributed. +# Comment: p-value for the Kolmogorv-Smirnov test is 0.0476 < 0.05. +# Therefore, we have to reject the null hypothesis. +# Thus, the given normal distribution is not a good fit for the sample data. +t <- 10^4; rho <- 0.9 +x <- rep(0,times = t) +x[1] <- rnorm(1,0,1); # x[1] represents X(0) +epsilon <- rnorm(t,0,1) # the error component of the Markov chain +for(i in 2:t) +{ +x[i] <- rho*x[i-1]+epsilon[i-1] +} +hist(x,col=3) +ks.test(x,pnorm,0,1/sqrt(1-rho^2)) +# Comment: The histogram suggests that the data is normally distributed. +# Comment: p-value for the Kolmogorv-Smirnov test is 0.006674 < 0.05. +# Therefore, we have to reject the null hypothesis. +# Thus, the given normal distribution is not a good fit for the sample data. +m<- 45;s <- 15 +x <- 27 +z <- (x-m)/s;z +pnorm(z) +x1 <- 39 +z1 <- (x1-m)/s;z1 +pnorm(z1) +0.3445783 -0.1150697 +qnorm(0.95,45,15) +qnorm(0.95) +z2 <- -15/sqrt(15^2+5^2) +z2 +z2 +pnorm(z2,lower.tail = FALSE) +library(MMatrix) +library(Matrix) +expm(P,3) +P <- matrix(c(0.5,0.4,0.3,0.3,0.20.3,0.2,0.4,0.3)) +P <- matrix(c(0.5,0.4,0.3,0.3,0.20.3,0.2,0.4,0.3),nrow=3) +P <- matrix(c(0.5,0.4,0.3,0.3,0.2,0.3,0.2,0.4,0.3),nrow=3) +P +power +P%^%3 +library(expm) +P%^%3 +p <- c(0.3,0.3,0.4) +p +P%^%3%*%p +x <- sqrt(10)*(2.226-2.1)/0.769;x +2*pnorm(x,lower.tail = FALSE) +2*pt(x,lower.tail = FALSE) +2*pt(x,lower.tail = FALSE,df=9) +2*pt(x,lower.tail = FALSE,df=9)/2 +setwd("C:/Users/bhoga/Downloads/rdevguide-SaranjeetKaur") +R.Version() +writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron") diff --git a/02-getting_started.Rmd b/02-getting_started.Rmd index acbf234..5ca36d5 100755 --- a/02-getting_started.Rmd +++ b/02-getting_started.Rmd @@ -12,7 +12,7 @@ To install $\textsf{R}$ in Windows follow these steps: 3. Select `base` subdirectory. Alternatively, you can select `install R for the first time`, it leads to the same page. The current official stable release distribution of $\textsf{R}$ can be downloaded from here. (Along with the link to the current official stable release, links to the development snapshot build and to the previous releases, are also available on this page). -4. This distribution is distributed as an installer `R-x.y.z-win.exe`. The `x.y.z` in the $\textsf{R}$ system version represent the major, minor, and patchlevel version numbers, respectively. +4. This distribution is distributed as an installer `R-x.y.z-win.exe`. The `x.y.z` in the $\textsf{R}$ system version represent the major, minor, and patchlevel numbers, respectively. 5. This has to be run in the Windows-style installer. @@ -32,11 +32,11 @@ To install $\textsf{R}$ in Windows follow these steps: 5. When there is a change in the minor version of $\textsf{R}$ (say, from 4.0.3 to 4.1.0), then the library names (folder `R\win-library\x.y` of your home directory, `R\win64-library\x.y` on 64-bit builds), will need to be updated too. For doing this, copy (say) `R\win-library\4.0` to `R\win-library\4.1` and then run the `update.packages(checkBuilt=TRUE, ask=FALSE)` command. -## Building $\textsf{R}$ and $\textsf{R}$ packages +6. Daily [tarballs](https://stat.ethz.ch/R/daily/) are available for the patched version of the current release (`r-patched`), and the development version of the current release (`r-devel`). The same are also available via the [R Subversion repository](https://svn.R-project.org/R/) -`RTools` is the [subdirectory](https://cran.r-project.org/bin/windows/Rtools/) which you want to build $\textsf{R}$ or your own $\textsf{R}$ package(s) on Windows. +## Building $\textsf{R}$ and $\textsf{R}$ packages -### What tools you need to build $\textsf{R}$ on Windows? +### What tools you need to build $\textsf{R}$ from source on Windows? 1. `RTools` is the [subdirectory](https://cran.r-project.org/bin/windows/Rtools/) which you want to build $\textsf{R}$ or your own $\textsf{R}$ package(s) on Windows. @@ -44,26 +44,31 @@ To install $\textsf{R}$ in Windows follow these steps: ### How to setup `RTools`? -## Get the source code - -## Compile and build +1. The executable version of `RTools` that is specific to your requirements can be downloaded from https://cran.r-project.org/bin/windows/Rtools/ and run in the Windows-style installer. -### UNIX +2. After completing the installation, you need to put the location of the RTools $\textit{make}$ $\textit{utilities}$ on the `PATH`. For doing this, exceute the following commands in $\textsf{R}$: -### Windows +```{r, results='hide'} +writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron") +``` -## Install dependencies +Restart $\textsf{R}$ now. Verify that $\textit{make}$ can be found using the following command. (The output of the command should show the path where you installed `RTools`): -### Linux +```{r, results='hide'} +Sys.which("make") +## "C:\\rtools40\\usr\\bin\\make.exe" +``` -### maxOS and OS X +If the above works, then try installing an $\textsf{R}$ package from source: -## Regenerate `configure` +```{r, results='hide'} +## install.packages("jsonlite", type = "source") ## An example +``` -## Troubleshoot the build +If you are successful in installing an $\textsf{R}$ package from source, then the setup for `RTools` is completed. -### Avoid recreating auto-generated files +### How to build $\textsf{R}$? -## Editors and Tools +To build $\textsf{R}$ for Windows using `RTools` follow the instructions in this [readme](https://github.com/r-windows/r-base#readme) file. -## Directory structure +## References (chapterwise or at the end of the guide?) From af9615c6e4c4fcd1afe5b49f6718aa5288db96ea Mon Sep 17 00:00:00 2001 From: Saranjeet Kaur Date: Mon, 15 Mar 2021 01:20:16 +0530 Subject: [PATCH 06/10] cleared command history From 91c417d6bc72a4429744938d75010e8c644b0884 Mon Sep 17 00:00:00 2001 From: Saranjeet Kaur Date: Mon, 15 Mar 2021 01:29:36 +0530 Subject: [PATCH 07/10] delete .Rhistory file --- .Rhistory | 512 ------------------------------------------------------ 1 file changed, 512 deletions(-) delete mode 100644 .Rhistory diff --git a/.Rhistory b/.Rhistory deleted file mode 100644 index 17d7640..0000000 --- a/.Rhistory +++ /dev/null @@ -1,512 +0,0 @@ -q <- qt(0.025,11) -q -pnorm() -7.15 - 0.186*5 -1 - (1-10^-4)^500 -pbinom(2,10000,0.0001) -pbinom(96,400,0.2) -pbinom(63,400,0.2) -pbinom(96,400,0.2) - pbinom(63,400,0.2) -z <- (0.49-0.13)/sqrt(0.49*0.51/100);z -x1 <- 60*120/100;x1 -x2 <- 62.5*120/100;x2 -pbinom(x1,120,0.637) -pbinom(x2,120,0.637) -pbinom(x1-1,120,0.637) -pbinom(x2,120,0.637)-pbinom(x1-1,120,0.637) -1.6/3 -0.8+2/3-1.6/3 -(2/3-1.6/3)/(1-0.8) -pbinom(17,250,0.1) -pbinom(18,250,0.1) -pbinom(18,250,0.06) -229-128 -271-242 -101+29 -128+242 -29/271 -120/370 -128/370 -229/500 -242/370 -.3*0.3*0.3*0.7 -dbinom(7,14,0.6) -dpois(8,12) -1-dbinom(0,30,0.22) -1-pbinom(5,30,0.22) -pbinom(5,30,0.22) -qnorm(0.08,lower.tail = FALSE) -s2 <- (76*0.3^2 + 53*0.85^2)/(77+54-2) -s2 -sqrt(s2*(1/77+1/54)) -sqrt(s2*(1/77+1/54))*1.4051 -r1 <- 1-1/10.781 -r1 -r2 <- 1-1/5.2553 -r2 -(r1-r2)/r1 -1-0.4*exp(-0.0001*2000) -#################################################### -x <- c(11,15,20,17,9,12,16,13,8,14,22,10,16,9) -m <- mean(x);m -sum(x*x) -s <- sd(x);s -z0 <- sqrt(12)*(m-12)/s;z0 -qnorm(0.1) -z0 <- sqrt(20)*(30-35)/15;z0 -qnorm(0.05) -qnorm(0.05/2) -s <- sqrt((49*100+59*14*14)/(49+59));s -z <- (-3)/(s*sqrt(1/50+1/60));z -qnorm(0.01/2) -y <- 9.336+9.102;y -qt(0.02,8) -11+9+8+9+10 -##############################################333 -disease <-rep(c("Present","Absent"),each=9) -disease -species <- rep(1:3,each=3) -species -species <- rep(rep(1:3,each=3),2) -species -location <- rep(1:3,6) -location -info <- c(34,12,20,50,44,18,23,31,22,83,97,34,87,75,55,68,48,43) -data <- data.frame(disease,species,location,info) -data -df <- table(data) -df -mantelhaen.test(df) -Table <- xtabs(info~disease+species+location,data=data1) -data1 <- data.frame(disease,species,location,info) -Table <- xtabs(info~disease+species+location,data=data1) -Table -ftable(Table) -mantelhaen.test(Table) -disease <-as.factor(rep(c("Present","Absent"),each=9)) -species <- as.factor(rep(rep(1:3,each=3),2)) -location <- as.factor(rep(1:3,6)) -info <- c(34,12,20,50,44,18,23,31,22,83,97,34,87,75,55,68,48,43) -data1 <- data.frame(disease,species,location,info) -Table <- xtabs(info~disease+species+location,data=data1) -ftable(Table) -# H0: The two nominal variables are conditionally independent in each stratum, assuming that there is no three-way interaction. -# H1: The two nominal variables are not conditionally independent in each stratum, assuming that there is no three-way interaction. -mantelhaen.test(Table) -# Comment: As the p-value = 0.01432 < 0.05, we can easily reject the null hypothesis at 5% level of significance. -# Thus, the tow variables, species and location are not conditionally independent in each of the strata - disease present and disease absent. -44/20 -2.2-0.6*.6 -8/20 -p <- 0.975 + pt(-1.706,27) -p -pt(-1.706,27) -pt(-1.706,27)+0.975->p -p -pt(-1.706,27) -pt(-1.706,27)+0.975->p -49+18 -67/(4*42) -56/67 -p <- (0.85+3*0.15)^2;p -p <- (0.85+3*0.15)^2/16;p -200*0.48 -o <- c(88,102,8) -sum(o) -o <- c(88,102,10) -e <- c(96,96,8) -sum(e) -x <- sum((o-e)^2/o^2) -x -x <- sum((o-e)^2/e^2) -x -x <- sum((o-e)^2/e) -x -qchisq(0.05,2,lower.tail = FALSE) -1.96/2 -s2 <- (45*48^2+46*900)/91 -s2 -t <- (-4)/sqrt(s2*(1/46+1/47)) -t -46+47-2 -> df -df -2*pt(abs(t),df,lower.tail = FALSE) -pt(abs(t),91,lower.tail = FALSE) -pt(abs(t),91,lower.tail = FALSE)*2 -4/7.962 -# (a) -g <- rep(1:20,each = 5) -g -y <- tapply(g,1,FUN = mean) -y -y <- tapply(g,2,FUN = mean) -fac <- factor(g, levels = 1:20) -fac -table(fac) -y <- tapply(table(fac),FUN = mean) -y <- tapply(table(fac),1,FUN = mean) -y <- tapply(table(fac),2,FUN = mean) -tapply(1:n, fac, mean) -# (a) -g <- rep(1:20,each = 5) -fac <- factor(g, levels = 1:20) -fac -fac <- factor(g, ) -fac -table(fac) -tapply(1:n, fac, mean) -y <- tapply(table(fac),2,FUN = mean) -y <- tapply(table(fac),2,FUN = mean) -y <- tapply(fac,2,FUN = mean) -y <- tapply(fac,1,FUN = mean) -g1 <- matrix(g,nrow = 20, byrow = TRUE) -g1 -y <- tapply(g1,1,FUN = mean) -y <- apply(g1,1,FUN = mean) -y -y <- tapply(1:20,g,FUN = mean) -# (a) -g <- as.factors(rep(1:20,each = 5)) -# (a) -g <- as.factorsrep(1:20,each = 5)) -# (a) -g <- as.factor(rep(1:20,each = 5)) -g -y <- tapply(1:20,g,FUN = mean) -y <- tapply(1:100,g,FUN = mean) -y -y <- tapply(1:20,g,FUN = mean) -y <- tapply(1:100,g,FUN = mean) -y -g -# (a) -g <- as.factor(rep(1:20,each = 5),levels = 20) -# (a) -g <- as.factor(rep(1:20,each = 5)) -# (a) -g <- rep(1:20,each = 5) -y <- tapply(1:100,g,FUN = mean) -y -y <- tapply(1:100,t(g),FUN = mean) -y -g -y <- tapply(1:100,g1,FUN = mean) -y -y <- tapply(1:20,g1,FUN = mean) -y -y <- tapply(1:20,g1,FUN = mean) -y -g1 <- matrix(g,ncol = 20) -y <- tapply(1:20,g1,FUN = mean) -y -y <- tapply(1:100,g1,FUN = mean) -y -x1 <- 17;n1 <- 85;x2 <- 24;n2 <- 80 -p1 <- x1/n1;p1 -p2 <- x2/n2;p2 -p <- (x1+x2)/(n1+n2);p -s <- sqrt(p*(1-p)*(1/85+1/80));s -t <- (p1-p2)/s;t -s1 <- sqrt(p1*(1-p1)/n1+p2*(1-p2)/n2) -s1 -0.1/s1 -s <- 683+925+834+204+229+926+374+501 -s -s/10222 -x1 <- (35737-51623)/7943;x1 -x2 <- (67509-51623)/7943;x2 -pnorm(2)-pnorm(-2) -(22+28)/2 -(20+22+26+24+28)/5 -(21+23+22+24+24+23+25+25+27+26)/10 -s2 <- 29*(4.2^2+3.9^2)/58;s2 -t0 <- 6/sqrt(s2/15);t0 -q <- qt(0.05,58,lower.tail = FALSE) -q -pt(t0,58,lower.tail = FALSE) -ppois(3,6) -1-ppois(3,10) -powermat <- function(x,m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -return(mat) -} -powermat(x,m) -######################################################## -powermat <- function(as.vector(x),m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -return(mat) -} -x <- c(1,2,3,4,0);m <- 5 -powermat(x,m) -######################################################## -powermat <- function(as.vector(x),m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -return(mat) -} -######################################################## -powermat <- function(as.vector(x),m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -mat -} -x <- c(1,2,3,4,0);m <- 5 -powermat(x,m) -######################################################## -powermat <- function(as.vector(x),m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -mat -} -x <- c(1,2,3,4,0);m <- 5 -powermat(x,m) -######################################################## -powermat <- function(Vectorize(x),m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -mat -} -x <- c(1,2,3,4,0);m <- 5 -powermat(x,m) -powermat <- function(Vectorize(x),m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -mat -} -######################################################## -powermat <- Vectorize(function(Vectorize(x),m)) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -mat -} -x <- c(1,2,3,4,0);m <- 5 -powermat(x,m) -######################################################## -powermat <- function(x,m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -mat -} -x <- c(1,2,3,4,0);m <- 5 -powermat(x,m) -powermat <- function(x,m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -mat -} -x <- c(1,2,3,4,0);m <- 5 -powermat(x,m) -x <- c(1,2,3,4,0,5);m <- 5 -powermat(x,m) -x <- c(1,2,3,4,0);m <- 5 -powermat(x,m) -powermat <- function(x,m) -{ -l <- length(x) -mat <- matrix(,ncol = m,nrow = l) -for(i in 1:m) mat[,i] <- x^(i-1) -mat -} -x <- c(1,2,3,4,0);m <- 5 -powermat(x,m) -exp(-5/4) -pbinom(3,10,0.2865) -100*25/26.6 -m <- 58; s <- 15 -x <- 40 -pf <- pnorm(x,m,s) -pf -(x-m)/s -pnorm(-1.2) -x1 <- 85 -z1 <- (x1-m)/s;z1 -pnorm(z1,lower.tail = FALSE) -1-pnbinom(5,1,pf) -dnbinom(6,2,0.03593032) -pnorm(z1,lower.tail = FALSE) -> pa -pa -pbinom(2,10,pa) -p <- c(0.645,0.21,0.05,0.095) -p*158 -p*158 -> e -e -qchisq(0.05,3,lower.tail = FALSE) -o <- c(97,33,5,23) -x <- sum((o-e)^2/e) -x -###################################################################### -s <- sqrt(0.83*0.17/100);s -z0 <- (0.86-0.9)/s;z0 -s1 <- sqrt(0.9*0.1/100) -s1 -z0 <- (0.83-0.9)/s;z0 -z1 <- (0.83-0.9)/s1;z1 -plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)") -################################################################### -t <- seq(0,100,length = 100) -p_prime <- -46.645*exp(-0.491*t) -plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)") -plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l") -################################################################### -t <- seq(0,50,length = 100) -p_prime <- -46.645*exp(-0.491*t) -plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l") -################################################################### -t <- seq(0,25,length = 100) -p_prime <- -46.645*exp(-0.491*t) -plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l") -################################################################### -t <- seq(0,20,length = 100) -p_prime <- -46.645*exp(-0.491*t) -plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l") -plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l",col=3,lwd=2) -46.645/0.491 -### (b) Plot for p(t) -p <- 95*exp(-0.491*t) -plot(t,p,xlab = "Time, t", ylab = "p(t)",main = "Plot of p(t)",type="l",col=2,lwd=2) -95*exp(-0.491*0.4) -### (a) Plot for p'(t) -t <- seq(0,20,length = 100) -p_prime <- -46.645*exp(-0.491*t) -plot(t,p_prime,xlab = "Time, t", ylab = "p'(t)",main = "Plot of p'(t)",type="l",col=3,lwd=2) -### (c) Plot for p(t) -p <- 95*exp(-0.491*t) -plot(t,p,xlab = "Time, t", ylab = "p(t)",main = "Plot of p(t)",type="l",col=2,lwd=2) -### (d) Blood Pressure at time 0.1 second. -95*exp(-0.491*0.4) ## Blood Pressure at time 0.1 second. -############################################################## -x <- c(0.25,0.33,0.35,0.10,0.21,0.10) -sx <- sum(x);sx -sx2 <- sum(x*x);sx2 -m <- sx/6 -m -s2 <- sd(x);sd -s2 <- sd(x);s2 -z <- (m-3)/sqrt(s2/6);z -pnorm(z) -pnorm(abs(z),lower.tail = FALSE) -################################################################ -t <- 10^4; rho <- 0.9 -x <- rep(0,times = t) -x[1] <- rnorm(1,0,1); # x[1] represents X(0) -epsilon <- rnorm(t,0,1) # the error component of the Markov chain -for(i in 2:t) -{ -x[i] <- rho*x[i-1]+epsilon[i-1] -} -hist(x,col=3) -ks.test(x,pnorm,0,1/sqrt(1-rho^2)) -# Comment: The histogram suggess that the dat is normally distributed. -# Comment: p-value for the Kolmogorv-Smirnov test is 0.003081 < 0.05. -# Therefore, we have to reject the null hypothesis. -shapiro.test(x) -t <- 10^4; rho <- 0.9 -x <- rep(0,times = t) -x[1] <- rnorm(1,0,1); # x[1] represents X(0) -epsilon <- rnorm(t,0,1) # the error component of the Markov chain -for(i in 2:t) -{ -x[i] <- rho*x[i-1]+epsilon[i-1] -} -hist(x,col=3) -ks.test(x,pnorm,0,1/sqrt(1-rho^2)) -# Comment: The histogram suggests that the data is normally distributed. -# Comment: p-value for the Kolmogorv-Smirnov test is 0.003081 < 0.05. -# Therefore, we have to reject the null hypothesis. -# Thus, the given normal distribution is not a good fit for the sample data. -t <- 10^4; rho <- 0.9 -x <- rep(0,times = t) -x[1] <- rnorm(1,0,1); # x[1] represents X(0) -epsilon <- rnorm(t,0,1) # the error component of the Markov chain -for(i in 2:t) -{ -x[i] <- rho*x[i-1]+epsilon[i-1] -} -hist(x,col=3) -ks.test(x,pnorm,0,1/sqrt(1-rho^2)) -t <- 10^4; rho <- 0.9 -x <- rep(0,times = t) -x[1] <- rnorm(1,0,1); # x[1] represents X(0) -epsilon <- rnorm(t,0,1) # the error component of the Markov chain -for(i in 2:t) -{ -x[i] <- rho*x[i-1]+epsilon[i-1] -} -hist(x,col=3) -ks.test(x,pnorm,0,1/sqrt(1-rho^2)) -# Comment: The histogram suggests that the data is normally distributed. -# Comment: p-value for the Kolmogorv-Smirnov test is 0.0476 < 0.05. -# Therefore, we have to reject the null hypothesis. -# Thus, the given normal distribution is not a good fit for the sample data. -t <- 10^4; rho <- 0.9 -x <- rep(0,times = t) -x[1] <- rnorm(1,0,1); # x[1] represents X(0) -epsilon <- rnorm(t,0,1) # the error component of the Markov chain -for(i in 2:t) -{ -x[i] <- rho*x[i-1]+epsilon[i-1] -} -hist(x,col=3) -ks.test(x,pnorm,0,1/sqrt(1-rho^2)) -# Comment: The histogram suggests that the data is normally distributed. -# Comment: p-value for the Kolmogorv-Smirnov test is 0.006674 < 0.05. -# Therefore, we have to reject the null hypothesis. -# Thus, the given normal distribution is not a good fit for the sample data. -m<- 45;s <- 15 -x <- 27 -z <- (x-m)/s;z -pnorm(z) -x1 <- 39 -z1 <- (x1-m)/s;z1 -pnorm(z1) -0.3445783 -0.1150697 -qnorm(0.95,45,15) -qnorm(0.95) -z2 <- -15/sqrt(15^2+5^2) -z2 -z2 -pnorm(z2,lower.tail = FALSE) -library(MMatrix) -library(Matrix) -expm(P,3) -P <- matrix(c(0.5,0.4,0.3,0.3,0.20.3,0.2,0.4,0.3)) -P <- matrix(c(0.5,0.4,0.3,0.3,0.20.3,0.2,0.4,0.3),nrow=3) -P <- matrix(c(0.5,0.4,0.3,0.3,0.2,0.3,0.2,0.4,0.3),nrow=3) -P -power -P%^%3 -library(expm) -P%^%3 -p <- c(0.3,0.3,0.4) -p -P%^%3%*%p -x <- sqrt(10)*(2.226-2.1)/0.769;x -2*pnorm(x,lower.tail = FALSE) -2*pt(x,lower.tail = FALSE) -2*pt(x,lower.tail = FALSE,df=9) -2*pt(x,lower.tail = FALSE,df=9)/2 -setwd("C:/Users/bhoga/Downloads/rdevguide-SaranjeetKaur") -R.Version() -writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron") From 8388ff6e95e78f8c4ef3bfd9096264b5a547d015 Mon Sep 17 00:00:00 2001 From: Saranjeet Kaur Date: Mon, 5 Apr 2021 03:57:11 +0530 Subject: [PATCH 08/10] references added --- 02-getting_started.Rmd | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/02-getting_started.Rmd b/02-getting_started.Rmd index 5ca36d5..90fc57c 100755 --- a/02-getting_started.Rmd +++ b/02-getting_started.Rmd @@ -22,17 +22,9 @@ To install $\textsf{R}$ in Windows follow these steps: ## General instructions -1. The $\textsf{R}$ executable downloaded by following the above steps, is the binary distribution of `R-x.y.z`, which can run on Windows XP and above versions (including 64-bit versions of Windows). It can run on ix86 and x86_64 chips. +1. If you install the latest version or R-patched or R-devel, it will not over-write the previous installation(s) in your Windows machine. -2. There are two versions of the $\textsf{R}$ executable, the 32-bit version (in `R-x.y.z\bin\i386`) and the 64-bit version (in `R-x.y.z\bin\x64`). On the 32-bit versions of Windows, by default only the former gets installed, whereas on the 64-bit versions, both get installed. - -3. If there is already a previous version of R installed in your system and you want to retain the packages installed in it, then uninstall the previous version of $\textsf{R}$ (from the Control Panel) and install the new one. In the new installation, copy any installed packages to the library folder and run `update.packages(checkBuilt=TRUE, ask=FALSE)` in the new $\textsf{R}$. - -4. If there are different versions of R installed, then they are present in parallel folders. Hence, earlier versions can also be retained if you wish to keep them. - -5. When there is a change in the minor version of $\textsf{R}$ (say, from 4.0.3 to 4.1.0), then the library names (folder `R\win-library\x.y` of your home directory, `R\win64-library\x.y` on 64-bit builds), will need to be updated too. For doing this, copy (say) `R\win-library\4.0` to `R\win-library\4.1` and then run the `update.packages(checkBuilt=TRUE, ask=FALSE)` command. - -6. Daily [tarballs](https://stat.ethz.ch/R/daily/) are available for the patched version of the current release (`r-patched`), and the development version of the current release (`r-devel`). The same are also available via the [R Subversion repository](https://svn.R-project.org/R/) +2. Daily [tarballs](https://stat.ethz.ch/R/daily/) are available for the patched version of the current release (`r-patched`), and the development version of the current release (`r-devel`). The same are also available via the [R Subversion repository](https://svn.R-project.org/R/) ## Building $\textsf{R}$ and $\textsf{R}$ packages @@ -44,31 +36,20 @@ To install $\textsf{R}$ in Windows follow these steps: ### How to setup `RTools`? -1. The executable version of `RTools` that is specific to your requirements can be downloaded from https://cran.r-project.org/bin/windows/Rtools/ and run in the Windows-style installer. - -2. After completing the installation, you need to put the location of the RTools $\textit{make}$ $\textit{utilities}$ on the `PATH`. For doing this, exceute the following commands in $\textsf{R}$: - -```{r, results='hide'} -writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron") -``` +1. The latest version of `RTools` can be downloaded from https://cran.r-project.org/bin/windows/Rtools/ and run in the Windows-style installer. You will need to know if you have a 32-bit or 64-bit Windows machine (right-click `This PC` in Windows Explorer and check the properties if you are unsure). -Restart $\textsf{R}$ now. Verify that $\textit{make}$ can be found using the following command. (The output of the command should show the path where you installed `RTools`): +2. Don't forget to add `RTools` to the path as documented on the download page. -```{r, results='hide'} -Sys.which("make") -## "C:\\rtools40\\usr\\bin\\make.exe" -``` +### How to build $\textsf{R}$? -If the above works, then try installing an $\textsf{R}$ package from source: +To build $\textsf{R}$ for Windows using `RTools` follow the instructions in this [readme](https://github.com/r-windows/r-base#readme) file. -```{r, results='hide'} -## install.packages("jsonlite", type = "source") ## An example -``` +## See also -If you are successful in installing an $\textsf{R}$ package from source, then the setup for `RTools` is completed. +1. [CRAN official website](https://cran.r-project.org) -### How to build $\textsf{R}$? +2. [R installation and administration manual](https://cran.r-project.org/doc/manuals/r-patched/R-admin.html) -To build $\textsf{R}$ for Windows using `RTools` follow the instructions in this [readme](https://github.com/r-windows/r-base#readme) file. +3. [R for Windows FAQ](https://cran.r-project.org/bin/windows/base/rw-FAQ.html) -## References (chapterwise or at the end of the guide?) +4. [Rtools40 manual for Windows](https://cran.r-project.org/bin/windows/Rtools/) From eabe0d38bf705b198bd761c6ed4b180ae631199e Mon Sep 17 00:00:00 2001 From: Saranjeet Kaur Date: Mon, 5 Apr 2021 05:49:38 +0530 Subject: [PATCH 09/10] updated each section --- 02-getting_started.Rmd | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/02-getting_started.Rmd b/02-getting_started.Rmd index 90fc57c..516e012 100755 --- a/02-getting_started.Rmd +++ b/02-getting_started.Rmd @@ -4,33 +4,23 @@ These instructions cover how to install $\textsf{R}$ in Windows. The tools requi ## Installing $\textsf{R}$ -To install $\textsf{R}$ in Windows follow these steps: +1. The binary builds of $\textsf{R}$ for Windows can be downloaded and installed from [here](https://cran.r-project.org/bin/windows/base/). Along with the link to the latest stable release, this page also contains links to the binary builds of r-patched and r-devel. -1. Go to https://cran.r-project.org. +2. Click on the download links to download an executable installer. -2. Select `Download R for Windows`. You will be directed to a page which shows `Subdirectories` for installing R on Windows. - -3. Select `base` subdirectory. Alternatively, you can select `install R for the first time`, it leads to the same page. The current official stable release distribution of $\textsf{R}$ can be downloaded from here. (Along with the link to the current official stable release, links to the development snapshot build and to the previous releases, are also available on this page). - -4. This distribution is distributed as an installer `R-x.y.z-win.exe`. The `x.y.z` in the $\textsf{R}$ system version represent the major, minor, and patchlevel numbers, respectively. - -5. This has to be run in the Windows-style installer. - -6. Select the language while installing, read the public license information, and select destination location to the start the installation. You will be prompted to select components at this stage: `User installation`, `32-bit User installation`, `64-bit User installation`, or `Custom installation`. The default option may be opted for the questions from this step onwards. - -7. Complete the installation. +3. Select the language while installing, read the public license information, and select destination location to the start the installation. You will be prompted to select components at this stage: `User installation`, `32-bit User installation`, `64-bit User installation`, or `Custom installation`. The default option may be opted for the questions from this step onwards to complete the installation. ## General instructions 1. If you install the latest version or R-patched or R-devel, it will not over-write the previous installation(s) in your Windows machine. -2. Daily [tarballs](https://stat.ethz.ch/R/daily/) are available for the patched version of the current release (`r-patched`), and the development version of the current release (`r-devel`). The same are also available via the [R Subversion repository](https://svn.R-project.org/R/) +2. R uses a ‘major.minor.patchlevel’ version numbering scheme. Accordingly there are three are different versions of $\textsf{R}$ available as binary builds: the latest official release (`r-release`), the latest patched release (`r-patched`), and the latest development (`r-devel`). The `r-devel` is the next minor or eventually major release development version of $\textsf{R}$. Mostly, bug fixes are introduced in `r-patched`, while `r-devel` is for introducing new features. ## Building $\textsf{R}$ and $\textsf{R}$ packages ### What tools you need to build $\textsf{R}$ from source on Windows? -1. `RTools` is the [subdirectory](https://cran.r-project.org/bin/windows/Rtools/) which you want to build $\textsf{R}$ or your own $\textsf{R}$ package(s) on Windows. +1. [RTools](https://github.com/r-windows/docs/blob/master/faq.md#what-is-rtools) is the toolchain bundle that you can use to build, $\textsf{R}$ base and $\textsf{R}$ packages containing compiled code, on Windows. 2. You also need a distribution of $\LaTeX$ installed for building $\textsf{R}$ and checking packages. The `MiKTeX` distribution of $\LaTeX$ that is used on CRAN can be downloaded from https://miktex.org. @@ -42,7 +32,13 @@ To install $\textsf{R}$ in Windows follow these steps: ### How to build $\textsf{R}$? -To build $\textsf{R}$ for Windows using `RTools` follow the instructions in this [readme](https://github.com/r-windows/r-base#readme) file. +To build $\textsf{R}$ for Windows using `RTools` follow the instructions in this [readme](https://github.com/r-windows/r-base#readme) file. There are two options available to build $\textsf{R}$. One is the quick development build and the other option is the full installer build. + +For development and testing, you need only the quick development build. Because, the quick build avoids building the manuals, which are generally not needed for development and testing. + +However, even for the quick build there are some [default requirements](https://github.com/r-windows/r-base/blob/master/quick-build.sh). For instance, `MikTeX` is to be installed in `C:/Program Files` and you have 64-bit $\textsf{R}$. If necessary, these defaults can be customised. The installation path of `MikTex` can be customised [here](https://github.com/r-windows/r-base/blob/50a229fc76c50a5fb42c0daa367466aaf2318171/quick-build.sh#L13) whereas the Windows bit can be customised [here](https://github.com/r-windows/r-base/blob/50a229fc76c50a5fb42c0daa367466aaf2318171/quick-build.sh#L6). + +The full installer build is for building the complete installer as it appears on CRAN. It will build both the 32-bit and 64-bit $\textsf{R}$, the pdf manuals, and the installer program. You will use this to create the binary builds and not when building $\textsf{R}$ from the source yourself. ## See also @@ -53,3 +49,5 @@ To build $\textsf{R}$ for Windows using `RTools` follow the instructions in this 3. [R for Windows FAQ](https://cran.r-project.org/bin/windows/base/rw-FAQ.html) 4. [Rtools40 manual for Windows](https://cran.r-project.org/bin/windows/Rtools/) + +5. [R FAQ](https://cran.r-project.org/doc/FAQ/R-FAQ.html) From 9e2b74bb1e6f10d0c5fd2278b228f95040413e1f Mon Sep 17 00:00:00 2001 From: Saranjeet Kaur Date: Fri, 9 Apr 2021 16:40:00 +0530 Subject: [PATCH 10/10] minor edits to getting started chapter --- 02-getting_started.Rmd | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/02-getting_started.Rmd b/02-getting_started.Rmd index 516e012..b898b27 100755 --- a/02-getting_started.Rmd +++ b/02-getting_started.Rmd @@ -2,6 +2,20 @@ These instructions cover how to install $\textsf{R}$ in Windows. The tools required to build $\textsf{R}$ and $\textsf{R}$ packages in Windows are also discussed. +## General instructions + +1. If you install the latest version or R-patched or R-devel, it will not over-write the previous installation(s) in your Windows machine. + +2. R uses a ‘major.minor.patchlevel’ version numbering scheme. Accordingly there are three main releases of $\textsf{R}$ available to install: + + * The official release (`r-release`), + + * The patched release (`r-patched`), and + + * The development (`r-devel`) release. + +The `r-devel` is the next minor or eventually major release development version of $\textsf{R}$. Mostly, bug fixes are introduced in `r-patched`, while `r-devel` is for introducing new features. + ## Installing $\textsf{R}$ 1. The binary builds of $\textsf{R}$ for Windows can be downloaded and installed from [here](https://cran.r-project.org/bin/windows/base/). Along with the link to the latest stable release, this page also contains links to the binary builds of r-patched and r-devel. @@ -10,17 +24,11 @@ These instructions cover how to install $\textsf{R}$ in Windows. The tools requi 3. Select the language while installing, read the public license information, and select destination location to the start the installation. You will be prompted to select components at this stage: `User installation`, `32-bit User installation`, `64-bit User installation`, or `Custom installation`. The default option may be opted for the questions from this step onwards to complete the installation. -## General instructions - -1. If you install the latest version or R-patched or R-devel, it will not over-write the previous installation(s) in your Windows machine. - -2. R uses a ‘major.minor.patchlevel’ version numbering scheme. Accordingly there are three are different versions of $\textsf{R}$ available as binary builds: the latest official release (`r-release`), the latest patched release (`r-patched`), and the latest development (`r-devel`). The `r-devel` is the next minor or eventually major release development version of $\textsf{R}$. Mostly, bug fixes are introduced in `r-patched`, while `r-devel` is for introducing new features. - ## Building $\textsf{R}$ and $\textsf{R}$ packages ### What tools you need to build $\textsf{R}$ from source on Windows? -1. [RTools](https://github.com/r-windows/docs/blob/master/faq.md#what-is-rtools) is the toolchain bundle that you can use to build, $\textsf{R}$ base and $\textsf{R}$ packages containing compiled code, on Windows. +1. [RTools](https://github.com/r-windows/docs/blob/master/faq.md#what-is-rtools) is the toolchain bundle that you can use to build $\textsf{R}$ base and $\textsf{R}$ packages containing compiled code, on Windows. 2. You also need a distribution of $\LaTeX$ installed for building $\textsf{R}$ and checking packages. The `MiKTeX` distribution of $\LaTeX$ that is used on CRAN can be downloaded from https://miktex.org. @@ -32,13 +40,13 @@ These instructions cover how to install $\textsf{R}$ in Windows. The tools requi ### How to build $\textsf{R}$? -To build $\textsf{R}$ for Windows using `RTools` follow the instructions in this [readme](https://github.com/r-windows/r-base#readme) file. There are two options available to build $\textsf{R}$. One is the quick development build and the other option is the full installer build. +To build $\textsf{R}$ for Windows using `RTools` follow the instructions in this [README](https://github.com/r-windows/r-base#readme) file. There are two options available to build $\textsf{R}$. One is the quick development build and the other option is the full installer build. -For development and testing, you need only the quick development build. Because, the quick build avoids building the manuals, which are generally not needed for development and testing. +For development and testing, you need only the quick development build. The quick build avoids building the manuals, which are generally not needed for development and testing. However, even for the quick build there are some [default requirements](https://github.com/r-windows/r-base/blob/master/quick-build.sh). For instance, `MikTeX` is to be installed in `C:/Program Files` and you have 64-bit $\textsf{R}$. If necessary, these defaults can be customised. The installation path of `MikTex` can be customised [here](https://github.com/r-windows/r-base/blob/50a229fc76c50a5fb42c0daa367466aaf2318171/quick-build.sh#L13) whereas the Windows bit can be customised [here](https://github.com/r-windows/r-base/blob/50a229fc76c50a5fb42c0daa367466aaf2318171/quick-build.sh#L6). -The full installer build is for building the complete installer as it appears on CRAN. It will build both the 32-bit and 64-bit $\textsf{R}$, the pdf manuals, and the installer program. You will use this to create the binary builds and not when building $\textsf{R}$ from the source yourself. +If you are a maintainer of the Windows CRAN releases then, the full installer build is available for building the complete installer as it appears on CRAN. It will build both the 32-bit and 64-bit $\textsf{R}$, the pdf manuals, and the installer program. You will use this to create the binary builds and not when building $\textsf{R}$ from the source yourself. ## See also