lenfreq.expand {FSA}R Documentation

Expands a length frequency based on a subsample.

Description

Creates a list of lengths for the individuals not measured based on the lengths measured in a subsample of individuals.

Usage

lenfreq.expand(df,cl=NULL,startcat,w,total,decimals=w.dec,...)

Arguments

df A data.frame that (minimally) contains a column of length measurements or a vector of observed lengths. See details.
cl A number or name indicating which column the length measurements occupy in the data.frame, df. Set to NULL if df is a vector.
startcat A number indicating the beginning of the first length-class.
w A number indicating the width of length classes to create.
total The total number of individuals in the sample (including those that were measured in the subsample).
decimals A number indicating the number of decimals used in the output vector of estimated lengths.
... Optional arguments to be passed to the lencat function.

Details

This function can take either a vector of observed lengths or a data.frame in which the variable containing the lengths is identified. If a vector is given in df then cl must be set to {NULL}. If a data.frame is given in df then cl must contain a valid name or number of the column containing the observed lengths.

The function will create length categories that begin with the value in startcat and continue by values of w until a category value greater than the largest observed length in df. The code does not allow categories of different widths. See the lencat function.

The resulting lengths are created by allocating individuals to each length class based on the proportion of measured individuals in the subsample in that length class. Individuals within a length class are then assigned a specific length within that length class based on a uniform distribution. Because the expanded number of individuals in a length class is rounded down based on the measured number per length class not all individuals will be assigned a length value initially. The remaining individuals are assigned to a length class randomly according to weights based on the proportion of individuals in the measured length classes. Finally, these individuals are assigned a specific length within the respective length class in the same manner as above.

The resulting length assignments are rounded to the number of decimals shown in decimal. If decimals is not set by the user then it will default to the same number of decimals shown in the w value. Care is taken to make sure that the rounded result will not pass out of the given length category (i.e., will not be allowed to round up to the next length category). Generally speaking, one will want to use more decimals then is shown in w. For example, one may want to create length categories with a width of 1 inch (i.e., w=1) but have the results printed as if measured to within 0.1 inch (i.e., decimals=1).

Value

Returns a vector that consists of measurements for the non-measured individuals in the entire sample.

Author(s)

Derek H. Ogle, dogle@northland.edu

Examples

## First example
# random lengths measured to nearest 0.1 unit
len1 <- round(runif(50,0.1,9.9),1)

# assignment of integer lengths to 110 non-measured indivs
new.len1a <- lenfreq.expand(len1,startcat=0,w=1,total=160)
new.len1a

# assignment of lengths to 0.1 to 110 non-measured indivs
new.len1b <- lenfreq.expand(len1,startcat=0,w=1,total=160,decimals=1)
new.len1b

## Second example
# random lengths measured to nearest 0.1 unit
len2 <- data.frame(len=round(runif(50,10,117),1))

# assignment of lengths to 0.1 for 40 non-measured indivs
new.len2a <- lenfreq.expand(len2,startcat=10,w=10,total=190,decimals=1)
new.len2a

## Third example
# hypothetically measured lengths
len <- c(6.7,6.9,7.3, 7.4,7.5,8.2,8.7,8.9)

# find lengths for unmeasured fish assuming a total of 30
newlen1 <- lenfreq.expand(len,startcat=6,w=0.5,total=30,decimals=1)
newlen1
# put together with measured lengths and make histogram
alllen <- c(len,newlen1)
hist(alllen,breaks=10,main="")

[Package FSA version 0.0-13 Index]