how to get confidence ellipse

Hello, I am working on a data set, where I was wondering if how can I have confidence ellipses around samples. If someone can help me,

#preparation of contigency table
#date: 03-22-2020

library(FactoMineR)

# reading data 
df1 <- read.csv("C:/Users/che/Downloads/maieu_data_aroma.csv",stringsAsFactors = F)
contingency.table <-  aggregate(df1[-c(1,2)], list(product=df1[, 2]), sum, na.rm=T)

library(prettyGraphs)
#> Warning: package 'prettyGraphs' was built under R version 3.5.2
library(ExPosition)
#> Warning: package 'ExPosition' was built under R version 3.5.2
ca.ex <- epCA(contingency.table[-1], graphs = F)
epGraphs(ca.ex)
#> **ExPosition plotting data**
#> *Contains the following objects:
#> 
#>   name           description                           
#> 1 "$fi.col"      "The colors for the row items."       
#> 2 "$fi.pch"      "The pch values for the row items."   
#> 3 "$fj.col"      "The colors for the column items."    
#> 4 "$fj.pch"      "The pch values for the column items."
#> 5 "$constraints" "Plotting constraints for axes."
install.packages("boot")
#> Installing package into 'C:/Users/chetan/Documents/R/win-library/3.5'
#> (as 'lib' is unspecified)
#> 
#>   There is a binary version available but the source version is
#>   later:
#>      binary source needs_compilation
#> boot 1.3-24 1.3-25             FALSE
#> installing the source package 'boot'
library(boot)
library(SensoMineR)
#> 
#> Attaching package: 'SensoMineR'
#> The following object is masked from 'package:boot':
#> 
#>     boot
DistanceCube <- DistanceFromSort(contingency.table)
#> Error in DistanceFromSort(contingency.table): could not find function "DistanceFromSort"
boot(df1, method = "sorting", axes = 1:2, scale = TRUE, ncp = NULL, group = NULL,
     nbsim = 200,level.conf = 0.95,nbchoix = NULL,color = NULL,cex = 0.8, 
     title = NULL, new.plot = TRUE)
#> Error in dimnames(res) <- list(attributes(tab)$row.names, listModa): length of 'dimnames' [2] not equal to array extent

Created on 2020-05-29 by the reprex package (v0.3.0)

Hi, I'm not sure if this is still an issue. Which data do you want to trace with an "ellipse"? There are many ways of doing this. In the very useful package "car", there is a function ellipse(). There is also confidenceEllipse, and others.

The code below installs car, loads it, and generates ellipses graphs from the help file in the package, with data that will be in your environment. This code was written by these fine people: Georges Monette, John Fox, and Michael Friendly.

If you just copy and paste into Rstudio, you'll have several ellipses graphs in your terminal immediately:

install.packages("car")
library(car)

dataEllipse(Duncan$income, Duncan$education, levels=0.1*1:9, 
            ellipse.label=0.1*1:9, lty=2, fill=TRUE, fill.alpha=0.1)

confidenceEllipse(lm(prestige~income+education, data=Duncan), Scheffe=TRUE)

confidenceEllipse(lm(prestige~income+education, data=Duncan), vcov.=hccm)

confidenceEllipse(lm(prestige~income+education, data=Duncan), 
                  L=c("income + education", "income - education"))

wts <- rep(1, nrow(Duncan))

wts[c(6, 16)] <- 0 # delete Minister, Conductor

with(Duncan, {
  dataEllipse(income, prestige, levels=0.68)
  dataEllipse(income, prestige, levels=0.68, robust=TRUE, 
              plot.points=FALSE, col="green3")
  dataEllipse(income, prestige, weights=wts, levels=0.68, 
              plot.points=FALSE, col="brown")
  dataEllipse(income, prestige, weights=wts, robust=TRUE, levels=0.68, 
              plot.points=FALSE, col="blue")
})

with(Prestige, dataEllipse(income, education, type, 
                           id=list(n=2, labels=rownames(Prestige)), pch=15:17,
                           xlim=c(0, 25000), center.pch="+",
                           group.labels=c("Blue Collar", "Professional", "White Collar"),
                           ylim=c(5, 20), level=.95, fill=TRUE, fill.alpha=0.1))

plot(x)
ellipse()

Thanks @Orson for the help. I am new to R and also trying to understand confidence ellipses role. I am using bootstrap resampling function, so if possible can you please help me under the context of this function.
I am receiving below mentioned error:

#preparation of contigency table
#date: 03-22-2020

library(FactoMineR)

# reading data 
df1 <- read.csv("C:/Users/chetan/Downloads/aroma.csv",stringsAsFactors = F)
contingency.table <-  aggregate(df1[-c(1,2)], list(product=df1[, 2]), sum, na.rm=T)

library(prettyGraphs)
#> Warning: package 'prettyGraphs' was built under R version 3.5.2
library(ExPosition)
#> Warning: package 'ExPosition' was built under R version 3.5.2
ca.ex <- epCA(contingency.table[-1], graphs = F)
epGraphs(ca.ex)
#> **ExPosition plotting data**
#> *Contains the following objects:
#> 
#>   name           description                           
#> 1 "$fi.col"      "The colors for the row items."       
#> 2 "$fi.pch"      "The pch values for the row items."   
#> 3 "$fj.col"      "The colors for the column items."    
#> 4 "$fj.pch"      "The pch values for the column items."
#> 5 "$constraints" "Plotting constraints for axes."

library(boot)
library(SensoMineR)
#> 
#> Attaching package: 'SensoMineR'
#> The following object is masked from 'package:boot':
#> 
#>     boot
boot(contingency.table, method = "sorting", axes = 1:2, scale = TRUE, ncp = NULL, group = NULL,
     nbsim = 200,level.conf = 0.95,nbchoix = NULL,color = NULL,cex = 0.8, 
     title = NULL, new.plot = TRUE)
#> Error in dimnames(res) <- list(attributes(tab)$row.names, listModa): length of 'dimnames' [2] not equal to array extent

Created on 2020-06-12 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.