Error when plotting results

821 views
Skip to first unread message

E Kibuchi

unread,
Dec 11, 2013, 2:55:11 AM12/11/13
to r-inla-disc...@googlegroups.com
Hi,
I am getting the following error after plotting spde results,

formula <- (PfPR ~ -1 + Intercept + Long+ Lat + prec+ f(field, model = spde, group = field.group, control.group = list(model="ar1")))

result = inla(formula, data = inla.stack.data(stack, spde=spde),
              family = "binomial", Ntrials=Ntrials,
              control.predictor = list(A=inla.stack.A(stack),link = 1,
                                       compute=TRUE),control.compute=list(cpo=TRUE,dic=TRUE), 
              keep=FALSE, verbose=TRUE)
plot(result)
Error in plot.window(...) : need finite 'ylim' values

What could the problem? Thanks

INLA help

unread,
Dec 11, 2013, 6:36:09 AM12/11/13
to E Kibuchi, r-inla-disc...@googlegroups.com
On Tue, 2013-12-10 at 23:55 -0800, E Kibuchi wrote:

> What could the problem? Thanks

seems like something is infinity.


--
Håvard Rue
he...@r-inla.org

Mudassar Chanda

unread,
Dec 11, 2013, 6:40:40 AM12/11/13
to he...@r-inla.org, E Kibuchi, r-inla-disc...@googlegroups.com
Hi,

I had same problem when trying to compute DIC and cpo together. I think its worth trying to plot computing either of them to see if it works.

control.compute=list(dic=TRUE)

with regards

Mudassar



--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.
To post to this group, send an email to r-inla-disc...@googlegroups.com.
Visit this group at http://groups.google.com/group/r-inla-discussion-group.
For more options, visit https://groups.google.com/groups/opt_out.



--
Dr.Mudassar Chanda
D.Phil Student
Spatial Ecology & Epidemiology Group
Department of Zoology, University of Oxford
Tinbergen Building, South Parks Road, Oxford, OX1 3PS, UK

K.e

unread,
Dec 11, 2013, 7:04:39 AM12/11/13
to r-inla-disc...@googlegroups.com, he...@r-inla.org, E Kibuchi

Thanks

On Wednesday, 11 December 2013 14:40:40 UTC+3, Mudassar Chanda wrote:
Hi,

I had same problem when trying to compute DIC and cpo together. I think its worth trying to plot computing either of them to see if it works.

control.compute=list(dic=TRUE)

with regards

Mudassar
On Wed, Dec 11, 2013 at 11:36 AM, INLA help <he...@r-inla.org> wrote:
On Tue, 2013-12-10 at 23:55 -0800, E Kibuchi wrote:

> What could the problem? Thanks

seems like something is infinity.


--
Håvard Rue
he...@r-inla.org

--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion-group+unsub...@googlegroups.com.

To post to this group, send an email to r-inla-disc...@googlegroups.com.
Visit this group at http://groups.google.com/group/r-inla-discussion-group.
For more options, visit https://groups.google.com/groups/opt_out.

K.e

unread,
Dec 12, 2013, 2:51:48 AM12/12/13
to r-inla-disc...@googlegroups.com


Hi,
I can now successfully plot results after using only dic in compute.control. Thanks to Mudassar chanda.
 But I have now encounteredec another problem when trying to plot a levelplot for the predicted posterior mean as shown in the following code:
print(levelplot(x=pred_mean1,
 row.values=proj_grid$x,column.values=proj_grid$y,
 col.regions<-tim.colors(64),
 ylim=c(-17.062565,-4.845903),xlim=c(14.7208,27.2958),
 aspect="iso",
 xlab="Easting",ylab="Northing"))
Warning messages:
1: In levelplot.matrix(x = pred_mean1, row.values = proj_grid$x, column.values = proj_grid$y,  :
  explicit 'data' specification ignored
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
Error in print(levelplot(x = pred_mean1, row.values = proj_grid$x, column.values = proj_grid$y,  : 
  error in evaluating the argument 'x' in selecting a method for function 'print': Error in seq.default(zrng[1], zrng[2], length.out = cuts + 2) : 
  'from' cannot be NA, NaN or infinite
What could be causing the error.
My original data has 196 clusters, 301 rows and the data with filled missing values has 10388 (number of years is 53). What could be the problem please?

Finn Lindgren

unread,
Dec 12, 2013, 3:20:54 AM12/12/13
to K.e, r-inla-disc...@googlegroups.com
It seems to have trouble calculating the default colourscale limits.
What does

summary(pred_mean1)

tell you?
levelplot handles "NA" without problem, but not "Inf".

Finn L
> --
> You received this message because you are subscribed to the Google Groups
> "R-inla discussion group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to r-inla-discussion...@googlegroups.com.
> To post to this group, send an email to
> r-inla-disc...@googlegroups.com.
> Visit this group at http://groups.google.com/group/r-inla-discussion-group.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Finn Lindgren
email: finn.l...@gmail.com

K.e

unread,
Dec 12, 2013, 3:51:50 AM12/12/13
to r-inla-disc...@googlegroups.com
Hi Finn,

Its not giving any error. Its giving the following output (a subset of one row)
min      NA
1st QU. NA
Median NA
Mean NAN
3rd QU. NA
Max NA

Could the mean be the one causing the problem because its NAN

Finn Lindgren

unread,
Dec 12, 2013, 3:58:53 AM12/12/13
to r-inla-disc...@googlegroups.com, eliudkibuchi@gmail.com >> "K.e"
Try

summary(as.vector(...))

instead. For example:

> summary(c(1,2,NA,NaN))
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
1.00 1.25 1.50 1.50 1.75 2.00 2

so that should show you if there are any _non_-NA/NaN in the variable.
If there are no regular values in it, it can't be plotted,
and you'll need to go back to the model&inla call to see why that happens.

Finn

K.e

unread,
Dec 12, 2013, 4:04:28 AM12/12/13
to r-inla-disc...@googlegroups.com
Hi Finn,
I am getting the following output,

Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
     NA      NA      NA     NaN      NA      NA 2219659 


On Wednesday, 11 December 2013 10:55:11 UTC+3, K.e wrote:

Finn Lindgren

unread,
Dec 12, 2013, 4:06:39 AM12/12/13
to K.e, r-inla-disc...@googlegroups.com
On 12/12/13 09:04, K.e wrote:
> Hi Finn,
> I am getting the following output,
>
> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
> NA NA NA NaN NA NA 2219659

That's what I suspected.
Did the verbose INLA output give any warnings?
Otherwise it's likely that the problem is where you calculate "pred_mean1".

Finn

>
>
>
> On Wednesday, 11 December 2013 10:55:11 UTC+3, K.e wrote:
>
> Hi,
> I am getting the following error after plotting spde results,
>
> formula <- (PfPR ~ -1 + Intercept + Long+ Lat + prec+ f(field, model
> = spde, group = field.group, control.group = list(model="ar1")))
>
> result = inla(formula, data = inla.stack.data(stack, spde=spde),
> family = "binomial", Ntrials=Ntrials,
> control.predictor = list(A=inla.stack.A(stack),link = 1,
> compute=TRUE),control.compute=list(cpo=TRUE,dic=TRUE),
> keep=FALSE, verbose=TRUE)
> plot(result)
>
> Error in plot.window(...) : need finite 'ylim' values
>
>
> What could the problem? Thanks
>

K.e

unread,
Dec 12, 2013, 4:15:47 AM12/12/13
to r-inla-disc...@googlegroups.com, K.e

I am not getting any error from the SPDE model output and when I check my pred_mean computation its ok

Finn Lindgren

unread,
Dec 12, 2013, 4:30:22 AM12/12/13
to K.e, r-inla-disc...@googlegroups.com
On 12/12/13 09:15, K.e wrote:
>
> I am not getting any error from the SPDE model output and when I check
> my pred_mean computation its ok

But if it generates only NA and NaN, something is not right.
Is the input to the calculations non-NA/NaN?
How do you do the calculation?
(also, I'm guessing it's just a typo, but above you wrote "pred_mean"
and below you wrote "pred_mean1" )

Finn
> > an email to r-inla-discussion...@googlegroups.com
> <javascript:>.
> > To post to this group, send an email to
> > r-inla-disc...@googlegroups.com <javascript:>.
> <http://groups.google.com/group/r-inla-discussion-group>.
> > For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "R-inla discussion group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to r-inla-discussion...@googlegroups.com.

Eliud Kibuchi

unread,
Dec 12, 2013, 5:29:21 AM12/12/13
to Finn Lindgren, r-inla-disc...@googlegroups.com
Finn,
Let me recompute the code and see if the spatial prediction maps will
be ok.Thanks for help.

Mudassar Chanda

unread,
Dec 12, 2013, 6:51:01 AM12/12/13
to Eliud Kibuchi, Finn Lindgren, r-inla-disc...@googlegroups.com
Hi there,

It depends how you calculated your pred_mean1 as you said your model is fine. while calculating mean, median etc for your variable the default is na.rm=FALSE and if your orginal model mean has any NA, then if you  try to calculate mean (pred_mean1) from your model then it will return as all NA and even your summary will have all NA. I think the best way to do find NA in your model and try to calcualte mean using the  function  na.rm= TRUE. 
for example  mean(X, na.rm= TRUE).


I may be wrong but its worth trying and I am sorry if I you have already tried this.

with regards

Mudassar

Reply all
Reply to author
Forward
0 new messages