2

I'm novice with R.

I have a text file with precalculated sequence of elliptic Fourier coefficients (harmonics). The first column keeps the objects name, other - sets of harmonics divides by spaces: A0 B0 C0 D0 ... An Bn Cn Dn. It is the part of a file:

Lceph-sp1-1    0    0,27    -1    0    -0,29    0,2    0,1    -0,05    0,15    0,1    0,07    0,02
Lceph-sp1-2    0    -0,36    1    0    -0,27    0,25    0,12    -0,09    -0,26    -0,03    -0,17    0
Lceph-sp1-3    0    0,25    -1    0    -0,29    0,19    0,09    -0,05    0,15    0,1    0,06    0,01
Lceph-sp1-4    0    -0,37    1    0    -0,27    0,26    0,09    -0,07    -0,19    -0,07    -0,12    -0,02

I load file into R with the read.delim2 command:

ef <- read.delim2( "filename", header=FALSE, sep="")

Then I want to analyze obtained data using functions from Momocs package, like calibrate_harmonicpower, plot, PCA and other.

To do so it is necessary to transform loaded data into Coe(?) or other object. (I don't exactly know to which one.)

How to prepare loaded data for analysis in Momocs R package?

Ivan Z
  • 1,517
  • 1
  • 16
  • 25

1 Answers1

2

If you calculates elliptical Fourier coefficients outside R/Momocs, then you must import them as an OutCoe object as follows:

# we load Momocs and import your table.
library(Momocs)

#Here I use your data (using `text` but a path to your file will work by your side
data <- read.table(dec=",", text="
Lceph-sp1-1    0    0,27    -1    0    -0,29    0,2    0,1    -0,05    0,15    0,1    0,07    0,02
Lceph-sp1-2    0    -0,36    1    0    -0,27    0,25    0,12    -0,09    -0,26    -0,03    -0,17    0
Lceph-sp1-3    0    0,25    -1    0    -0,29    0,19    0,09    -0,05    0,15    0,1    0,06    0,01
Lceph-sp1-4    0    -0,37    1    0    -0,27    0,26    0,09    -0,07    -0,19    -0,07    -0,12    -0,02")

# we can extract the `$fac` cofactor/variates table with `lf_structure`
fac <- lf_structure(data[, 1], names=c("ind", "sp", "id"), split="-")

# then we simply pass all columns but the first, the `fac` 
# and two others arguments `Momocs` cannot deduce `method` and `norm`
# see ?Outcoe
x <- OutCoe(coe=data[, -1], fac=fac, method="efourier", norm=TRUE)

We now have a 'working' Outcoe object:

> x
An OutCoe object [ elliptical Fourier analysis ]
--------------------
  - $coe: 4 outlines described, 3 harmonics
- $fac: 3 classifiers:
  'ind' (factor 1): Lceph.
'sp' (factor 1): sp1.
'id' (factor 4): 1, 2, 3, 4.

That you can use to continue your analyses, eg:

x %>% PCA %>% plot

Is that what you were looking for?

Vincent Bonhomme
  • 7,235
  • 2
  • 27
  • 38