Plotting df Model with Two Covariables

17 views
Skip to first unread message

juan pablo Zurano

unread,
May 24, 2024, 8:46:49 AMMay 24
to distance-sampling

Hi folks,

I have some problems plotting a distance model with two covariables.

My model is:

hr.size.amb <- ds(df_dist, key="hr", convert_units=conversion.factor, transect="line",  formula=~ size + amb)

`size` and `amb` are categorical variables with two and three levels, respectively.

After plotting the model like this:

 plot(size.amb, breaks=cutpoints, showpoints=TRUE)

  I would like to add level to level of the covariable size using:

add.df.covar.line(hr.size.amb, data=data.frame(size="small"), lwd=3, lty=1, col="#a50026")  

  I get the following error message:

Error in eval_with_covars(xx, data[i, ], df, pdf) : columns in `newdata` do not match those in fitted model

Could someone please help me with a simple example to make a plot with two covariables in the model?

Thanks so much, Juan


Eric Rexstad

unread,
May 24, 2024, 8:54:55 AMMay 24
to juan pablo Zurano, distance-sampling
Juan

Welcome to the list.

Because you have two covariates in your detection function model (`size` and amb​), you will likewise need values for both covariates in the data frame you are passing to add_df_covar_line​.  I don't know what value of amb​ you would like to examine, but here is a possibility

add_df_covar_line(hr.size.amb, data=data.frame(size="small", amb=mean(df_dist$amb, na.rm=TRUE)), lwd=3, lty=1, col="#a50026")  

This will show the shape of the fitted detection function when size​ is small and amb​ is the mean of the values of amb​ in your data set.

Alternatively, you could simply set the value of amb​ in your new data set to a value of interest to you.

From: distance...@googlegroups.com <distance...@googlegroups.com> on behalf of juan pablo Zurano <zura...@gmail.com>
Sent: 24 May 2024 13:06
To: distance-sampling <distance...@googlegroups.com>
Subject: [distance-sampling] Plotting df Model with Two Covariables
 
--
You received this message because you are subscribed to the Google Groups "distance-sampling" group.
To unsubscribe from this group and stop receiving emails from it, send an email to distance-sampl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/distance-sampling/b023c883-c01b-4e2c-8c3c-0096a29daba3n%40googlegroups.com.

juan pablo Zurano

unread,
May 24, 2024, 9:41:11 AMMay 24
to Eric Rexstad, distance-sampling
Dear Eric

Thank you very much for your answer. I have created a plot using both covariates as follows:  

plot(hr.size.amb, showpoints=T)

add_df_covar_line(hr.size.amb, data=data.frame(size="small", 
                                                                                   amb="grassland"), 
                                 lwd=3, lty=1, col="#bd0026")


Regards Juan
--

Juan Pablo Zurano

Instituto de Biología Subtropical (IBS, CONICET-UNaM), Nodo Iguazú

Av. Tres Fronteras 183 (3370) Puerto Iguazú, Misiones, Argentina.

Telefono: +54 3757 42-3289 Celular: +54 3764 15 879558, 

www.ibs-conicet.gob.ar


Reply all
Reply to author
Forward
0 new messages