-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors from the posterior approximation graphs #17
Comments
Try directly assigning |
So when I directly assigned Warning: Error in plot.xy: plot.new has not been called yet
Stack trace (innermost first):
63: plot.xy
62: lines.default
61: lines
60: FUN [/home/fabusard/git/KaphiShiny/app.R#525]
59: lapply
58: FUN [/home/fabusard/git/KaphiShiny/app.R#523]
57: lapply
56: observerFunc
1: runApp This is happening because In 2371673 I commented out everything after |
@gtng92 found a bug/mistake in my approach to plotting the lines on the posterior approximation graph, and help me fix it. This issue is still unsolved but solving that bug is a step in the right direction. The nested lapply and for loop used the same variable to iterate (it was i). Now I changed it such that the lapply uses i and the for loop uses j: observe(
lapply(seq_len(length(modelParameters)), function(i) {
pal = rainbow(n=6, start=0, end=0.5, v=1, s=1)
output[[paste0("posteriorApproximationsOf", modelParameters[[i]])]] <- renderPlot(
for (j in 1:5) {
temp <- trace[trace$n==j*10,]
lines(density(temp[[modelParameters[[i]]]], weights=temp$weight), col=pal[j+1], lwd=1.5)
}
)
}),
priority = 97
) |
I am still working on update the plot with out re-rending it in shiny. I tried plotting using the approach outline in this stackoverflow thread, but that didin't work. I just got white space with no plot. code used: observe(
lapply(seq_len(length(modelParameters)), function(i) {
pal = rainbow(n=6, start=0, end=0.5, v=1, s=1)
output[[paste0("posteriorApproximationsOf", modelParameters[[i]])]] <- renderPlot(function() {
plot.new()
plot.window(xlim=c(0, 3), ylim=c(0, 20))
axis(1)
axis(2)
title(main=paste0(input$specificModel, " ", modelParameters[[i]]))
title(xlab=paste0(input$specificModel, ' rate parameter (', modelParameters[[i]], ')'))
title(ylab="Density")
box()
lines(density(trace[[modelParameters[[i]]]][trace$n==1], weights=trace$weight[trace$n==1]))
for (j in 1:5) {
temp <- trace[trace$n==j*10,]
lines(density(temp[[modelParameters[[i]]]], weights=temp$weight), col=pal[j+1], lwd=1.5)
}
lines(density(trace[[modelParameters[[i]]]][trace$n==max(trace$n)], weights=trace$weight[trace$n==max(trace$n)]), col='black', lwd=2)
})
})
) Note that this approach works when implemented in an R script. |
I tried plotting points instead of densities but that also returned white space instead of the plot. here is the code snippet I used: observe(
lapply(seq_len(length(modelParameters)), function(i) {
pal = rainbow(n=6, start=0, end=0.5, v=1, s=1)
output[[paste0("posteriorApproximationsOf", modelParameters[[i]])]] <- renderPlot(function() {
plot.new()
plot.window(xlim=c(0, 3), ylim=c(0, 20))
axis(1)
axis(2)
title(main=paste0(input$specificModel, " ", modelParameters[[i]]))
title(xlab=paste0(input$specificModel, ' rate parameter (', modelParameters[[i]], ')'))
title(ylab="Density")
box()
points(1,1)
points(2,2)
points(3,3)
})
})
) |
I used However, |
When trying to use Warning in density.default(temp[[modelParameters[[i]]]], weights = temp$weight) :
sum(weights) != 1 -- will not get true density
Warning: Error in density.default: need at least 2 points to select a bandwidth automatically
Stack trace (innermost first):
102: density.default
101: density
100: lines
99: renderPlot [/home/fabusard/git/KaphiShiny/app.R#452]
89: <reactive:plotObj>
78: plotObj
77: origRenderFunc
76: output$posteriorApproximationsOflambda
1: runApp as of commit 0b5297b, i am using |
Error in density.default: need at least 2 points to select a bandwidth automatically This code is specifically tailored to the SMC simulation of the Yule model in Originally the code was: for (i in 1:7) {
temp <- trace[trace$n==i*10,]
lines(density(temp[[param]], weights=temp$weight), col=pal[i+1], lwd=1.5)
} This code will run assuming that there will be at least While looking at results from run in for (i in 1: ( length(unique(trace$n)) %/% 10 ) ) {
temp <- trace[trace$n==i*10,]
lines(density(temp[[param]], weights=temp$weight), col=pal[i+1], lwd=1.5)
} Hopefully this helps! |
Thanks @gtng92, I will incorporate your changes in KaphiShiny, test, and push when completed! |
Also when you show the prior distribution, there's another section that needs to be generalized. Originally it was: # show the prior distribution
x <- seq(0, 2, 0.1) # again, specifically for param lambda in Yule model)
y <- function(x) {arg.prior <- x; eval(parse(text=config$prior.densities[[param]]))}
lines(x, y(x), lty=5) In # show the prior distribution
x <- sort( replicate(1000, eval(parse(text=config$priors[[param]]))) )
y <- function(x) {arg.prior <- x; eval(parse(text=config$prior.densities[[param]]))}
lines(x, y(x), lty=5) |
Thanks again, I will incorporate this ASAP |
I am getting this error when trying to generate posterior approximation graphs:
I am using the following code (it is commented out in the master branch as the above error breaks the app):
The text was updated successfully, but these errors were encountered: