Description Usage Arguments Details Value Author(s) Examples

View source: R/predict_gaussian_2D.R

Predict values from a fitted 2D gaussian

1 | ```
predict_gaussian_2D(fit_object, X_values, Y_values, ...)
``` |

`fit_object` |
Either the output of |

`X_values` |
vector of numeric values for the x-axis |

`Y_values` |
vector of numeric values for the y-axis |

`...` |
Additional arguments |

This function assumes Gaussian parameters have been fitted beforehand. No
fitting of parameters is done within this function; these can be
supplied via the object created by `gaussplotR::fit_gaussian_2D()`

.

If `fit_object`

is not an object created by
`gaussplotR::fit_gaussian_2D()`

, `predict_gaussian_2D()`

attempts
to parse `fit_object`

as a list of two items. The coefficients of the fit
must be supplied as a one-row, named data.frame within
`fit_object$coefs`

, and details of the methods for fitting the Gaussian
must be contained as a character vector in `fit_object$fit_method`

. This
character vector in `fit_object$fit_method`

must be a named vector that
provides information about the method, amplitude constraint choice, and
orientation constraint choice, using the names `method`

,
`amplitude`

, and `orientation`

. `method`

must be one of:
`"elliptical"`

, `"elliptical_log"`

, or `"circular"`

.
`amplitude`

and `orientation`

must each be either
`"unconstrained"`

or `"constrained"`

. For example, ```
c(method =
"elliptical", amplitude = "unconstrained", orientation = "unconstrained")
```

.
One exception to this is when `method = "circular"`

, in which case
`orientation`

must be `NA`

, e.g.: ```
c(method = "circular",
amplitude = "unconstrained", orientation = NA)
```

.

A data.frame with the supplied `X_values`

and `Y_values`

along with the predicted values of the 2D gaussian
(`predicted_values`

)

Vikram B. Baliga

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | ```
if (interactive()) {
## Load the sample data set
data(gaussplot_sample_data)
## The raw data we'd like to use are in columns 1:3
samp_dat <-
gaussplot_sample_data[,1:3]
#### Example 1: Unconstrained elliptical ####
## This fits an unconstrained elliptical by default
gauss_fit <-
fit_gaussian_2D(samp_dat)
## Generate a grid of x- and y- values on which to predict
grid <-
expand.grid(X_values = seq(from = -5, to = 0, by = 0.1),
Y_values = seq(from = -1, to = 4, by = 0.1))
## Predict the values using predict_gaussian_2D
gauss_data <-
predict_gaussian_2D(
fit_object = gauss_fit,
X_values = grid$X_values,
Y_values = grid$Y_values,
)
## Plot via ggplot2 and metR
library(ggplot2); library(metR)
ggplot_gaussian_2D(gauss_data)
## Produce a 3D plot via rgl
rgl_gaussian_2D(gauss_data)
#### Example 2: Constrained elliptical_log ####
## This fits a constrained elliptical, as in Priebe et al. 2003
gauss_fit <-
fit_gaussian_2D(
samp_dat,
method = "elliptical_log",
constrain_orientation = -1
)
## Generate a grid of x- and y- values on which to predict
grid <-
expand.grid(X_values = seq(from = -5, to = 0, by = 0.1),
Y_values = seq(from = -1, to = 4, by = 0.1))
## Predict the values using predict_gaussian_2D
gauss_data <-
predict_gaussian_2D(
fit_object = gauss_fit,
X_values = grid$X_values,
Y_values = grid$Y_values,
)
## Plot via ggplot2 and metR
ggplot_gaussian_2D(gauss_data)
## Produce a 3D plot via rgl
rgl_gaussian_2D(gauss_data)
}
``` |

```
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.