generateSpectrum {Cardinal} | R Documentation

## Generate a simulated spectrum or image

### Description

Generates a simulated spectral signal, or multiple such signals, with peaks of specified intensities.

These functions are provided for backward-compatibility; new code should use `simulateSpectrum` and `simulateImage` instead.

### Usage

    generateSpectrum(n, peaks = 100,
        range = c(1001, 20000),
        centers = seq(
            from = range[1] + diff(range) / (peaks + 1),
            to = range[2] - diff(range) / (peaks + 1),
            length.out = peaks),
        intensities = runif(peaks, min=0.1, max=1),
        step = diff(range)/1e3,
        resolution = 500,
        noise = 0.05,
        sd = 0.1,
        baseline = 2000,
        auc = TRUE)

    generateImage(data = factor(1),
        coord = expand.grid(
            x = 1:max(1, nrow(data)),
            y = 1:max(1, ncol(data))),
        peaks = length(levels(as.factor(data))),
        delta = 10,
        as = c("SImageSet", "MSImageSet"),
        ...)

### Arguments

`n` | The number of signals to simulate.
`peaks` | The number of peaks in the signal.
`range` | A pair of numbers specifying the range of continues feature values at which the signal is measured.
`centers` | The values of the singal feature at which peaks occur.
`intensities` | The values of the intensities of the peaks, which could either be heights of the peaks or their area under the curve.
`step` | The step size between measurements in the feature space.
`resolution` | The instrument resolution. This affects the width of the peaks. Higher resolutions produce sharper peaks.
`noise` | A value without scale that indicates the amount of noise in the signal.
`sd` | Standard deviation of the intensities of the peaks.
`baseline` | A value without scale that indicates the shape and size of the baseline.
`auc` | Should the peak heights be influenced by the area under the curve? This reflects fragmentation and limited accuracy at higher mass ranges. If 'FALSE' then the peak heights correspond directly to the provided intensities.
`data` | Either a `factor` or an integer matrix. If a `factor` is used, the `coord` argument should be specified with `data` to indicate the arrangement of regions in the image. If a matrix is given, `coord` should not be specified. The image will automatically be generated with different regions corresponding to unique integers in the matrix.
`coord` | A `data.frame` with columns representing the spatial dimensions. Each row provides a spatial coordinate for the location of an element of `data` if `data` is a factor.
`delta` | The effect size of the difference between peaks differentiating different regions in the image (as specified by `data`).
`as` | Should the output object be an `SImageSet` or `MSImageSet`?
`...` | Additional arguments to pass to `generateSpectrum`.

### Value

For `generateSpectrum`, a `list` with elements:

- `x`: `numeric`, a numeric vector of signal intensities

- `t`: `numeric`, a numeric vector of signal features

For `generateImage()`, a `SImageSet` or a `MSImageSet`.

### Author(s)

Kylie A. Bemis

### See Also

`simulateSpectrum`, `simulateImage`

### Examples

    # Generate spectra
    s <- generateSpectrum(1)
    plot(x ~ t, type="l", data=s)

    s <- generateSpectrum(1, centers=c(2000,3000), resolution=10, baseline=3000)
    plot(x ~ t, type="l", data=s)

    s <- generateSpectrum(1, peaks=2, auc=FALSE, baseline=0)
    plot(x ~ t, type="l", data=s)

    # Generate images
    data <- matrix(c(NA, NA, 1, 1, NA, NA, NA, NA, NA, NA, 1, 1, NA, NA,
     NA, NA, NA, NA, NA, 0, 1, 1, NA, NA, NA, NA, NA, 1, 0, 0, 1,
     1, NA, NA, NA, NA, NA, 0, 1, 1, 1, 1, NA, NA, NA, NA, 0, 1, 1,
     1, 1, 1, NA, NA, NA, NA, 1, 1, 1, 1, 1, 1, 1, NA, NA, NA, 1,
     1, NA, NA, NA, NA, NA, NA, 1, 1, NA, NA, NA, NA, NA), nrow=9, ncol=9)

    set.seed(1)
    x <- generateImage(data)

    plot(x, pixel=1)
    image(x, feature=1)

    coord <- expand.grid(x=1:nrow(data), y=1:ncol(data))

    data2 <- as.factor(data[is.finite(data)])
    coord2 <- coord[is.finite(data),]

    set.seed(1)
    x2 <- generateImage(data=data, coord=coord, as="MSImageSet")

    plot(x, pixel=1)
    image(x2, feature=1)

[Package Cardinal version 2.2.6 Index]