lin.bg.sub | R Documentation |
Subtracts a linear background out of a X-Y dataset and returns the background coefficients as well as the corrected dataset
lin.bg.sub(df, win_df, pl = F)
lin.bg.sub(df, win_df)
df |
Has to be a 2 column dataframe containing the X-Y data. |
win_df |
1. This is referred to as the *windows* dataframe. |
pl |
1. Boolean bit set to TRUE by default. |
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.
Chitran Ghosal
##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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.