lin.bg.sub: Linear background subtraction out of an X-Y dataset

View source: R/lin.bg.sub.R

lin.bg.subR Documentation

Linear background subtraction out of an X-Y dataset

Description

Subtracts a linear background out of a X-Y dataset and returns the background coefficients as well as the corrected dataset

Usage

lin.bg.sub(df, win_df, pl = F)
lin.bg.sub(df, win_df)

Arguments

df

Has to be a 2 column dataframe containing the X-Y data.
First column should be the X-data.

win_df

1. This is referred to as the *windows* dataframe.
2. It MUST be a 2 column dataframe.
3. The column names MUST be *min* and *max*.
4. Each entry of this dataframe defines a window within which the background must be evaluated.

pl

1. Boolean bit set to TRUE by default.
2. When true plots the dataset along with a red line depicting the evaluated background.
3. The column names MUST be *min* and *max*.

Value

1. The returned value is alway a LIST.
2. The list contains two elements, 'bg_coeff' and 'sub_data'.
3. 'sub_data' is a dataframe containing the background subtracted data.
4. 'bg_coeff' is a vector containing the two coefficients of the linear background fit.
5. The first coefficient is the slope and the second is the intercept.

Author(s)

Chitran Ghosal

Examples

##testing
#create a gaussian on a linear background
X <- seq(0, 10, by = 0.1)
Y <- gauss(X, amp = 6, mu = 5, sig = 0.75)
Y <- Y + 0.1*X +1
#add noise
Y <- Y + rnorm(n = length(X), mean = 0, sd = 0.5)
#build dataframe
dat <- data.frame(X, Y)
subplot(c(2,1))
plot(dat$X, dat$Y, type = 'b')
abline(v = c(0, 3, 7, 10), col = 'red')
win <- data.frame(min = c(0, 7), max = c(3, 10))
names(win) <- c('min', 'max')

L <- lin.bg.sub(df = dat, win_df = win)
lines(L$sub_data$X, L$sub_data$Y, type = 'l', col = 'blue')
subplot(c(1, 1))

Chitran1987/StatsChitran documentation built on Feb. 23, 2025, 8:30 p.m.