Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix: import reshape2 instead of reshape #17

Merged
merged 5 commits into from

3 participants

@jucor

This should solve issue #15 , hope this helps :)

@dmenne

No, that's no enough. You have to run the test, for example variable_name is variable.name in reshape2

@jucor

Great: so where are the unit tests that I can run? I can't find any.

@dmenne

Build the package which includes an example; there are no unit tests, but a full build/check for CRAN includes this.

@jucor

Thanks. Weird: I had compiled the package, but didn't see the test. I probably had a no-check flag somewhere, or didn't pay attention. Will get back to it.

@jucor

PS: I've asked on manipulatr mailing list for any info on broken backward compatibility between reshape and reshape2.

@dmenne

Instead wasting too many grey cells on the check-flags, use RStudio, create a package project, and Build/Check. I also suggest to explicitly check "roxygenize on Build and Reload", because that what one easily forgets.

The only other change is the _/. in melt.data.frame. But there is also the problem with Rhat and 1 chain, and the nasty histogram warnings.

@jucor

Thanks Dieter. Looks like there's also cast() which has been renamed acast/dcast depending on the use. The warnings do not worry me so much: they are ugly indeed, but apparently can be fixed.

jucor added some commits
@jucor jucor Replace cast() by dcast() from reshape2 4e76705
@jucor jucor Replace X1/X2 by Var1/Var2
reshape2's melt() names its columns Var1/Var2
while reshape used to name them X1/X2
6a991d0
@jucor

Fixed the _/., the cast(), and a naughty melt() issue, too. Now the check passes smoothly, and doesn't raise any histogram warnings. Could you please give me examples to reproduce:

  • the histogram warnings
  • the problem of Rhat with 1 chain ?

If you add them as standalone files and pull-request on my fork jucor/ggmcmc , I will turn them into unit tests and work from there. Thanks!

@dmenne

You should see the histogram-warning when compiling the standard example. It comes from ggs_histogram/geom_histogram. I suggest the following changes, but cannot get it to work since I do not know the syntax (code below fails in geom_histogram).
Feel free to check:
http://stackoverflow.com/questions/17271968/different-breaks-per-facet-in-ggplot2-histogram

breaks = tapply(D$value,D$Parameter,function(x){
pretty(range(x), n = nclass.FD(x), min.n = 1)
})
f <- ggplot(D, aes(x=value) ) +
geom_histogram(breaks=breaks) +
facet_wrap(~ Parameter, ncol=1, scales="free")
return(f)

@dmenne

When trying to reproduce the 1-chain problem, I encountered another one which I remember had to do with some coda-related problems; I had already solved that once, but don't remember the details. See Issue #18. Sorry, I have to leave, cannot work on this one currently.

@jucor

Thanks for your help Dieter! I'll fix what I can/need, and contact @xfim to see if he can pull.

@jucor

The problem with the multiple binwidths appears to be that breaks can only specify common breaks for all variables. There are a few workarounds, but the desagreement of the warning is small enough and the effort to high for me to push further :-) I suggest filling a separate issue.

@jucor

Bottom line: the port to reshape2 is done here. The Rhat with 1 chain is also a separate problem (that I'll be glad to look into, too), but at least this issue is ripe for merging. Emailing @xfim. Thanks for the input Dieter!

@xfim xfim merged commit 6a991d0 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 22, 2013
  1. @jucor
Commits on Jun 24, 2013
  1. @jucor

    Fix variable_name -> variable.name

    jucor authored
    Thanks Dieter Menne for pointing this out.
  2. @jucor

    Automatic reorder by Roxygen2

    jucor authored
  3. @jucor
  4. @jucor

    Replace X1/X2 by Var1/Var2

    jucor authored
    reshape2's melt() names its columns Var1/Var2
    while reshape used to name them X1/X2
This page is out of date. Refresh to see the latest.
View
2  DESCRIPTION
@@ -11,7 +11,7 @@ Maintainer: Xavier Fernández i Marín <xavier.fim@gmail.com>
Author: Xavier Fernández i Marín <xavier.fim@gmail.com>
Depends:
plyr,
- reshape,
+ reshape2,
ggplot2
Suggests:
foreach,
View
6 NAMESPACE
@@ -1,7 +1,5 @@
export(ac)
export(ggmcmc)
-export(ggs)
-export(ggs_Rhat)
export(ggs_autocorrelation)
export(ggs_caterpillar)
export(ggs_compare_partial)
@@ -9,9 +7,11 @@ export(ggs_crosscorrelation)
export(ggs_density)
export(ggs_geweke)
export(ggs_histogram)
+export(ggs_Rhat)
export(ggs_running)
export(ggs_traceplot)
+export(ggs)
export(sde0f)
import(ggplot2)
import(plyr)
-import(reshape)
+import(reshape2)
View
2  R/ggs.R
@@ -116,7 +116,7 @@ ggs_chain <- function(s) {
# Prepare the dataframe
d <- data.frame(Iteration=iter, as.matrix(unclass(s)))
- D <- melt(d, id.vars=c("Iteration"), variable_name="Parameter")
+ D <- melt(d, id.vars=c("Iteration"), variable.name="Parameter")
# Revert the name of the parameters to their original names
levels(D$Parameter) <- name.chains
View
4 R/ggs_caterpillar.R
@@ -58,7 +58,7 @@ ggs_caterpillar <- function(D, family=NA, X=NA,
dc <- ddply(D[[i]], .(Parameter), summarize,
q=quantile(value, probs=qs), qs=qs)
dc$qs <- factor(dc$qs, labels=names(qs))
- dcm <- cast(dc, Parameter ~ qs, value=.(q))
+ dcm <- dcast(dc, Parameter ~ qs, value=.(q))
D[[i]] <- dcm # replace list element with transformed list element
}
#
@@ -79,7 +79,7 @@ ggs_caterpillar <- function(D, family=NA, X=NA,
q=quantile(value, probs=qs), qs=qs,
.parallel=attributes(D)$parallel)
dc$qs <- factor(dc$qs, labels=names(qs))
- dcm <- as.data.frame(cast(dc, Parameter ~ qs, value=.(q)))
+ dcm <- as.data.frame(dcast(dc, Parameter ~ qs, value=.(q)))
}
#
View
10 R/ggs_crosscorrelation.R
@@ -18,15 +18,15 @@ ggs_crosscorrelation <- function(D, family=NA, absolute.scale=TRUE) {
if (attributes(D)$nParameters <= 1) {
stop("Can't calculate crosscorrelations with a single chain")
}
- X <- cast(D, Iteration + Chain ~ Parameter)
+ X <- dcast(D, Iteration + Chain ~ Parameter)
# Chain management is not easy
bc.cc <- melt(cor(as.matrix(X[,-c(1, 2)])))
# Need to revert parameter names
- bc.cc$X1 <- factor(bc.cc$X1, labels=levels(D$Parameter))
- bc.cc$X2 <- factor(bc.cc$X2, labels=levels(D$Parameter))
- bc.cc$value[bc.cc$X1==bc.cc$X2] <- NA
+ bc.cc$Var1 <- factor(bc.cc$Var1, labels=levels(D$Parameter))
+ bc.cc$Var2 <- factor(bc.cc$Var2, labels=levels(D$Parameter))
+ bc.cc$value[bc.cc$Var1==bc.cc$Var2] <- NA
# Plot
- f <- ggplot(bc.cc, aes(x=X1, y=X2)) +
+ f <- ggplot(bc.cc, aes(x=Var1, y=Var2)) +
geom_tile(aes(fill=value)) +
xlab("") + ylab("") + theme(axis.text.x=element_text(angle=90))
if (absolute.scale) {
View
6 R/ggs_geweke.R
@@ -41,9 +41,9 @@ ggs_geweke <- function(D, family=NA, frac1=0.1, frac2=0.5) {
.parallel=attributes(D)$parallel)
# Cast the dataframe in pieces to have the data arranged by parameter, chain
# and first and last
- M <- cast(D.geweke, Parameter + Chain ~ part, value=.(m))
- N <- cast(D.geweke, Parameter + Chain ~ part, value=.(n))
- SDE0F <- cast(D.geweke, Parameter + Chain ~ part, value=.(sde0f))
+ M <- dcast(D.geweke, Parameter + Chain ~ part, value=.(m))
+ N <- dcast(D.geweke, Parameter + Chain ~ part, value=.(n))
+ SDE0F <- dcast(D.geweke, Parameter + Chain ~ part, value=.(sde0f))
# Reorganize the z scores
Z <- data.frame(Parameter=M$Parameter, Chain=M$Chain,
z= (M$first - M$last) /
View
2  R/globals.R
@@ -8,7 +8,7 @@ if (base::getRversion() >= "2.15.1") {
"Lag", "Autocorrelation", # from ggs_autocorrelation
"thick.low", "thick.high", "thin.low", "thin.high", # from ggs_caterpillar
"part_chain", # for ggs_compare_partial
- "X1", "X2", # for ggs_crosscorrelation
+ "Var1", "Var2", # for ggs_crosscorrelation
"n", "z", "part", # for ggs_geweke
"m" # for ggs_geweke and ggs_running
))
View
2  R/help.R
@@ -7,7 +7,7 @@
#' results against observed variables.
#'
#' @references \url{http://xavier-fim.net/packages/ggmcmc}.
-#' @import plyr ggplot2 reshape
+#' @import plyr ggplot2 reshape2
#' @docType package
#' @name ggmcmc
#' @aliases ggmcmc ggmcmc-package
Something went wrong with that request. Please try again.