andrewcparnell / simmr

A stable isotope mixing model in R
https://andrewcparnell.github.io/simmr/
28 stars 8 forks source link

problem with summary() for simmr_out object #22

Closed nathanmct closed 4 years ago

nathanmct commented 4 years ago

Hi Andrew,

First, thanks for all the work you put into this package. I'm running 0.4.1, which is the most recent I could get from CRAN, and came across errors while re-running some scripts that worked about a year ago. When attempting to view the convergence statistics, this error is thrown:

summary(susp_out, type = "diagnostics") Summary for 1 Error in apply(out_all, 2, "quantile", probs = c(0.025, 0.25, 0.5, 0.75, : dim(X) must have a positive length

The creation of the simmr_out object susp_out = simmr_mcmc(simmr_groups_susp) appears to work correctly and the list object looks normal upon basic inspection.

From here onward, there are errors thrown for every call of the susp_out object.

posterior_predictive(susp_out) Error in simmr_out$output[[group]]$model$model() : attempt to apply non-function

summary(susp_out, type='quantiles', group_num=1) Summary for 1 Error in apply(out_all, 2, "quantile", probs = c(0.025, 0.25, 0.5, 0.75, : dim(X) must have a positive length

susp.summ <- summary.simmr_output(susp_out, type=c("quantiles"), group=c(1:max(susp$Code))) Error in summary.simmr_output(susp_out, type = c("quantiles"), group = c(1:max(susp$Code))) : could not find function "summary.simmr_output"

Any ideas why the summary calls don't work? THANK YOU so much for you help. Let me know if you would like a reproducible example.

Best regards, Nathan

andrewcparnell commented 4 years ago

Hi Nathan,

Thanks for the message. I cannot re-create this error. Would you be able to create a reproducible example and post the code here?

Andrew

nathanmct commented 4 years ago

Hi Andrew,

I've pasted the example code below. I also attached a script and csv files if you want to run it yourself. Hopefully I'm overlooking something obvious. I'm a bit miffed since this was working code about a year ago. Thanks for your help!

Nathan

############################# library(rjags) library(simmr)

setwd("") susp <- read.csv("susp_for_simmr.csv", header = TRUE) corrections <- read.csv("corrections.csv") sources <- read.csv("source.averages.csv",header=T)

mix.susp <- as.matrix.data.frame(susp[,c(6:5)], ncol=2, nrow=length(susp$d13C)) #in this df d13C is the 6th column, and d15N is the 5th

s_names <- levels(sources$Source) s_means <- as.matrix.data.frame(sources[,c(2,4)], ncol=2, nrow=length(sources$Source)) s_sds <- as.matrix.data.frame(sources[,c(3,5)], ncol=2, nrow=length(sources$Source))

c_means <- as.matrix.data.frame(corrections[,c(2,4)], ncol=2, nrow=length(sources$Source)) c_sds <- as.matrix.data.frame(corrections[,c(3,5)], ncol=2, nrow=length(sources$Source))

grp.susp <- as.integer(as.matrix(susp$Code))

simmr_groups_susp <- simmr_load(mixtures=mix.susp, source_names=s_names, source_means=s_means, source_sds=s_sds, correction_means=c_means, correction_sds=c_sds, group=grp.susp) #this appears to work correctly

plot(simmr_groups_susp) #produces a tracers plot

source("simmrmcmc.r") susp_out = simmr_mcmc(simmr_groups_susp) #appears to work correctly

from here on out, these throw an error for me. Erros were copied from

console and are listed below.

plot(susp_out, type = 'convergence')

Error in match.arg(type, several.ok = TRUE) :

'arg' should be one of “isospace”, “histogram”, “density”, “matrix”,

“boxplot”

summary(susp_out, type = "diagnostics")

Error in apply(out_all, 2, "quantile", probs = c(0.025, 0.25, 0.5, 0.75,

:

dim(X) must have a positive length

posterior_predictive(susp_out)

Error in simmr_out$output[[group]]$model$model() :

attempt to apply non-function

summary(susp_out, type='quantiles', group_num=1)

Error in apply(out_all, 2, "quantile", probs = c(0.025, 0.25, 0.5, 0.75,

:

dim(X) must have a positive length

plot(susp_out, type='matrix', group=1:max(grp.susp))

Error in colnames<-(*tmp*, value = x$input$source_names) :

attempt to set 'colnames' on an object with less than two dimensions

susp.summ <- summary.simmr_output(susp_out, type=c("quantiles"), group=c(1:max(susp$Code)))

Error in summary.simmr_output(susp_out, type = c("quantiles"), group =

c(1:max(susp$Code))) :

could not find function "summary.simmr_output

On Thu, Jun 11, 2020 at 5:12 AM Andrew Parnell notifications@github.com wrote:

Hi Nathan,

Thanks for the message. I cannot re-create this error. Would you be able to create a reproducible example and post the code here?

Andrew

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/andrewcparnell/simmr/issues/22#issuecomment-642638261, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD2CTMP2PYB2WBHDZEQZ2Q3RWDJZFANCNFSM4NMYFQEQ .

andrewcparnell commented 4 years ago

Thanks Nathan,

I didn't know you could attach files to these messages - I can't see them above.

One weird thing that pops out to me from your code is your use of a new MCMC function in source("simmrmcmc.r"). Have you tried running it without this? The simmr_mcmc function is already in simmr so you shouldn't need another unless you're doing something specific.

Andrew

nathanmct commented 4 years ago

Hi Andrew,

Hmmm... that function was the problem. Was that part of an earlier version of simmr perhaps? I don't even remember where that came from. Regardless, the simmr_mcmc function works perfectly. For some reason I was using an old(?) function summary.simmr_output() to obtain the quantiles, but plain summary() obtains the values fine.

After running through the rest of my code, I noticed that summary(mix_out, type=c("quantiles"), group=c(1:max(mix$Code))) now produces a list where the first row of the quantiles is "deviance". What is that measuring?

Thanks for the help! I'm glad it was something very simple afterall. It looks like you are preparing to release a new version of simmr? Will it be backwards compatible with the current version? Looking forward to seeing it.

Cheers, Nathan

On Fri, Jun 12, 2020 at 12:56 AM Andrew Parnell notifications@github.com wrote:

Thanks Nathan,

I didn't know you could attach files to these messages - I can't see them above.

One weird thing that pops out to me from your code is your use of a new MCMC function in source("simmrmcmc.r"). Have you tried running it without this? The simmr_mcmc function is already in simmr so you shouldn't need another unless you're doing something specific.

Andrew

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/andrewcparnell/simmr/issues/22#issuecomment-643158905, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD2CTMN6IEOK4JKB7QMAH6LRWHUT3ANCNFSM4NMYFQEQ .

andrewcparnell commented 4 years ago

Not sure about that simmr_mcmc is the main function in simmr and has always been there. Occasionally I write new versions of it for different types of bespoke analysis for people - perhaps you got your code from someone else?

Deviance is a measure of model fit (strictly speaking it's minus twice the log likelihood) but you can pretty much ignore that. JAGS includes it by default for comparing between difference models.