Page 1 of 1

Calculating quadratic time (TT)

PostPosted: Mon Aug 01, 2022 1:09 pm
by chasingbirds
Hi all,
I'm trying to calculate quadratic time for my nest survival analysis in rMark and I'm running into an issue. I am a self-learner, and am trying my best to read through all forums/workshops/resources, so please be patient with me.

I have run several models already with linear time, nest age, DSR, etc. and am trying to add in quadratic time. I followed one line of code from another paper, and tried this:
Code: Select all
nestdata$S$TT <- as.numeric (nest.ddl$Time)^2


Though it was successful, it added a column of code to my dataframe that looks like this:
    c(0, 1, 4, 9, 16, 25 ....)

For every row (i.e. individual nest) in my dataset. I know this is incorrect, but ran the model anyway to see what the output would be, and the error says "error in dataframe, arguments imply differing number of rows: 58, 62).... misspecification of model or internal error in code."

I know I'm likely missing some step that includes time in my dataframe, but I just can't make sense of how to add it in without needed some kind of time-related covariate. I'm happy to include an example of what y dataframe looks like if that seems helpful, but I didn't want to clog up this post any more. Any help/advice would be great, and again, I apologize if this information seems obvious--I'm learning as I go!

Thanks so much!

Re: Calculating quadratic time (TT)

PostPosted: Mon Aug 01, 2022 1:15 pm
by jhines
Should be:

nest.ddl$S$TT = as.numeric(nest.ddl$S$Time)^2

Another possibility, where you don't need to create that covariate is to use the formula:

S ~ Time + I(Time ^2)
or
S ~ poly(Time,2)

Re: Calculating quadratic time (TT)

PostPosted: Mon Aug 01, 2022 2:14 pm
by jlaake
Thanks Jim. You beat me to it. I would recommend using the first approach. I have run into issues using I() and poly.

Whenever you get a problem like this, pull apart the statement and examine the contents. For example has you typed

nest.ddl$Time

You would have seen that it is NULL - doesn't exist.

--jeff

Re: Calculating quadratic time (TT)

PostPosted: Mon Aug 01, 2022 2:26 pm
by jhines
Also, I suggest looking at the design-matrix produced to make sure if does what you think it does.

Re: Calculating quadratic time (TT)

PostPosted: Tue Aug 02, 2022 4:21 am
by B.K. Sandercock
It's possible to fit a quadratic model without modifying the design matrix but by specifying the quadratic term in the model statement based on the column for the linear trend of Time. Here's a snippet of code:

Code: Select all
# DSR follows a quadratic trend through time
TimeQuad=mark(nest,nocc=occ,model="Nest",
   model.parameters=list(S=list(formula=~Time + I(Time^2))))


Good luck with your models!