moving-average

Smoothing a 2D matrix with rollmean, filter, rollapply or other R facilities by moving average sliding window method

百般思念 提交于 2019-12-07 19:05:09
问题 I am trying to find a function in R which smooths a 2D matrix which is already padded by zero around the matrix depending on the length of the window. If the window size is 3 then we pas 3 zeros from the top, bottom, right and left and then we do the averaging to smooth it. I found rollmean in SO and other tutorials but it doesn't exactly do what I want. I need (say if the window size is 3) we consider a window of 3*3 and take the average and replace it by the current elements of the current

Moving average - MySQL

◇◆丶佛笑我妖孽 提交于 2019-12-07 14:45:40
问题 I'm trying to implement system-wide login throttling and I need to calculate the daily average number of failed login attempts from the last 3 months. I'm currently inserting a record on every login fail, each with a timestamp. How can I do this in MySQL? Thanks in advance for your help 回答1: SELECT AVG(cnt) FROM (SELECT COUNT(*) AS cnt FROM mytable WHERE `date` BETWEEN DATE_SUB(NOW(), INTERVAL 3 MONTH) AND NOW() GROUP BY DATE(`date`)) x Assuming you have a table mytable with field date of

rolling average to multiple variables in R using data.table package

…衆ロ難τιáo~ 提交于 2019-12-06 23:47:55
问题 I would like to get rolling average for each of the numeric variables that I have. Using data.table package, I know how to compute for a single variable. But how should I revise the code so it can process multiple variables at a time rather than revising the variable name and repeat this procedure for several times? Thanks. Suppose I have other numeric variables named as "V2", "V3", and "V4". require(data.table) setDT(data) setkey(data,Receptor,date) data[ , `:=` ('RollConc' = rollmean

C# MSChart Candle Stick & Moving Average Chart. Error: Formula error - There are not enough data points for the Period

穿精又带淫゛_ 提交于 2019-12-06 16:32:26
You cannot vote on your own post 0 I am trying to create a stock candle with MA(15) on daily data. I can create a chart with OHLC bar without any problem. But when I started usingDataManipulator.FinancialFormula for MA, I keep getting errors of "Formula error - There are not enough data points for the Period." Can someone help me out on this? Thanks Here is the code. DataSet ds = new DataSet(); SqlConnection connection = new SqlConnection(); connection.ConnectionString = @"Data Source=XXX;Database=Stock;Integrated Security=SSPI;"; connection.Open(); string sql = "Select datestamp, highprice,

Rolling comparison between a value and a past window, with percentile/quantile

自作多情 提交于 2019-12-06 15:35:47
问题 I'd like to compare each value x of an array with a rolling window of the n previous values. More precisely I'd like to see at which percentile this new value x would be, if we added it to the previous window : import numpy as np A = np.array([1, 4, 9, 28, 28.5, 2, 283, 3.2, 7, 15]) print A n = 4 # window width for i in range(len(A)-n): W = A[i:i+n] x = A[i+n] q = sum(W <= x) * 1.0 / n print 'Value:', x, ' Window before this value:', W, ' Quantile:', q [ 1. 4. 9. 28. 28.5 2. 283. 3.2 7. 15. ]

Moving average in SQLite

强颜欢笑 提交于 2019-12-06 12:08:57
问题 I would like to compute a moving average over data in a SQLite table. I found several method in MySQL, but couldn't find an efficient one in SQLite. In SQL, I think something like this should do it (however, I was not able to try it...) : SELECT date, value, avg(value) OVER (ORDER BY date ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING) as MovingAverageWindow7 FROM t ORDER BY date; However, I see two drawbacks : This does not seems to work on sqlite If data are not continuous for few dates on

How to take the mean of last 10 values in a column before a missing value using R?

谁说我不能喝 提交于 2019-12-06 08:58:10
问题 I am new to R and having trouble figuring out to go about this. I have data on tree growth rates from dead trees, organized by year. So, my first column is year and the columns to the right are growth rates for individual trees, ending in the year each tree died. After the tree died, the values are "NA" for the remaining years in the dataset. I need to take the mean growth for the 10 years preceding each tree's death, but each tree died in a different year. Does anyone have an idea for how to

Smoothing a 2D matrix with rollmean, filter, rollapply or other R facilities by moving average sliding window method

混江龙づ霸主 提交于 2019-12-06 07:58:24
I am trying to find a function in R which smooths a 2D matrix which is already padded by zero around the matrix depending on the length of the window. If the window size is 3 then we pas 3 zeros from the top, bottom, right and left and then we do the averaging to smooth it. I found rollmean in SO and other tutorials but it doesn't exactly do what I want. I need (say if the window size is 3) we consider a window of 3*3 and take the average and replace it by the current elements of the current window and then move the window to the right by one unit (pixel). And for example when we reach the

Moving average for time series with not-equal intervls

空扰寡人 提交于 2019-12-06 05:37:02
问题 I have a dataset for price of the ticker on the stock exchange: time - price. But intervals between data points are not equal - from 1 to 2 minutes. What is the best practice to calculate moving average for such case? How to make it in Matlab? I tend to think, that weights of the points should depend on the time interval that was last since previous point. Does we have function in Matlab to calculate moving average with custom weights of the points? 回答1: Here is an example of the "naive"

Moving average - MySQL

好久不见. 提交于 2019-12-05 21:39:21
I'm trying to implement system-wide login throttling and I need to calculate the daily average number of failed login attempts from the last 3 months. I'm currently inserting a record on every login fail, each with a timestamp. How can I do this in MySQL? Thanks in advance for your help SELECT AVG(cnt) FROM (SELECT COUNT(*) AS cnt FROM mytable WHERE `date` BETWEEN DATE_SUB(NOW(), INTERVAL 3 MONTH) AND NOW() GROUP BY DATE(`date`)) x Assuming you have a table mytable with field date of type date , datetime or timestamp 来源: https://stackoverflow.com/questions/5036176/moving-average-mysql