Introduction

What is R ?

According to the R-project site :

R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R.

Note that R is available as Free Software and runs on a wide variety of platforms UNIX, Linux, Windows or MacOS.

R is made of 5 components:

• an effective data handling and storage facility (list, vectors, matrices)
• a suite of operators for calculations on vector and matrices
• a large collection of intermediate tools for data analysis
• graphical facilities for data analysis
• a simple and effective programming language

All of this makes R very difficult to master all the more that the functions produce different results in function of the parameters provided.

How can I use R ?

You can either :

• use the text interface with the program R in a terminal
• use the Rscript program to execute scripts
• use the graphical interface called R-studio

Terminal

For example if you execute R in a terminal you will get somehting like this and you will be in interactive mode: you have to type your calculation and press enter to get the result

Multiple non linear regression

> x
[1] 10 20 30 40 50
> z
[1] 60 16  1 18 64

fit <- nls(z ~ a +  b * ((x -c)^2), start=list(a=-10, b=-50,c=0))
> summary(fit)

Formula: z ~ a + b * ((x - c)^2)

Parameters:
Estimate Std. Error t value Pr(>|t|)
a  1.497776   0.353335   4.239   0.0514 .
b  0.151429   0.001355 111.734 8.01e-05 ***
c 29.669811   0.053030 559.487 3.19e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.5071 on 2 degrees of freedom

Number of iterations to convergence: 3
Achieved convergence tolerance: 4.058e-06

> coefficients(fit)
a          b          c
1.4977757  0.1514286 29.6698114
> f <- function(x) 1.4977757 + 0.1514286 *((x - 29.6698114)^2)
> sapply(x, f)
[1] 60.085725 15.657145  1.514285 17.657145 64.085725

> c <- coefficients(fit)
> f <- function(x) c[1] + c[2] *((x - c[3])^2)
> sapply(x, f)
a         a         a         a         a
60.085713 15.657142  1.514285 17.657142 64.085712