--- title: "CondExp" author: "D. Renard" date: "11 mai 2021" output: pdf_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library(RGeostats) rm(list=ls()) ``` ## Introduction This file is meant to demonstrate the capabilities of the correlation function and its auxiliary features ## Data We create a set of variables in a Db. This Db is created as a regular grid for better legibility. The first variable is created by sampling a Normal distribution whereas the second one is obtained by adding a Uniform noise around the first variable. ```{r Data Base} db = db.create(nx=c(100,100)) db = db.add(db,var1=rnorm(db$nech)) db = db.add(db,var2=var1 + runif(db$nech,min=-1,max=1)) ``` ## Correlation The next plot shows the correlation between the two variables The correlation is discretized within a fine grid covering both axes. Each pixel is painted with a color which correponds to the number of samples contained within this pixel. ```{r Correlation} correlation(db,name1="var1",name2="var2") ``` The previous figure can be managed as far as its dimensions are concerned. For example, we can decide to set both axes equal. ```{r Iso} correlation(db,name1="var1",name2="var2",flag.iso=TRUE,asp=1) ``` ## Adding some decorations Adding the regression line in blue ```{r Regression_Line} correlation(db,name1="var1",name2="var2", flag.regr=TRUE, reg.lwd=2,reg.col="blue") ``` Adding the first bisector in red (even if it does not make too much sense here). The plot is represented with same scale on both axes. ```{r First_Bisector} correlation(db,name1="var1",name2="var2", flag.iso=TRUE,flag.diag=TRUE, diag.lwd=2, diag.col="red",asp=1) ``` Adding the regression curve in green ```{r Regression_Curve} correlation(db,name1="var1",name2="var2", flag.ce=TRUE, nbr.ce=20, ce.lwd=4, ce.col="green") ``` ## Representing the correlation as points When the number of samples is not too large, we may prefer to represent the scatter plot as a set of points. Each sample is now represented by an individual point whose color is set equal to the sample rank ```{r As_Points} correlation(db,name1="var1",name2="var2", ,name.col="rank",flag.aspoint=TRUE) ```