#'
#' One-dimensional gaussian segmentation
#'
#' @description Simulating a one-dimenstional segmentation with a given number of segments
#' @param mean Vector of means (mean of consecutive segments)
#' @param tau relative position (between 0 and 1) of the changepoints (the last position is always 1)
#' @param sigma A positive number: the value (unique) of the standard deviation for all the Gaussian laws in the simulation
#' @param n The number of data point to simulate
#' @return A vector of data of length n generated by the simulated segmentation
#' @examples
#' data <- dataG1(sigma = 0.05, n=20)
#' plot(1:20,data)
dataG1 <- function(mean=c(0.5,0,-0.5,0), tau=c(0.25,0.5,0.75,1), sigma = 1, n=100){
y <- rep(0,n)
for (i in 1:n){
index <- which(tau>=i/n)[1]
y[i] <- rnorm(1,mean[index],sigma)
}
return(y)
}
#'
#' Two-dimensional gaussian segmentation
#'
#' @description Simulating a two-dimenstional segmentation with a given number of segments
#' @param mean1 Vector of means for the first dimension
#' @param mean2 Vector of means for the second dimension
#' @param tau relative position (between 0 and 1) of the changepoints (the last position is always 1)
#' @param sigma A positive number: the value (unique) of the standard deviation for all the Gaussian laws in the simulation #' @param n The number of data point to simulate
#' @param n The number of data point to simulate
#' @return A matrix of data of dimension 2 x n generated by the simulated segmentation
#' @examples
#' data <- dataG2(sigma = 0.05, n=50)
#' max = max(data);min = min(data)
#' plot(1:50,data[1,],ylim = c(min,max))
#' par(new = TRUE)
#' plot(1:50,data[2,],ylim = c(min,max),col=2)
#' par(new = FALSE)
dataG2 <- function(mean1=c(0,1,1,0), mean2=c(0,0,1,1), tau=c(0.25,0.5,0.75,1), sigma = 1, n=100){
y <- matrix(0,2,n)
for (i in 1:n){
index <- which(tau>=i/n)[1]
y[1,i] <- rnorm(1,mean1[index],sigma)
y[2,i] <- rnorm(1,mean2[index],sigma)
}
return(y)
}
#'
#' data in dimension 1 with no pruned last changepoint candidate
#'
#' @description Generating data in dimension 1 with no pruning
#' @param n length of the vector
#' @param beta the penalty coefficient (use the same beta in function fpop1d)
#' @return A vector of data of length n
#' @examples
#' data <- dataAll(n = 10, beta = 2)
#' fpop1d(data, beta = 2)
#'
#'
dataAll <- function(n, beta = 1){
v <- rep(0,n)
for(i in 2:n){v[i] <- sqrt(beta/n)*(sqrt(n-1)-sqrt(i*(n-i))+sqrt((i-1)*(n-i+1)))}
return(v)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.