How do I plot the graph of `res ` for different `epsilon` in the same plot?

oliver

I want to plot function res for different value of epsilon=0.1, 0.2,0.3,0.9 in the same plot in R.

My setting is that

#make this example reproducible
set.seed(1001)
n <- 500
#Sample GOE random matrix
A <- matrix(rnorm(n*n, mean=0, sd=1), n, n) 
G <- (A + t(A))/sqrt(2*n)
ev <- eigen(G)
l <- ev$values
v <- ev$vectors

#size of multivariate distribution
mean <- rep(0, n) 
var <- diag(n)

#simulate bivariate normal distribution
initial <- MASS::mvrnorm(n=1000, mu=mean, Sigma=var) #ten random vectors
#normalized the first possible initial value, the initial data uniformly distributed on the sphere
xmats <- lapply(1:1000, function(i) initial[i, ]/norm(initial[i, ], type="2"))

#define my function
h1t <- function(t,x_0) {
  h10 <- c(x_0 %*% v[, n])
  denom <- vapply(t, function(.t) {
    sum((x_0 %*% v)^2 * exp(-4*(l - l[n]) * .t))
  }, numeric(1L))
  abs(h10) / sqrt(denom)
}

For 1000 initial value x_0 from normal distribution (I put them in a matrix xmats), I can plot all value of t so that h1t=epsilon for epsilon=0.9.

#set epsilon=0.9
find_t <- function(x, epsilon = 0.9, range = c(-500, 500)) {
  uniroot(function(t) h1t(t, x) - epsilon, range,
          tol = .Machine$double.eps)$root
}

res <- lapply(xmats, find_t)
plot(density(unlist(res)), xlim = c(0, 300),col = "red",
     main = "Fix epsilon=0.9. Density of tau_epsilon for different initial value for n=500")

I got:enter image description here

Question: How do I plot the graph of res for different epsilon in the same plot?

MarBlo

You can do this by applying your function to the parameter. I called the result find_t03 and call lines after the plot call with this new result.

I have added ylim to the plot and also added a break in the title.

#set epsilon=0.9
find_t <- function(x, epsilon = 0.9, range = c(-500, 500)) {
  uniroot(function(t) h1t(t, x) - epsilon, range,
          tol = .Machine$double.eps)$root
}
#set epsilon=0.3
find_t03 <- function(x, epsilon = 0.3, range = c(-500, 500)) {
  uniroot(function(t) h1t(t, x) - epsilon, range,
          tol = .Machine$double.eps)$root
}

res <- lapply(xmats, find_t)
res03 <- lapply(xmats, find_t03)

plot(density(unlist(res)), xlim = c(0, 200),
     ylim=c(0, 0.2),col = "red",
     main = paste0("Fix epsilon=0.9 (red) and 0.3 (black).",
                   "\n", "Density of tau_epsilon for different initial value for n=500"))
lines(density(unlist(res03)), ylim = c(0, 1000))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I plot a bar graph using Pandas?

How to plot two violin plot series on the same graph using seaborn?

How do I plot two pandas DataFrames in one graph with the same colors but different line styles?

How to plot different implicit equation in the same graph using python sumpy plot implicit

Plot lines with different x asixs in the same graph

How do I plot the the rows of a matrix as points on a graph?

How to plot multiple learning curve from different model on the same graph?

How can I plot graph in different position in pandas?

How do I plot a Bar graph when comparing the rows?

How do I plot an animation and a point in the same matplotlib plot

How do I plot pie chart graph with pandas data

How do I plot multiple lines of different types on the same chart with ggplot & R

How to plot in pandas - Different x and different y axis in a same plot

How do i plot the graph side by side for comparison?

Pyplot - How do I plot multiple lines on the same graph when list lengths for one axis are not consistent?

How do I plot a graph through an indexed time in matlab?

How can I plot multiple line in the same graph in python?

How can I do a multiple plot with a somSC type graph?

How do I plot multiple data sets with different x and y values on one graph?

How to combine graph of different rows (data frame) & plot in a same graph in R?

R - how to do an XY plot with two datasets in same graph?

How to plot different months as different series in the same graph in R

How do I plot a graph of previously grouped data?

How can I plot 2 graph lines generated on the same plot , separately on two different plots in the image?

How do I plot multiple files in a single graph?

How do you plot smooth components of different GAMs in same panel?

How do I plot the graph for differentiation of a function on Octave?

How do I plot a graph by based on 3 groups in ggplot?

How can I plot two linear regressions on one same graph?