Package 'otoclass'

Title: Otolith Classification and Proportion Estimation
Description: Methods for classification and analysis of otoliths along with methods for estimating species proportions in samples.
Authors: Christoffer Moesgaard Albertsen [aut, cre]
Maintainer: Christoffer Moesgaard Albertsen <[email protected]>
License: GPL-2
Version: 0.8.0
Built: 2024-11-16 05:36:10 UTC
Source: https://github.com/calbertsen/otoclass

Help Index


Convert to otolith_contour_list

Description

Convert to otolith_contour_list

Usage

as.otolith_contour_list(x, ...)

Arguments

x

otolith_contour object or output from read_image

...

other parameters

Value

otolith_contour_list object

Author(s)

Christoffer Moesgaard Albertsen


Assign unknown contours by binomial regression on elliptic fourier descriptors

Description

Assign unknown contours by binomial regression on elliptic fourier descriptors

Usage

assign_unknown(
  nimList,
  N = 60,
  delta = 0.01,
  lambda = 1,
  link = "probit",
  normalize_efd = FALSE
)

Arguments

nimList

A list of normalized contours

N

Number of harmonics for the fourier descriptors

delta

passed to fcbf for feature selection

lambda

passed to fcbf for feature selection

link

Link function passed to stats::glm

normalize_efd

Should EFDs be normalized?

Value

A list of normalized contours where 'Unknown' Position attributes are replaced by 'Left' or 'Right'.

Author(s)

Christoffer Moesgaard Albertsen


Calculate Elliptical Fourier Descriptors

Description

Calculate Elliptical Fourier Descriptors

Usage

efd(x, N, ...)

## S3 method for class 'matrix'
efd(x, N, returnAsList = FALSE, normalize = FALSE, ...)

## S3 method for class 'otolith_contour'
efd(x, N, ...)

## S3 method for class 'otolith_image'
efd(x, N, ...)

## S3 method for class 'otolith_contour_list'
efd(x, N, ...)

Arguments

x

contour object

N

Number of harmonics to calculate

...

other argiments

returnAsList

Should result be returned as a list that can be passed to efd2coord?

normalize

Normalize using method from Ferson et al. 1985?

Value

List of elliptical fourier descriptors

Author(s)

Christoffer Moesgaard Albertsen

References

Kuhl, F. P., Giardina, C. R. (1981) Elliptic Fourier Features of a Closed Contour. Computer Graphics and Image Processing. 18:236-258 Ferson, S., Rohlf, F. J., Koehn, R. K. (1985) Measuring Shape Variation of Two-Dimensional Outlines. Systematic Zoology. 34(1):59-68

Examples

Ellipsis <- function(theta,r1=1,r2=2){
  xx <- seq(0,2*pi,len=100)
  X <- cbind(r1*cos(xx),r2*sin(xx))
  R <- matrix(c(cos(theta),sin(theta),-sin(theta),cos(theta)),2,2)
  Y <- t(apply(X,1,function(x) as.vector(R %*% x)))
  return(Y)
}
efd(Ellipsis(pi/2),1)

efd(Ellipsis(pi/2),1,normalize = TRUE)

efd(Ellipsis(-pi/2),1,normalize = TRUE)

Calculate XY-coordinates from Elliptical Fourier Descriptors

Description

Calculate XY-coordinates from Elliptical Fourier Descriptors

Usage

efd2coord(n, A, B, C, D, A0 = 0, C0 = 0)

Arguments

n

Number of coordinates to calculate

A

A EFD coefficients

B

B EFD coefficients

C

C EFD coefficients

D

D EFD coefficients

A0

A0 EFD coefficients

C0

C0 EFD coefficients

Value

Matrix of coordinates

Author(s)

Christoffer Moesgaard Albertsen


Calculate XY-coordinates from Elliptical Fourier Descriptors

Description

Calculate XY-coordinates from Elliptical Fourier Descriptors

Usage

efd2coordOld(n, A, B, C, D, A0 = 0, C0 = 0)

Arguments

n

Number of coordinates to calculate

A

A EFD coefficients

B

B EFD coefficients

C

C EFD coefficients

D

D EFD coefficients

A0

A0 EFD coefficients

C0

C0 EFD coefficients

Value

Matrix of coordinates

Author(s)

Christoffer Moesgaard Albertsen


Fast Correlation Based Filter for Feature Selection in High-Dimensional Data

Description

Fast Correlation Based Filter for Feature Selection in High-Dimensional Data

Usage

fcbf(
  train,
  group,
  delta,
  lambda = 1,
  nCuts = function(x) {     round(length(unique(x))/5) }
)

Arguments

train

A matrix of training data

group

A vector of groups

delta

Tuning parameter

lambda

Tuning parameter

nCuts

Function that calculates number of bins used for calculating correlations

Value

A vector of selected features

Author(s)

Christoffer Moesgaard Albertsen

References

http://pdf.aminer.org/000/335/746/feature_selection_for_high_dimensional_data_a_fast_correlation_based.pdf


Flip an otolith

Description

Flip an otolith

Usage

flip(x, axis, ...)

Arguments

x

otolith object

axis

axis to flip around

...

not used

Value

a flipped otolith object

Author(s)

Christoffer Moesgaard Albertsen


Fourier Series Basis for Splines

Description

Fourier Series Basis for Splines

Usage

fs(x, N, Boundary = range(x))

Arguments

x

the predictor variable

N

Half the number of basis functions. Both a cos and a sin basis function will be added.

Boundary

Boundary points that determines a period

Value

A matrix of dimension 'c(length(x), 2*N)'.

Author(s)

Christoffer Moesgaard Albertsen


Prepare allele matrix for PCA analysis

Description

Prepare allele matrix for PCA analysis

Usage

gen2PCA(x, alleleMeans)

Arguments

x

output from \linkread.gen

alleleMeans

Mean allele frequencies to impute. Is calculated if missing.

Value

allele data for PCA analysis

Author(s)

Christoffer Moesgaard Albertsen


Calculate group means for a data frame of covariates

Description

Calculate group means for a data frame of covariates

Usage

getGroupMeans(f, data, ...)

## S3 method for class 'mlld'
getGroupMeans(f, data, keep.cov = FALSE, ...)

Arguments

f
data

Author(s)

Christoffer Moesgaard Albertsen


Calculate group proportions for a data frame of covariates

Description

Calculate group proportions for a data frame of covariates

Usage

getGroupProportion(f, data, ...)

## S3 method for class 'mlld'
getGroupProportion(f, data, randEff = TRUE, ...)

Arguments

f
data

Author(s)

Christoffer Moesgaard Albertsen


Get a pixel matrix from an image file

Description

Get a pixel matrix from an image file

Usage

getPixelMatrix(file, grey = TRUE)

Arguments

file

Path to image file

grey

Should output be greyscale?

Value

A matrix of pixel values (0-255)

Author(s)

Christoffer Moesgaard Albertsen


Interpolate otolith coordinates through EFDs

Description

Interpolate otolith coordinates through EFDs

Usage

interpolate(x, N, Nefd, ...)

Arguments

x

otolith object

N

Number of coordinates to output

Nefd

Number of EFDs to use

...

not used

Value

an interpolated otolith object

Author(s)

Christoffer Moesgaard Albertsen


k Nearest Neighbour

Description

knn returns the votes to each level factor(group) from the kn nearest neighbours to test from train.

Usage

knn(train, group, test, kn = 1, dist = c("L2", "L1", "Linf"))

Arguments

train

A matrix of (continuous) features for the training sample

group

A vector of group labels for the training sample

test

A matrix of (continuous) features for the test sample

kn

Number of neighbours to consider

dist

Distance measure to use ("L1", "L2","Linf"). Default is Euclidian distance ("L2").


Maximum Likelihood Contour Discrimination

Description

Maximum Likelihood Contour Discrimination

Usage

mlcd(
  train,
  group,
  test,
  prior = as.vector(table(group))/length(group),
  penalty = 0,
  lambda = 0.4,
  Nefd = 60,
  correlatedCoordinates = FALSE,
  equalVariance = TRUE,
  silent = FALSE,
  control = list(iter.max = 1e+05, eval.max = 1e+05),
  ...
)

Arguments

train

3D Array of training data (2 x number of contour points x number of observations)

group

Factor of training groups

test

3D array of test data

prior

Prior probability of groups

penalty

p to use for Lp penalty. Zero is no penalty.

lambda

Positive scalar factor for Lp penalty. Zero is no penalty.

Nefd

Number of EFDs to use for mean otolith

correlatedCoordinates

Should coordinates be correlated?

equalVariance

Should the variance be equal in the two coordinates?

silent

Should the TMB object be silent?

control

control parameters passes to nlminb

...

Other parameters

Value

a list of the result

Author(s)

Christoffer Moesgaard Albertsen


Maximum likelihood linear discrimination

Description

Maximum likelihood linear discrimination

Usage

mlld(
  y,
  group,
  data = NULL,
  formula = ~1,
  formulaCommon = ~1,
  formulaProportion = ~1,
  formulaLogScale = ~-1,
  equalLogScale = FALSE,
  lp_penalty = NA,
  lambda = 0.4,
  estimateLambda = TRUE,
  REML = FALSE,
  tMixture = 0,
  tDf = 5,
  estimateTMix = FALSE,
  sameTMix = FALSE,
  estimateTDf = FALSE,
  sameTDf = FALSE,
  independent = FALSE,
  silent = FALSE,
  control = list(iter.max = 1e+05, eval.max = 1e+05),
  drop.unused.levels = TRUE,
  onlyObj = FALSE,
  doSdreport = TRUE,
  getReportCovariance = TRUE,
  equalVariance = TRUE,
  confusionMatrixList = NULL,
  groupConversionList = list(),
  confusionLevelTypes = rep("Known", ifelse(is.null(ncol(group)), 1, ncol(group))),
  observationType = c("MVMIX", "SNP1", "SNP2", "SPL_AR1", "FS1_AR1", "SPL_CATEGORICAL"),
  forceMeanIncrease = FALSE,
  fixZeroGradient = TRUE,
  SNP2dm = FALSE,
  sameSNP2dm = TRUE,
  SPLknots = NULL,
  Nefd = 5,
  lower = list(),
  upper = list(),
  guessStartingValues = TRUE,
  imputeMissing = FALSE,
  ...
)

Arguments

...
proportionGroup
confusionGroup

Author(s)

Christoffer Moesgaard Albertsen


Normalize an Otolith Image

Description

Normalize an Otolith Image

Usage

normalize_image(
  dat,
  n,
  datCompare = NULL,
  forceFlip = FALSE,
  flipByPosition = c("No", "Left", "Right", startByPolar = FALSE)
)

Arguments

dat

otolith_image object

n

Number of coordinates to output

datCompare

Data to compare with

forceFlip

Force a flip of the otolith?

flipByPosition

Position (Left/Right) to flip. Use 'No' if otoliths should not be flipped by position.

Value

A normalized Otolith Image

Author(s)

Christoffer Moesgaard Albertsen


Plot otolith contour

Description

Plot otolith contour

Usage

## S3 method for class 'otolith_contour'
plot(x, asUsed = FALSE, ...)

Arguments

x

Otolith contour

asUsed

Plot image as read; i.e. transformed

...

further arguments

Value

nothing

Author(s)

Christoffer Moesgaard Albertsen


Plot otolith contour list

Description

Plot otolith contour list

Usage

## S3 method for class 'otolith_contour_list'
plot(x, asUsed = FALSE, ask = TRUE, ...)

Arguments

x

Otolith contour list

asUsed

Plot image as read; i.e. transformed

ask

Ask before plotting next contour?

...

further arguments

Value

nothing

Author(s)

Christoffer Moesgaard Albertsen


Plot otolith image

Description

Plot otolith image

Usage

## S3 method for class 'otolith_image'
plot(x, asUsed = FALSE, ...)

Arguments

x

Otolith image

asUsed

Plot image as read; i.e. transformed

...

further arguments

Value

nothing

Author(s)

Christoffer Moesgaard Albertsen


Signed area of a closed polygon

Description

The function uses the shoelace formula to calculate the signed area of a closed non-intersecting polygon.

Usage

polygon_area(X)

Arguments

X

A numeric matrix with two columns of vertices

Value

Polygon area in same units as input

Author(s)

Christoffer Moesgaard Albertsen


Print otolith image contour

Description

Print otolith image contour

Usage

## S3 method for class 'otolith_contour'
print(x, ...)

Arguments

x

Otolith image contour

...

further arguments

Value

nothing

Author(s)

Christoffer Moesgaard Albertsen


Print otolith image

Description

Print otolith image

Usage

## S3 method for class 'otolith_image'
print(x, ...)

Arguments

x

Otolith image

...

further arguments

Value

nothing

Author(s)

Christoffer Moesgaard Albertsen


LDA-like projection

Description

LDA-like projection

Usage

projection(x, ...)

Arguments

x
...

Author(s)

Christoffer Moesgaard Albertsen


Read Otolith Images and Extract Contours

Description

Read Otolith Images and Extract Contours

Usage

read_image(
  file,
  noiseFactor = NULL,
  onlyOne = FALSE,
  minPixelDiff = 0.05 * min(nc, nr),
  extreme = TRUE,
  floodFillTolerance = 0.1,
  floodFillCol = 0,
  whiteBalance = 0.4,
  histogramAlpha = 0.4,
  borderBasedCutOff = FALSE,
  transformations = character(0),
  logisticTransformLocation = c("mean", "median", "borderMean", "borderMedian"),
  logisticTransformScale = 1,
  gaussianBlurSize = round(0.02 * min(nc, nr)),
  gaussianBlurSigma = gaussianBlurSize/10,
  pixelwise = FALSE,
  assignSinglesByPosition = TRUE,
  forceCenter = TRUE,
  minCountScale = 0,
  minCountForMax = 1e-04,
  reduceCutOffPercent = 0,
  zeroCutOffPercent = 0.05
)

Arguments

file

Image file path

noiseFactor

Scalar value determining cutoff value for background noise on image. If NULL, a value is calculated automatically.

onlyOne

Boolean value. Is there only one otolith on the image?

minPixelDiff

Minimum pixel difference between otoliths

extreme

Boolean value. Should pixel values be converted to 0/1?

borderBasedCutOff

Use a border based cut off?

transformations

Vector of image transformations: logistic, gaussianBlur, unsharp, floodFill

logisticTransformLocation

Location parameter for logistic transformation

logisticTransformScale

Scale parameter for logistic transformation

gaussianBlurSize

Size (n x n) for Gaussian blur kernel

gaussianBlurSigma

Variance parameter of Gaussian distribution used to blur

pixelwise

Boolean value. If TRUE, a pixel-wise algorithm is used to extract contours; otherwise, grDevices::contourLines is used.

assignSinglesByPosition

Should single otoliths be assigned to Left/Right based on position on image?

minCountScale

See details

minCountForMax

See details

reduceCutOffPercent

See details

zeroCutOffPercent

See details

Value

otolith image object

Author(s)

Christoffer Moesgaard Albertsen


Extract otolith contours from images

Description

Extract otolith contours from images

Usage

read_images(files, ...)

Arguments

files

file paths to read

...

Arguments passed to read_image

Value

an otolith_contour_list object

Author(s)

Christoffer Moesgaard Albertsen

See Also

read_image


Read genepop data files

Description

Read genepop data files

Usage

read.gen(
  f,
  pop.names,
  sort.loci = FALSE,
  sort.individuals = FALSE,
  NAlleleKeep = NA
)

Arguments

f

file name

pop.names

population names. If missing, the ID of the last individual is used

sort.loci

Should loci be sorted by names?

sort.individuals

Should individuals be sorted by id?

Value

an allele array

Author(s)

Christoffer Moesgaard Albertsen


Rotate an otolith

Description

Rotate an otolith

Usage

rotate(x, angle, degrees = TRUE, ...)

Arguments

x

object to rotate

angle

Angles to rotate the object

degrees

Is the angle in degrees?

...

not used

Value

A rotated element

Author(s)

Christoffer Moesgaard Albertsen


Run shiny example included in the package

Description

Run shiny example included in the package

Usage

runShinyExample(name)

Arguments

name

Name of the shiny example (biascorrect, or proportion)

Value

Nothing

Author(s)

Christoffer Moesgaard Albertsen