nira
: Near-infrared data analysisLast update: 10.10.2020
Author: M.Sc André Dantas de Medeiros (Universidade Federal de viçosa). Email: andre.d.medeiros@ufv.br
This package uses functions developed from the following packages:
pls, prospectr, dplyr, reshape2, ggplot2, ggpubr, factoextra, FactoMineR, readxl, plyr, caret, e1071
. We thank the creators of these useful packages.
Warning:
The data structure must be in Dataframe format. Use the following command to transform it into a dataframe: as.data.frame()
.
The last column must contain the response variable in factor
orcharacter
format.
The package is under development and was made for the specific needs of our laboratory.
#Install if(!require(devtools)) install.packages("devtools") if(!require(nira)) devtools::install_github("admedeiros/nira") #Load package library(nira)
if(!require(devtools)) install.packages("devtools") if(require(nira)) remove.packages("nira") .rs.restartR() if(!require(nira)) devtools::install_github("admedeiros/nira") #Load package library(nira)
import_csv()
: Import and merge CSV NIR files
plotmean_df()
: Create graphics with the average of the spectra class.
plotraw_df()
: Create graphics with the raw of the spectra class.
center_df()
: Center the data on the average.
autoscaling_df()
: Autoscaling the data using the Z-score transformation.
snv_df()
: Standard Normal Variate (SNV) on near-infrared (NIR) data.
msc_df()
: Multiplicative Scatter Correction (MSC) on near-infrared (NIR) data.
der_df()
: Applying derivatives with Savitzky-Golay smoothing..
pca_df()
: Plots a graph of the principal component analysis.
classification_df()
: Function to develop classification models
load_classifier_df()
: Function to load and apply classifier created with the classification_df function
prediction_df_df()
: Function to apply the classifier to new data without labels
library(nira) library(ggpubr) #for ggarrange # raw spectra a<-plotraw_df(nir_seed) # mean spectra per class b<-plotmean_df(nir_seed) # center c<-plotraw_df(center_df(nir_seed)) d<-plotmean_df(center_df(nir_seed)) # Autoscaling e<-plotraw_df(autoscaling_df(nir_seed)) f<-plotmean_df(autoscaling_df(nir_seed)) # SNV g<-plotraw_df(snv_df(nir_seed)) h<-plotmean_df(snv_df(nir_seed)) # MSC i<-plotraw_df(msc_df(nir_seed)) j<-plotmean_df(msc_df(nir_seed)) # 1st derivative with Savitzky-Golay smoothing k<-plotraw_df(der_SG(nir_seed,1)) l<-plotmean_df(der_SG(nir_seed,1)) # 2nd derivative with Savitzky-Golay smoothing m<-plotraw_df(der_SG(nir_seed,2)) n<-plotmean_df(der_SG(nir_seed,2)) x<-ggarrange(a, b,c,d,e,f,g,h,i,j,k,l,m,n, common.legend = TRUE, labels = c("Raw spectra", "Mean spectra", "Center ", "","Autoscaling","","SNV ","","MSC ", "","1st derivative", "", "2nd derivative", "" ), font.label = list(size=12), hjust = -0.7, vjust = 1, ncol = 2, nrow = 7) dados<-nir_seed classification<-classification_df(dados) p<-classification$plsplot q<-pca_df(nir_seed) y<-ggarrange(q,p, labels = c("PCA", "PLS-DA"), hjust = -8, vjust = 2, ncol = 1, nrow = 2) ggarrange(x,y, labels = c("Spetral",""), ncol = 2, nrow = 1)
library(nira) library(ggpubr) #for ggarrange # raw spectra a<-plotraw_df(nir_seed) # mean spectra per class b<-plotmean_df(nir_seed) # center c<-plotraw_df(center_df(nir_seed)) d<-plotmean_df(center_df(nir_seed)) # Autoscaling e<-plotraw_df(autoscaling_df(nir_seed)) f<-plotmean_df(autoscaling_df(nir_seed)) # SNV g<-plotraw_df(snv_df(nir_seed)) h<-plotmean_df(snv_df(nir_seed)) # MSC i<-plotraw_df(msc_df(nir_seed)) j<-plotmean_df(msc_df(nir_seed)) # 1st derivative with Savitzky-Golay smoothing k<-plotraw_df(der_SG(nir_seed,1)) l<-plotmean_df(der_SG(nir_seed,1)) # 2nd derivative with Savitzky-Golay smoothing m<-plotraw_df(der_SG(nir_seed,2)) n<-plotmean_df(der_SG(nir_seed,2)) ggarrange(a, b,c,d,e,f,g,h,i,j,k,l,m,n, labels = c("Raw spectra", "Mean spectra", "Center", "Center","Autoscaling","Autoscaling","SNV","SNV","MSC", "MSC","1st derivative", "1st derivative", "2nd derivative", "2nd derivative" ), ncol = 2, nrow = 7)
pca_df(nir_seed,1,2)
data(nir_seed) classification<-classification_df(nir_seed,metrics = 2)
classification$`Cross-validation`
classification$Training_results
classification$Testing_results
classification$plsplot
classification$`Variable importance`
data(nir_seed) load_classifier_df(nir_seed)
data(nir_seed) pc<-prediction_df(nir_seed[,-313]) pca_df(pc)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.