r - Loess regression produces a stair-stepped graph after a specific value -


enter image description here

i trying smooth series of datasets erase noise preserve meaningful peaks. this, have been using loess regression.

as can see image above, after dataset goes past diameter of 10, smoothed graph becomes stepped, alters data much. happens after diameter of 10.

my goal isolate , understand why happening.

code reproduce issue

the following code uses packages ggplot2 , dplyr.

here function have used apply regression. graph example, have used smoothing span of 0.05.

applyloesssmooth <- function(raw.data, smoothing.span) {   curr.scan.state <- raw.data[complete.cases(raw.data),]   ## response   vars <- colnames(curr.scan.state)   ## covariate   id <- 1:nrow(curr.scan.state)     ## define loess filter function (fitting loess regression line)   loess.filter <- function (x, span) loess(formula = paste(x, "id", sep = "~"),                                        data = curr.scan.state,                                        degree = 1,                                        span = span, na.action=na.omit)$fitted   ## apply filter column-by-column   loess.graph.data <- as.data.frame(lapply(vars, loess.filter, span = smoothing.span),                                 col.names = colnames(curr.scan.state))   sample.rows <- length(loess.graph.data[,1])   return(loess.graph.data %>% mutate("sample.diameters" = curr.scan.state$sample.diameters[1:sample.rows])) } 

some smaller subsets (~200 values) of graphed data around area of interest, before , after regression applied:

here exact data subsets can use reproduce graph, except contain 1 scan instead of four. if dataset 4 scans, please let me know , upload .csv - large copypaste using dput(). warned these subsets ~4000 values, large.

this ggplot2 call using generate graph.

scan.plot <- ggplot(data = scan.plot.data, aes(sample.diameters, scan1)) +   geom_line() +   scale_size_manual(values = c(0.1, 1.5)) +   xlab("diameters (nm)") +   ylab("concentration (dn#/cm^2)") +   theme(plot.title = element_text(hjust = 0.5)) 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -