Widget HTML Atas

Chemometrics With R Package Download

How to install and use R to perform chemometrics analysis

Figures - uploaded by Endler Marcel Borges

Author content

All figure content in this area was uploaded by Endler Marcel Borges

Content may be subject to copyright.

ResearchGate Logo

Discover the world's research

  • 20+ million members
  • 135+ million publications
  • 700k+ research projects

Join for free

How to install and use R to perform

chemometrics analysis

La´ıs Feltrin Sidou; Prof. Dr. Endler Marcel Borges

September 13, 2019

Contents

1 Installing and using R 2

1.1 Accessing CRAN and downloading the most recent version of R 2

1.2 InstallingR ............................ 4

1.3 UsingR'sinterface ........................ 6

1.3.1 Installing a package . . . . . . . . . . . . . . . . . . . . 7

1.3.2 Loading a package . . . . . . . . . . . . . . . . . . . . 9

2 Running the Principal Components Analysis (PCA) using

RCommander 11

2.1 Loading a plugin in RCommander . . . . . . . . . . . . . . . . 12

2.2 RunningthePCA......................... 12

3 Further reading 20

1

1 Installing and using R

R is a free and open source software capable of running several statistical

analysis, from the most simple to the most complex ones (R Core Team,

2016).

Installing R on Windows is a very simple task. The steps are shown down

below.

1.1 Accessing CRAN and downloading the

most recent version of R

Go to CRAN h https://cran.r-project.org/i , database where all the files

from R project are stored. Click on "Download R for Windows", according

to Figure 1.1.

2

Figure 1.1:

On the new page, click on "base", according to Figure 1.2.

Figure 1.2:

Then, click on "Download R (version-number) for Windows" to download

the executable file (.exe), according to Figure 1.3. Wait until the download

is completed.

3

Figure 1.3:

1.2 Installing R

Open the downloaded .exe file and give it the necessary permissions for

the installation as needed. The first window, represented in Figure 1.4, asks

for the desired installation language.

Figure 1.4:

Click on "OK" and then on "Next" in the next windows. Select the

installation components according to Figure 1.5.

4

Figure 1.5:

Accept the standart installation and initialization option, according to

Figure 1.6. Click "Next" until the installation is completed.

Figure 1.6:

5

1.3 Using R's interface

For Windows OSs, the standard R installation comes with a simple but

effective graphical user interface (GUI) which offers the main usage options

such as inserting a new data set, installing packages, etc, like shown in Figure

1.7 with the command line interface (CLI) on the left side and the main menus

above.

Figure 1.7:

On Windows it is not necessary to use the CLI for tasks like installing

and loading packages. However, it can be used if you prefer it.

6

1.3.1 Installing a package

To install a package using the GUI, access the "Packages" menu and then

click on the "Install package(s)..." option according to Figure 1.8.

Figure 1.8:

Then, select the desired mirror for the installation from which the pack-

ages will be downloaded (Figure 1.9). It is recommended to use the nearest

mirror to your location because the download will be faster.

7

Figure 1.9:

After clicking on "OK", select the desired package on the list. For

the purposes of this tutorial, we will be using the packages "Rcmdr" and

"RcmdrPlugin.FactoMineR". It is recommended to install the packages

separately, in the order above, to avoid dependence conflicts. Wait until the

installation of both packages is completed.

Alternatively, you can use the command line interface. For that, type the

following command on the "R Console" and press Enter:

install.packages('package-name')

To install the desired packages for this tutorial, the commands are:

install.packages('Rcmdr') and

install.packages('RcmdrPlugin.FactoMineR')

8

The CLI will guide the installation on how to choose the mirror in a

simple and intuitive way. Wait until all the packages are installed and check

for any installation errors.

1.3.2 Loading a package

To load a package using the GUI, simply access again the "Packages"

menu, click on the "Load package..." option and choose the desired package

from the list – in this case, we will be loading the Rcmdr package only.

To use the CLI, the generic syntax is:

library(package-name)

And to load the Rcmdr the package:

library(Rcmdr)

The first time you load RCommander (Rcmdr) it is likely that it will

show an error box (Figure 1.10) requiring the installation of some additional

packages. Click on "Yes" and, in the following window, click on "OK" (Figure

1.11). The packages will be downloaded from CRAN and installed on your

computer.

Figure 1.10:

9

2 Running the Principal Components

Analysis (PCA) using RComman-

der

Once the installation of the required packages is completed and the pack-

age Rcmdr (RCommander) is loaded, a new working space will show up

(Figure 2.1).

Figure 2.1:

RCommander carries a very complete selection of statistical analysis in

a simple graphical user interface. Among its greatest perks are the series of

11

plugins (RcmdrPlugin...) which can add new functionalities to the interface,

making it simple and intuitive to perform complex analysis such as PCA,

HCA and others.

2.1 Loading a plugin in RCommander

We have already installed the FactoMineR plugin, which allows us to run

the PCA. To load it in RCommander, simply go to the "Tools" menu and,

then, select the option "Load Rcmdr plug-in(s) ". Select RcmdrPlu-

gin.FactoMineR from the list with the installed plugins that will show up

(Figure 2.2).

Figure 2.2:

RCommander will request to be restarted. After this, a new menu called

FactoMineR will show up in the superior toolbar.

2.2 Running the PCA

When first clicking on the 'FactoMineR' menu, the only possible option

is to insert a new data set ("Read data from text file, clipboard or URL").

Click on it to load the data set previously saved in your computer.

Attention!

Your data must be saved in .csv or .dat file formats

12

A new window will pop up asking information about the data file format-

ting (Figure 2.3).

Figure 2.3:

Take the following steps:

1. Enter a name for your data set;

2. Verify if the first row of your data set corresponds to the variable names.

If so, check the option "Variable names in file";

3. Verify if the first column of your data set corresponds to the sample

names. If so, check the option "Row names in the first columns";

4. If the data set file is saved in your computer, select the option "Local

file system";

5. Open your data set file with a separate text reader (like Notepad) and

check the field separator being used: white space, commas or tabs.

Select the corresponding option.

13

6. Check if the decimal point character is a period (as in 1.234) or a

comma (as in 1,234) and mark the correct option.

7. Click on "OK". Browse for the data set file in your computer folders

and open it.

Attention!

Check the selected options in this step carefully and thoroughly.

Selecting the wrong option can make R unable to recognize your data.

If everything was done correctly, RCommander should show the following

output (Figure 2.4):

Figure 2.4:

When clicking on "See data set" it is possible to see the inserted data

and check if there were any mistakes when importing the file (Figure 2.5).

For the purposes of this tutorial, we will be using the data provided by Lyra

et al. (2010).

14

Figure 2.5:

The spaces with a gray background correspond to the variable names

(first row) and sample names (first column).

Then, click again on 'FactoMineR'. Now, the plugin's analysis options are

available. Click on "Principal Component Analysis (PCA)". A new window

will pop up with the analysis options (Figure 2.6).

15

Figure 2.6:

For this tutorial, we will use the standard options provided by the tool.

Click on "OK" and wait for the results.

The expected results are: a text output with information on the Eigenval-

ues and the cumulative percentage of variance (Figure 2.7) and two graphs:

an individuals (samples) map (Figure 2.8) and a variables map (Figure 2.9).

16

3 Further reading

For further information on how to use the R Commander package please

refer to its CRAN page h https://cran.r-project.org/web/packages/Rcmdr/

index.htmli.

20

Bibliography

LYRA, Wellington da Silva et al. Classifica¸ao peri´odica: um

exemplo did´atico para ensinar an´alise de componentes principais.

Qu´ımica Nova, v. 33, n. 7, p. 1594–1597, 2010. ISSN 0100-4042.

Dispon´ıvel em: h http://www.scielo.br/scielo.php?script=sci abstract&pid=

S0100-40422010000700030&lng=p&nrm=iso&tlng=pti.

R Core Team. R: A Language and Environment for Statistical Com-

puting. Vienna, Austria, 2016. Dispon´ıvel em: h https://www.R-project.

orgi.

21

Principal component analysis (PCA) is one of the most important and powerful methods in chemometrics as well as in a wealth of other areas. Running a PCA results in two main elements, the score plot and the loading plot; the score plot provides the location of the samples, and the loading plot indicates correlations among variables, the trends in the grouping of samples, and the most important variables. In the past 10 years teaching chemometrics, we have struggled with not having free software with an easy to use graphical user interface for data handling and calculations. In this paper, we provide a series of examples that students used to carry PCA in R-Project, a free and open source software program. In the first example, students used PCA to find correlations among chemical properties of chemical elements and relate these properties with the periodic distribution of the elements. In the second example, meat samples were grouped using 14 variables, and students could observe how outlier samples might influence the PCA model; in this case, they were also taught how to use the t test to choose the variables that were significant to the PCA model. In the third example, healthy patients were differentiated from diabetic patients using 163 lipid concentrations. In the fourth example, Atlantic salmon samples were differentiated from catfish samples. In the fifth and sixth examples, students were able to observe how data treatment affects the classification of natural products and edible oils, respectively. Copyright © 2020 American Chemical Society and Division of Chemical Education, Inc.

PERIODIC CLASSIFICATION: A DIDACTIC EXAMPLE TO TEACH PRINCIPAL COMPONENT ANALYSIS. A dataset of chemical properties of the elements is used herein to introduce principal components analysis (PCA). The focus in this article is to verify the classification of the elements within the periodic table. The reclassification of the semimetals as metals or nonmetals emerges naturally from PCA and agrees with the current SBQ/IUPAC periodic table. Dataset construction, basic preprocessing, loading and score plots, and interpretation have been emphasized. This activity can be carried out even when students with distinct levels of formation are together in the same learning environment.

Source: https://www.researchgate.net/publication/337801370_How_to_install_and_use_R_to_perform_chemometrics_analysis

Posted by: fivewidget02.blogspot.com