R2ucare error in R

questions concerning analysis/theory using programs M-SURGE, E-SURGE and U-CARE

R2ucare error in R

Postby statsfordays » Sat Oct 31, 2020 1:56 pm

Hi all,

I am attempting to assess the goodness of fit of CJS to my dataset using R2ucare. However, I am receiving the error: "Error in rep(NA,K-2):invalid 'times' argument". This occurs when I'm trying to define the function: mydata.ucare.cjs=overall_CJS(mydata)

My dataset is very simple--just a binary ch where each row is an individual, each column is a primary sampling occasion, 1 for observed, 0 for unobserved. I've gone through my dataset and see no abnormalities in the file I have imported to R and I don't receive any errors while running CJS or other models in RMark.

I'm sure there must be a simple solution that I am overlooking here. Can someone please offer me some insight?
statsfordays
 
Posts: 6
Joined: Sun Nov 17, 2019 11:00 am

Re: R2ucare error in R

Postby simone77 » Sun Nov 01, 2020 2:09 pm

My guess is that it has to do with the test3sr() function that is called by overall_CJS(). If you have a look at test3sr (e.g. just by writing it down in your R console), you'll see this:

Code: Select all
function (X, freq, verbose = TRUE, rounding = 3)
{
    n = dim(X)[1]
    K = dim(X)[2]
    result = data.frame(component = rep(NA, K - 2), stat = rep(NA,
        K - 2), p_val = rep(NA, K - 2), signed_test = rep(NA,
        K - 2), test_perf = rep(FALSE, K - 2))
...


So, it is creating a data frame with component, stat, p_val, signed_test, and test_perf as columns.

K is the number of columns of X, i.e. of your dataframe. Something seems to go wrong with that, isn't it? I would try to digit dim(mydata)[2] and see if you get a hint...
Please let us know if you find what the error was.

Simone
simone77
 
Posts: 176
Joined: Mon Aug 10, 2009 2:52 pm

Re: R2ucare error in R

Postby statsfordays » Tue Nov 03, 2020 10:47 am

Hi Simone,

First, thanks for your input.

Second, I'm now wondering if there is a problem with how my data is formatted. When I ran dim(mydata)[2] it came back with "1," leading me to believe that its reading my 14 columns of ch as one large column.

Forgive my ignorance, but I'm teaching myself R. If I'm way off base--please let me know. I'm not sure where to go from here. I've tried following Gimenez's dipper data example but the fact that it's a built in dataset throws me off while I'm importing my own data from a .txt file.
statsfordays
 
Posts: 6
Joined: Sun Nov 17, 2019 11:00 am

Re: R2ucare error in R

Postby cooch » Tue Nov 03, 2020 11:09 am

The dipper data are 'in the public domain' (such that they now represent the single most anayzed data set on the planet), so you could attempt to create your own input file, to test if you're doing it correctly, by trying to replicate Olivier's result.
cooch
 
Posts: 1494
Joined: Thu May 15, 2003 4:11 pm
Location: Cornell University

Re: R2ucare error in R

Postby simone77 » Tue Nov 03, 2020 11:22 am

OK, so you get that error message when you do overall cjs(mydata) because it can not perform rep(NA, K-2). If you try to run rep(NA, -1) in R, you will see the same error message ('times' is actually the rep() function's second argument, and it must be a positive integer).

Second, I'm now wondering if there is a problem with how my data is formatted. When I ran dim(mydata)[2] it came back with "1," leading me to believe that its reading my 14 columns of ch as one large column.

Correct.

There must be an error in either the syntax you are using or the way your dataset is formatted. I'll be happy to try to help you if you can provide some details about them. Some important details are: the extension (* .txt? * .inp?) of the file that you are importing in R, what your dataset looks like in your file (could you paste the first lines here?), and the syntax that you are using in R to import the data.
simone77
 
Posts: 176
Joined: Mon Aug 10, 2009 2:52 pm

Re: R2ucare error in R

Postby statsfordays » Tue Nov 03, 2020 6:18 pm

simone77 wrote:There must be an error in either the syntax you are using or the way your dataset is formatted. I'll be happy to try to help you if you can provide some details about them. Some important details are: the extension (* .txt? * .inp?) of the file that you are importing in R, what your dataset looks like in your file (could you paste the first lines here?), and the syntax that you are using in R to import the data.


Sure, here are the first five lines that represent five individuals over 14 years:

11000000000000
11001000001000
10010000000000
10000000000000
10000000000000

The syntax I am using to import the data is most definitely the problem here. I normally would use import.chdata(), a function of RMark, to import my ch. However, I'm seeing that I'm supposed to be using read_inp(), or at least that's what the dipper example code shows. I know this is only for Mark formatted input files which does not apply to me, as I'm not using a .inp file. I am using a .txt file. Is there another way to import ch data to use with R2ucare that I'm missing? Anytime I use read.delim() it reads the file just fine, just not as ch. How do I get it to recognize the file as ch?

cooch wrote:The dipper data are 'in the public domain' (such that they now represent the single most anayzed data set on the planet), so you could attempt to create your own input file, to test if you're doing it correctly, by trying to replicate Olivier's result.


I will definitely be doing this once I can figure out how to read my own file into R2ucare. Thanks!

I really appreciate all the help y'all have to offer!
statsfordays
 
Posts: 6
Joined: Sun Nov 17, 2019 11:00 am

Re: R2ucare error in R

Postby simone77 » Wed Nov 04, 2020 7:54 am

Of course, the best you can do is study the help files of these functions in depth, but to get out of trouble, you can start by adding 1 ; at the end of each row. This means that you have a single grouping factor (or otherwise said, no separate groups) and an individual's encounter history on each row. Your data would look like that:

11000000000000 1 ;
11001000001000 1 ;
10010000000000 1 ;
10000000000000 1 ;
10000000000000 1 ;

Next, you can run the following code:

Code: Select all
mydatafile<- "the path where your *.inp file is stored in your machine (e.g. "C:/Users/statsfordays/Documents/mydata.inp")"
mydata<- read_inp(mydatafile)
mydataCJS_GOF<- overall_CJS(X = mydata$encounter_histories, freq = mydata$sample_size)
simone77
 
Posts: 176
Joined: Mon Aug 10, 2009 2:52 pm


Return to analysis help

Who is online

Users browsing this forum: No registered users and 1 guest