Showing posts with label R codes. Show all posts
Showing posts with label R codes. Show all posts

Friday, June 19, 2015

Nonlinear fit to exponential decay model in R

I had some trouble looking around for a non linear model that could fit exponential decay model on R. Finally this is what I have. Hopefully, the next code searcher will find it easier to hunt for such a code!
 :D

The data is in this format:
Week  TAD
0          a
1          b
….
(a and b are values of Cellulose concentration)

ti = seq(0,11, 0.1)
kSAD = nls(TAD~exp(-k*Week), start =list(k= 0.5), trace=T)
summary(kSAD)
plot(Week,TAD, pch=16, xlab="Week", ylab="Cellulose concentration microcosms in mg/mL", cex.lab=1.45,cex.axis=1.5)
lines(ti, predict(kSAD, list(Week = ti)), col="black", lty=3, lwd=2)
arrows(Week, TAD-RETAD, Week, TAD+RETAD, length=0.05, angle=90, code=3)
Created by Pretty R at inside-R.org

Enjoy! <3

Friday, July 25, 2014

Uninstalling old version of R in Ubuntu 12.04.4 for R 3.1.1

After many frustrated attempts at installing the newer version of R aka R version 3.1.1 (2014-07-10) I finally figured out what was perhaps happening.

I had done the glorious and famous step 0 of:
sudo apt-get update
sudo apt-get remove r-base
sudo apt-get remove r-base-core

up to no avail! R.2 something always managed to run and execute itself.

"Sock it to Me"

What finally worked was an interesting combinations of various suggestions on internet that some how worked together - like a miracle!

The long and short of the procedure of installing R. 3.1.1  after successfully effacing the older version of R is:

Uninstalling the older version
Step 1: Do the Step 0 (the above mentioned glorious and famous step 0) of removing r-base and r-base-core

Step2: See what still remains:
 dpkg --get-selections | grep "^r\-"'

Step 3: Individually purge the files that belong to 'r-' family. I used sudo apt-get purge (name of R related file)

Installing the R 3.1.1 (2014-07-10) -- "Sock it to Me" 
Step 4: Followed suggestions as mentioned here: (http://askubuntu.com/a/352438) Please note that when I typed in the command for seeing r packages
apt-cache showpkg r-base I saw different packages than the ones mentioned in the comments. This is explainable as packages keep updating with newer ones showing up. I had the following show up:

Package: r-base
Versions:
3.1.1-1precise0 (/var/lib/apt/lists/cran.rstudio.com_bin_linux_ubuntu_precise_Packages) (/var/lib/dpkg/status)
 Description Language:
                 File: /var/lib/apt/lists/cran.rstudio.com_bin_linux_ubuntu_precise_Packages
                  MD5: 5787ca79ed716232c4cc2087ed9b425b

so I did
sudo apt-get install -f r-base=3.1.1-1precise0

Step 5: Typed in R and bingo!!

Enjoy R folks!

Monday, May 6, 2013

Spinning 3D MDS plot in R

I did the classical MDS on my data and drew 3D spinning MDS plot and here is the code:
(Note that this code uses vegan, MASS, and rgl packages and the plot below was made in R 2.15.3)


And here is the plot:



Yay!

And yes now here is the data format:
In first column are names of different samples and in next columns abundance of different classes of bacteria. 

Sample A   sp1   sp2   sp3   sp4 ...
Sample B   sp1   sp2   sp3   sp4 ...
Sample C   sp1   sp2   sp3   sp4 ...
.
.