This function converts an appropriatedly formated comma-separated values file (.csv) to a format usable by unmarked's fitting functions (see Details).

csvToUMF(filename, long=FALSE, type, species, ...)

Arguments

filename

string describing filename of file to read in

long

FALSE if file is in long format or TRUE if file is in long format (see Details)

species

if data is in long format with multiple species, then this can specify a particular species to extract if there is a column named "species".

type

specific type of unmarkedFrame.

...

further arguments to be passed to the unmarkedFrame constructor.

Details

This function provides a quick way to take a .csv file with headers named as described below and provides the data required and returns of data in the format required by the model-fitting functions in unmarked. The .csv file can be in one of 2 formats: long or wide. See the first 2 lines of the examples for what these formats look like.

The .csv file is formatted as follows:

  • col 1 is site labels.

  • if data is in long format, col 2 is date of observation.

  • next J columns are the observations (y) - counts or 0/1's.

  • next is a series of columns for the site variables (one column per variable). The column header is the variable name.

  • next is a series of columns for the observation-level variables. These are in sets of J columns for each variable, e.g., var1-1 var1-2 var1-3 var2-1 var2-2 var2-3, etc. The column header of the first variable in each group must indicate the variable name.

Value

an unmarkedFrame object

Author

Ian Fiske ianfiske@gmail.com

Examples

# examine a correctly formatted long .csv head(read.csv(system.file("csv","frog2001pcru.csv", package="unmarked")))
#> RouteNumStopNum JulianDate Pcru MinAfterSunset Wind Sky Temperature #> 1 211202.0 72 3 48 1 0 8.3 #> 2 211202.0 72 3 64 1 0 7.8 #> 3 211202.0 72 3 72 1 0 7.8 #> 4 211202.0 72 3 81 1 0 7.8 #> 5 211202.0 72 3 90 1 0 7.8 #> 6 211202.1 72 3 97 1 1 7.2
# examine a correctly formatted wide .csv head(read.csv(system.file("csv","widewt.csv", package="unmarked")))
#> site y.1 y.2 y.3 elev forest length date.1 date.2 #> 1 1 0 0 0 -1.1729446 -1.156228147 1.824549 -1.761481 0.3099471 #> 2 2 0 0 0 -1.1265010 -0.501483710 1.629241 -2.904339 -1.0471958 #> 3 3 0 0 0 -0.1976283 -0.101362109 1.458615 -1.690053 -0.4757672 #> 4 4 0 0 0 -0.1047411 0.007761963 1.686399 -2.190053 -0.6900529 #> 5 5 0 0 0 -1.0336137 -1.192602838 1.280934 -1.832910 0.1670899 #> 6 6 0 0 0 -0.8478392 0.917129237 1.808289 -2.618624 0.1670899 #> date.3 ivel.1 ivel.2 ivel.3 #> 1 1.3813757 -0.5060353 -0.5060353 -0.5060353 #> 2 0.5956614 -0.9336151 -0.9907486 -1.1621491 #> 3 1.4528042 -1.1355754 -1.3388644 -1.6099164 #> 4 1.2385185 -0.8193481 -0.9272669 -1.1970640 #> 5 1.3813757 0.6375563 0.8803737 1.0422520 #> 6 1.3813757 -1.3288666 -1.0422624 -0.8989603
# convert them! dat1 <- csvToUMF(system.file("csv","frog2001pcru.csv", package="unmarked"), long = TRUE, type = "unmarkedFrameOccu") dat2 <- csvToUMF(system.file("csv","frog2001pfer.csv", package="unmarked"), long = TRUE, type = "unmarkedFrameOccu") dat3 <- csvToUMF(system.file("csv","widewt.csv", package="unmarked"), long = FALSE, type = "unmarkedFrameOccu")