I'm a researcher working in the R package WARN by Tsutaya (2013). I've gotten it to work fine using the example dataset, but when using my own data I think the code gets stuck in a loop.
library(WARN)
warn(age = nonadult$age,
d15N = nonadult$d15N,
female.mean = mean(female$d15N),
female.sd = NA,
fraction = "collagen",
prior = c(0.5, 3, 3, 3, 1.9, 0.9, female.mean, 3, 0, 1),
num.particle = 10000,
form = "parabolic",
tolerances = c(2.0, 1.0, 0.5, 0.25, 0.125, 0.0625, 0))
I just get this in the console:
Remains: 7
Sometimes if I wait, the number ticks down but never gets to 0. Sometimes the number is lower, but usually it's 7. I have to force-quit using the stop button and then try tweaking things.
I think it has to do with the female.mean argument. I tried just giving a single number, female.mean = 9.87, but it didn't like that.
Is it just taking forever to run the code? When I use the example dataset it runs instantly. For this, I can walk away, get a drink, come back and it's still counting down, or seems to be stuck at 1. My dataset is larger than the example dataset... but still.
Any help is much appreciated!
Related
I am trying to plot four separate functions on the same graph using the curve() function in r. I came up with the following code:
for (n in 1:4){
curve(n*sin(x), -5, 5, add = TRUE)
}
Unfortunately, when I try that, the resulting plot is extremely zoomed in on one arbitrary point of the graph (axes labels nor graph borders can be seen either). Just to clarify, there is no resulting error message in the console at all, the plot is just very zoomed in.
Instead of plotting them in a for loop, I tried plotting them separately to see if it would work and it did. I used:
curve(4*sin(x), -5, 5)
curve(3*sin(x), -5, 5, add = TRUE)
curve(2*sin(x), -5, 5, add = TRUE)
curve(1*sin(x), -5, 5, add = TRUE)
I had also thought that it could be that I used curve() in a for loop; however, it has worked for this code (demonstrating that the function doesn't seem to care whether I use it in a loop-type function):
for (n in 0:5){
curve(x^n, -3, 3, add = TRUE)
}
Besides trying out different code, I have closed my graphics device, turned it off with dev.off(), restarted RStudio, but none of it has worked.
If I were only using a sequence from 1 to 4, like I mentioned above, I wouldn't care about typing them separately; however, I plan on using a much larger range of sequences in the future (like 1:50 or 1:100 for example).
I'm using RStudio version 3.4.4 with macOS 10.14.2 if that matters.
I'm fairly new to R-programming and have been struggling to understand how certain objects seem to pass variables to functions, but don't seem to return these variables overtly. Have a look at this example:
install.packages("cluster")
library(cluster)
x <- rbind(cbind(rnorm(10, 0, 0.5), rnorm(10, 0, 0.5)),
cbind(rnorm(15, 5, 0.5), rnorm(15, 5, 0.5)),
cbind(rnorm( 3,3.2,0.5), rnorm( 3,3.2,0.5)))
fannyx <- cluster::fanny(x, 2)
p <- cluster::clusplot(fannyx)
When examining the plot, the following information is provided:
These two components explain 100 % of the point variability
I simply don't understand where how this information is passed! The variability explained is not returned by the fannyx-object.
I've encountered this issue before when other functions have provided more information by summary() than by using print().
How can this be explained?
If we expand the clusplot function
cluster:::clusplot.default
We can see the line of code:
sub = paste("These two components explain",
round(100 * var.dec, digits = 2), "% of the point variability.")
So in this case this particular metric is calculated internally within the function, and then added to the plot.
Edit:
And we can see that cluster:::mkCheckX returns var.dec, which is called in clusplot
This question already has answers here:
Why are these numbers not equal?
(6 answers)
Closed 5 years ago.
I am attempting to use seq() to define my breaks on a plot. Dummy example below.
ggplot(data, aes(x=cat, y=dog) +
scale_y_continuous(breaks=seq(-0.3, 0.3, by=0.1))
For some reason, seq() is giving me output numbers that are off by minute amounts. This behavior occurs within and outside of my plotting device. As evidenced below, it appears to be a problem with generating negative numbers. It can produce them, but that's where the issue appears.
seq(0.3, 0.9, by=0.1) # test with positives
seq(-0.3, 0.3, by = 0.1) # test with negatives
format(seq(-0.3, 0.3, by = 0.1), scientific = F) # show full number
I read the documentation and couldn't find anything talking about negatives so I'm not sure how to fix it. Is there something I'm doing wrong or excluding? Is there a workaround or another function I should be using?
edit
Marked as duplicate but the duplicate doesn't explicitly provide a solution to this. Here's a few:
# i went with this solution as given in comments to keep it all contained within seq()
seq(-0.3, 0.3, length.out=7)
# from the answers
seq(-3, 3, by=1)/10
# didn't work for my case but should work as a general rule
round(x, digits=n) # x would be the seq(-0.3, 0.3, by = 0.1) and n=1 in my case)
For a workaround you could try seq(-3,3,1)/10
This question already has an answer here:
forceNetwork is not zero indexed
(1 answer)
Closed 5 years ago.
I am trying to make an interactive website traffic diagram using web traffic data.
Using networkd3 packages.
It is just a simpleNetwork, however keeps giving me this warning and force closes RStudio.
library(networkD3)
simpleNetwork(data.frame(BWT2012$Visitors, 1:189157, fontSize = 16, nodeColour = "blue", nodeClickColour = "red", textColour = "black", opacity = 0.6, zoom = T))
Warning Message: It looks like Source/Target is not zero-indexed. This
is required in Javascript and so your plot may not render.
I have been researching for hours however cannot seem to find how this works. I understand that javascript reads from 0 and r from 1. That is why it is not working.
it is very difficult for anyone to help you because you haven't provided a reproducible example, i.e. we have no idea what your data frame BWT2012 looks like
there seems to be a bug in your code... data.frame(BWT2012$Visitors, 1:189157, fontSize = 16, nodeColour = "blue", nodeClickColour = "red", textColour = "black", opacity = 0.6, zoom = T) will not work no matter what BWT2012 looks like because you're passing elements to the data.frame function that are of different lengths. I suspect you meant for it to be simpleNetwork(data.frame(BWT2012$Visitors, 1:189157), fontSize = 16, nodeColour = "blue", nodeClickColour = "red", textColour = "black", opacity = 0.6, zoom = T), where the first argument of the simpleNetwork() function is a complete data.frame() with BWT2012$Visitors as its first argument and 1:189157 as its second argument, i.e. you intend to pass to the simpleNetwork() function a data frame that has the first column/variable equal to BWT2012$Visitors and the second column equal to 1:189157
Assuming #2 above is correct, the data frame you are trying to pass is telling simpleNetwork that the values in BWT2012$Visitors are the sources of each link, and the values in 1:189157 are the targets of each link. That seems like a very unlikely scenario, so I would make sure you're getting what you think you're getting.
The warning you mention is just a warning... it will not stop the function from running. In many (maybe all since recent changes in networkd3) cases it will still plot the graph, though the results might be unexpected. For instance...
Source <- c(1, 1, 2)
Target <- c(2, 3, 3)
NetworkData <- data.frame(Source, Target)
simpleNetwork(NetworkData)
Using the example from #4, if you wanted to renumber your source and target ids so that they were 0-indexed and avoid the warning, you could do...
Source <- c(1, 1, 2)
Target <- c(2, 3, 3)
Source <- Source - 1
Target <- Target - 1
NetworkData <- data.frame(Source, Target)
simpleNetwork(NetworkData)
This is a question about an error in R's package BayesFactors.
When I tried the code generated in this example, I can use ttestBF fine.
However, when I tried running ttestBF on my data I got the following error:
Error in is.infinite(c(x, y)) :
default method not implemented for type 'list'
I also get that error if I create very simple data like this:
why <- data.frame(sensitivity = c(5, 6, 7, 7, 8, 9), perspective = c(1, 1, 1, 0, 0, 0))
ttestBF(sensitivity ~ perspective, data = why)
t.test(sensitivity ~ perspective, data = why)
The t.test works fine. I imagine it is a very simple issue, but I can't figure this out, and I guess others might face similar issues.
I eventually got the answer from the relevant github Issues thread.
BayesFactor::ttestBF(formula=sensitivity ~ perspective, data = why)