transformCharacter: Transformation of Character

View source: R/transformCharacter.R

transformCharacterR Documentation

Transformation of Character

Description

This function transforms morphological characters by applying another function passed in the argument.

Usage

transformCharacter(object, character, FUN, newName = NULL)

Arguments

object

an object of class morphodata.

character

a morphological character that should be transformed.

FUN

the transforming function to be applied to character.

newName

a name to rename the original character. If NULL, the name of the transformed character remains the same.

Details

Transformation is applied to characters to improve their distribution (to become normally distributed or at least to achieve lesser deviation from normality). The FUN argument takes any function, able to accept as input any value of the character specified by character argument.

Note that, when using a log transformation, a constant should be added to all values to make them all positive before transformation (if there are zero values in the data), because the argument of the logarithm can be only positive numbers. The arcsine transformation is applicable for proportions and percentages (for values ranging from 0 to 1).

Value

an object of class morphodata with the following elements:

ID

IDs of each row of data object.

Population

population membership of each row of data object.

Taxon

taxon membership of each row of data object.

data

data.frame of individuals (rows) and values of measured morphological characters (columns).

Examples

data(centaurea)

# For a right-skewed (positive) distribution can be used:
# Logarithmic transformation
cTransf = transformCharacter(centaurea, character = "SF", FUN = function(x) log(x+1))
cTransf = transformCharacter(centaurea, character = "SF", FUN = function(x) log10(x+1))
# Square root transformation
cTransf = transformCharacter(centaurea, character = "SF", FUN = function(x) sqrt(x))
# Cube root transformation
cTransf = transformCharacter(centaurea, character = "SF", FUN = function(x) x^(1/3))
# Arcsine transformation
cTransf = transformCharacter(centaurea, character = "SF", FUN = function(x) asin(sqrt(x)))

# For a left-skewed (negative) distribution can be used:
# Logarithmic transformation
cTransf = transformCharacter(centaurea, character="SF", FUN=function(x) log((max(x)+1)-x))
cTransf = transformCharacter(centaurea, character="SF", FUN=function(x) log10((max(x)+1)-x))
# Square root transformation
cTransf = transformCharacter(centaurea, character="SF", FUN=function(x) sqrt((max(x)+1)-x))
# Cube root transformation
cTransf = transformCharacter(centaurea, character="SF", FUN=function(x) ((max(x)+1)-x)^(1/3))
# Arcsine transformation
cTransf = transformCharacter(centaurea, character="SF", FUN=function(x) asin(sqrt((max(x))-x)))



MorphoTools2 documentation built on March 7, 2023, 6:18 p.m.