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 |
Convert to otolith_contour_list
as.otolith_contour_list(x, ...)
as.otolith_contour_list(x, ...)
x |
otolith_contour object or output from read_image |
... |
other parameters |
otolith_contour_list object
Christoffer Moesgaard Albertsen
Assign unknown contours by binomial regression on elliptic fourier descriptors
assign_unknown( nimList, N = 60, delta = 0.01, lambda = 1, link = "probit", normalize_efd = FALSE )
assign_unknown( nimList, N = 60, delta = 0.01, lambda = 1, link = "probit", normalize_efd = FALSE )
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 |
normalize_efd |
Should EFDs be normalized? |
A list of normalized contours where 'Unknown' Position attributes are replaced by 'Left' or 'Right'.
Christoffer Moesgaard Albertsen
Calculate Elliptical Fourier Descriptors
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, ...)
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, ...)
x |
contour object |
N |
Number of harmonics to calculate |
... |
other argiments |
returnAsList |
Should result be returned as a list that can be passed to |
normalize |
Normalize using method from Ferson et al. 1985? |
List of elliptical fourier descriptors
Christoffer Moesgaard Albertsen
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
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)
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
efd2coord(n, A, B, C, D, A0 = 0, C0 = 0)
efd2coord(n, A, B, C, D, A0 = 0, C0 = 0)
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 |
Matrix of coordinates
Christoffer Moesgaard Albertsen
Calculate XY-coordinates from Elliptical Fourier Descriptors
efd2coordOld(n, A, B, C, D, A0 = 0, C0 = 0)
efd2coordOld(n, A, B, C, D, A0 = 0, C0 = 0)
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 |
Matrix of coordinates
Christoffer Moesgaard Albertsen
Fast Correlation Based Filter for Feature Selection in High-Dimensional Data
fcbf( train, group, delta, lambda = 1, nCuts = function(x) { round(length(unique(x))/5) } )
fcbf( train, group, delta, lambda = 1, nCuts = function(x) { round(length(unique(x))/5) } )
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 |
A vector of selected features
Christoffer Moesgaard Albertsen
http://pdf.aminer.org/000/335/746/feature_selection_for_high_dimensional_data_a_fast_correlation_based.pdf
Flip an otolith
flip(x, axis, ...)
flip(x, axis, ...)
x |
otolith object |
axis |
axis to flip around |
... |
not used |
a flipped otolith object
Christoffer Moesgaard Albertsen
Fourier Series Basis for Splines
fs(x, N, Boundary = range(x))
fs(x, N, Boundary = range(x))
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 |
A matrix of dimension 'c(length(x), 2*N)'.
Christoffer Moesgaard Albertsen
Prepare allele matrix for PCA analysis
gen2PCA(x, alleleMeans)
gen2PCA(x, alleleMeans)
x |
output from \linkread.gen |
alleleMeans |
Mean allele frequencies to impute. Is calculated if missing. |
allele data for PCA analysis
Christoffer Moesgaard Albertsen
Calculate group means for a data frame of covariates
getGroupMeans(f, data, ...) ## S3 method for class 'mlld' getGroupMeans(f, data, keep.cov = FALSE, ...)
getGroupMeans(f, data, ...) ## S3 method for class 'mlld' getGroupMeans(f, data, keep.cov = FALSE, ...)
f |
|
data |
Christoffer Moesgaard Albertsen
Calculate group proportions for a data frame of covariates
getGroupProportion(f, data, ...) ## S3 method for class 'mlld' getGroupProportion(f, data, randEff = TRUE, ...)
getGroupProportion(f, data, ...) ## S3 method for class 'mlld' getGroupProportion(f, data, randEff = TRUE, ...)
f |
|
data |
Christoffer Moesgaard Albertsen
Get a pixel matrix from an image file
getPixelMatrix(file, grey = TRUE)
getPixelMatrix(file, grey = TRUE)
file |
Path to image file |
grey |
Should output be greyscale? |
A matrix of pixel values (0-255)
Christoffer Moesgaard Albertsen
Interpolate otolith coordinates through EFDs
interpolate(x, N, Nefd, ...)
interpolate(x, N, Nefd, ...)
x |
otolith object |
N |
Number of coordinates to output |
Nefd |
Number of EFDs to use |
... |
not used |
an interpolated otolith object
Christoffer Moesgaard Albertsen
knn
returns the votes to each level factor(group) from the kn nearest neighbours to test from train.
knn(train, group, test, kn = 1, dist = c("L2", "L1", "Linf"))
knn(train, group, test, kn = 1, dist = c("L2", "L1", "Linf"))
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
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), ... )
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), ... )
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 |
a list of the result
Christoffer Moesgaard Albertsen
Maximum likelihood linear discrimination
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, ... )
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, ... )
... |
|
proportionGroup |
|
confusionGroup |
Christoffer Moesgaard Albertsen
Normalize an Otolith Image
normalize_image( dat, n, datCompare = NULL, forceFlip = FALSE, flipByPosition = c("No", "Left", "Right", startByPolar = FALSE) )
normalize_image( dat, n, datCompare = NULL, forceFlip = FALSE, flipByPosition = c("No", "Left", "Right", startByPolar = FALSE) )
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. |
A normalized Otolith Image
Christoffer Moesgaard Albertsen
Plot otolith contour
## S3 method for class 'otolith_contour' plot(x, asUsed = FALSE, ...)
## S3 method for class 'otolith_contour' plot(x, asUsed = FALSE, ...)
x |
Otolith contour |
asUsed |
Plot image as read; i.e. transformed |
... |
further arguments |
nothing
Christoffer Moesgaard Albertsen
Plot otolith contour list
## S3 method for class 'otolith_contour_list' plot(x, asUsed = FALSE, ask = TRUE, ...)
## S3 method for class 'otolith_contour_list' plot(x, asUsed = FALSE, ask = TRUE, ...)
x |
Otolith contour list |
asUsed |
Plot image as read; i.e. transformed |
ask |
Ask before plotting next contour? |
... |
further arguments |
nothing
Christoffer Moesgaard Albertsen
Plot otolith image
## S3 method for class 'otolith_image' plot(x, asUsed = FALSE, ...)
## S3 method for class 'otolith_image' plot(x, asUsed = FALSE, ...)
x |
Otolith image |
asUsed |
Plot image as read; i.e. transformed |
... |
further arguments |
nothing
Christoffer Moesgaard Albertsen
The function uses the shoelace formula to calculate the signed area of a closed non-intersecting polygon.
polygon_area(X)
polygon_area(X)
X |
A numeric matrix with two columns of vertices |
Polygon area in same units as input
Christoffer Moesgaard Albertsen
Print otolith image contour
## S3 method for class 'otolith_contour' print(x, ...)
## S3 method for class 'otolith_contour' print(x, ...)
x |
Otolith image contour |
... |
further arguments |
nothing
Christoffer Moesgaard Albertsen
Print otolith image
## S3 method for class 'otolith_image' print(x, ...)
## S3 method for class 'otolith_image' print(x, ...)
x |
Otolith image |
... |
further arguments |
nothing
Christoffer Moesgaard Albertsen
LDA-like projection
projection(x, ...)
projection(x, ...)
x |
|
... |
Christoffer Moesgaard Albertsen
Read Otolith Images and Extract Contours
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 )
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 )
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, |
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 |
otolith image object
Christoffer Moesgaard Albertsen
Extract otolith contours from images
read_images(files, ...)
read_images(files, ...)
files |
file paths to read |
... |
Arguments passed to read_image |
an otolith_contour_list object
Christoffer Moesgaard Albertsen
read_image
Read genepop data files
read.gen( f, pop.names, sort.loci = FALSE, sort.individuals = FALSE, NAlleleKeep = NA )
read.gen( f, pop.names, sort.loci = FALSE, sort.individuals = FALSE, NAlleleKeep = NA )
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? |
an allele array
Christoffer Moesgaard Albertsen
Rotate an otolith
rotate(x, angle, degrees = TRUE, ...)
rotate(x, angle, degrees = TRUE, ...)
x |
object to rotate |
angle |
Angles to rotate the object |
degrees |
Is the angle in degrees? |
... |
not used |
A rotated element
Christoffer Moesgaard Albertsen
Run shiny example included in the package
runShinyExample(name)
runShinyExample(name)
name |
Name of the shiny example (biascorrect, or proportion) |
Nothing
Christoffer Moesgaard Albertsen