Learn R Programming

MRIaggr (version 1.1.5)

simul_fMM: Simulation under the mixture model

Description

Simulation of a sample following a distribution issue from a non-spatial mixture model.

Usage

simul_fMM(n, G, Ydist="gaussian", Y_mu, Y_sd, nclass = "auto",
    beta=FALSE, Xdist=NULL, X_mu=NULL, X_sd=NULL,
    n.Id=NULL, Id_sd=NULL, noise_sd=NULL,
    display_Y=TRUE, display_X=TRUE, window=FALSE,
	filename="calc-echantillon", width=1000, height=700, path=NULL, unit="px", res=NA)

Arguments

n
The number of observation to simulate. interger.
G
The number of groups to be considered for the mixture. integer.
Ydist
The distribution of the observations. character vector[G]. Must contains only : "unif", "unif_segment", "gaussian", "Gamma" or "Beta".
Y_mu
The expected value of each group. numeric vector[G].
Y_sd
The standard deviation of each group. numeric vector[G].
nclass
The number of observation by class for the histogram. integer.
beta
Should a concomitant model be considered ? logical.
Xdist
The distribution of the concomitant variable. character vector[G]. Must contains only : "unif", "gaussian", "Gamma".
X_mu
The expected value of the concomitant varible for each group. numeric vector[G].
n.Id
The number of patient to be considered. numeric.
Id_sd
The standard deviation of the random effect. numeric.
X_sd
The standard deviation of the concomitant varible for each group. numeric vector[G].
noise_sd
The standard deviation of the noise. numeric. NULL indicates no noise.
display_Y
Should the graphics representing the Y distribution be displayed. logical.
display_X
Should the graphics representing the X distribution be displayed. logical.
window
Display the graphics in the current graphics device (F), in a new device (T), save it in a png/eps/svg file ("png" / "esp" / "png"). NULL indicates no display.
filename
Name of the file (without the extension) where the plot should be saved. character. Ignored if window is not png/eps/svg.
width
the width of the device. numeric. Ignored if window is not png/eps/svg.
height
the width of the device. numeric. Ignored if window is not png/eps/svg.
path
the directory where the plot file will be created. character. Default is NULL corresponding to the current working directory.
unit
the units in which height and width are given. Can be "px", "in", "cm" or "mm". Default is "px".
res
the nominal resolution in ppi which will be recorded in the bitmap file, if a positive integer. numeric. Default is NA.

Value

  • A list containing :
  • Ya vector containing the simulated response variables.
  • Xa vector containing the simulated concomitant variables.
  • moya numeric containing the empirical mean of the response variable.
  • vara numeric containing the empirical standard deviation of the response variable.
  • Y_ga list containing the simulated response variables for each group.
  • X_ga list containing the simulated concomitant variables for each group.
  • moy_ga vector containing the empirical mean of the response variable for each group.
  • var_ga vector containing the empirical standard deviation of the response variable for each group.
  • Ydista list containing the family used to simulate the response variables.
  • Y_mua vector containing the simulated mean of the response variable for each group (without possible addition of noise).
  • Y_sda vector containing the simulated standard deviation of the response variable for each group (without possible addition of noise).
  • betaa vector containing the theorical parameters of the concomitant model for each group.
  • Xdista vector containing the family used to simulate the concomitant variables.
  • X_mua vector containing the empirical expected value of the concomitant variable for each group.
  • X_sda vector containing the empirical standard deviation of the concomitant variable for each group.
  • groupa matrix indicating the group membership of the observations.
  • priora matrix indicating the prior probabilities associated to the concomitant model.

Examples

Run this code
# settings 
G <- 3 # nb of groups
n_px <- 30 # width of the area
n <- (n_px*G)^2 # total number of pixel
mu <- c(-3,0,4) # mean values of the groups
sigma <- c(sqrt(3),1,sqrt(3)) # sd values of the groups
Ydist <- c("gaussian","gaussian","gaussian") # distribution of the groups

# simulation 
set.seed(10)
simulation <- simul_fMM(n=rep(n/3,G),
                          G=G,                          
                          Ydist=Ydist,
                          Y_mu=mu,
                          Y_sd=sigma,
                          display_Y=TRUE)
                          
if(try(require(fields))){
image.plot(x=1:sqrt(n),y=1:sqrt(n),xlab="",ylab="",axes=FALSE,
           z=matrix(simulation$Y,sqrt(n),sqrt(n)),
           main="Groups")
}

Run the code above in your browser using DataLab