moving-average

Calculating moving-averages of variable parameters

浪尽此生 提交于 2019-12-20 02:52:35
问题 I have an integer property which is updated every second with a signal-strength value ranging from 0 - 100. I'd like to be able to keep an ongoing measure of the moving average over the last 10, 25, 50 measurements. What's the most efficient way of doing this? I'm currently thinking of implementing a set of FIFO queues using NSMutableArray and popping the leading value every time I add a new one at the end once the array has the requisite number of entries. However, I'm not sure if there's a

Rolling / moving avg by group

允我心安 提交于 2019-12-19 06:19:11
问题 How to generate rolling mean with grouped data. Here's the data set.seed(31) dd<-matrix(sample(seq(1:20),30,replace=TRUE),ncol=3) Add a group identifier, and sort by group identifier du<-sample(seq(1:4),10,replace=TRUE) d<-cbind(du,dd) d<-d[order(d[,1]),] This gives the rolling mean but ignores group bounderis d_roll_mean <- apply(d[,2:4], 2, function(x) { rollapply(zoo(x), 3, mean, partial=TRUE, align='right') } ) This gives the results below # cbind(d,d_roll_mean) # [1,] 1 3 3 12 3.000000 3

Cumulative sums, moving averages, and SQL “group by” equivalents in R

给你一囗甜甜゛ 提交于 2019-12-18 13:24:40
问题 What's the most efficient way to create a moving average or rolling sum in R? How do you do the rolling function along with a "group by"? 回答1: While zoo is great, sometimes there are simpler ways. If you data behaves nicely, and is evenly spaced, the embed() function effectively lets you create multiple lagged version of a time series. If you look inside the VARS package for vector auto-regression, you will see that the package author chooses this route. For example, to calculate the 3 period

Grouped moving average in r

﹥>﹥吖頭↗ 提交于 2019-12-17 20:27:43
问题 I'm trying to calculate a moving average in r over a particular field BUT I need this moving average to be grouped by two or more other fields. The purpose of this new average is for predictive analysis so I need it to be trailing as well. Any variables that do not have enough values to be averaged (such as student J) would ideally give either NA or its original Score value. I've been trying rollapply and data.table and am having no luck! I've provided the table of data and two moving

Replace NaN or missing values with rolling mean or other interpolation

落花浮王杯 提交于 2019-12-17 18:55:20
问题 I have a pandas dataframe with monthly data that I want to compute a 12 months moving average for. Data for for every month of January is missing, however (NaN), so I am using pd.rolling_mean(data["variable"]), 12, center=True) but it just gives me all NaN values. Is there a simple way that I can ignore the NaN values? I understand that in practice this would become a 11-month moving average. The dataframe has other variables which have January data, so I don't want to just throw out the

Conditional rolling mean (moving average) on irregular time series

懵懂的女人 提交于 2019-12-17 18:41:33
问题 I have a group of data in the format: ID Minutes Value xxxx 118 3 xxxx 121 4 xxxx 122 3 yyyy 122 6 xxxx 123 4 yyyy 123 8 ... ... .... Each ID is a patient and each value is, say, blood pressure for that minute. I would like to create a rolling average for the 60 minutes before and 60 minutes after each point. However - as you can see, there are missing minutes (so I cannot merely use row numbers) and I would like to create average for each unique ID (so the average for ID xxxx cannot include

SQL Query for 7 Day Rolling Average in SQL Server

╄→гoц情女王★ 提交于 2019-12-17 09:36:18
问题 I have a table of hourly product usage (how many times the product is used) data – ID (bigint)| ProductId (tinyint)| Date (int - YYYYMMDD) | Hour (tinyint)| UsageCount (int) #|1 | 20140901 | 0 | 10 #|1 | 20140901 | 1 | 15 #|1 | 20140902 | 5 | 25 #|1 | 20140903 | 5 | 25 #|1 | 20140904 | 3 | 25 #|1 | 20140905 | 7 | 25 #|1 | 20140906 | 10 | 25 #|1 | 20140907 | 9 | 25 #|1 | 20140908 | 5 | 25 #|2 | 20140903 | 16 | 10 #|2 | 20140903 | 13 | 115 Likewise, I have the usage data for 4 different

How do you create a Moving Average Method in SQL?

[亡魂溺海] 提交于 2019-12-13 09:27:23
问题 How do you create a Moving Average Method in SQL? order table: id_order id_staff date_order O0001 S0003 12/12/2555 O0002 S0003 12/12/2555 O0003 S0003 12/12/2555 O0004 S0003 13/12/2555 O0005 S0003 13/12/2555 O0006 S0003 13/12/2555 O0007 S0003 13/12/2555 O0008 S0003 13/12/2555 detail_order table: idde_order id_order id_material count M0004 O0003 S0002 3 M0005 O0003 S0003 5 M0009 O0003 S0002 3 M0010 O0003 S0003 5 M0011 O0003 S0001 3 Desired table join or output: Date count 3 day Moving Average

Simple Moving Average summation/offset issue

落爺英雄遲暮 提交于 2019-12-13 06:08:47
问题 I wrote a simple moving average with a moving window of Temperatures read as a voltage between 0 and 10V. The algorithm appears to work correctly, however, it has a problem where depending upon which Temperatures filled the window first, the moving average will have an offset for any values not near this value. For example, running this program with the temp. sensor plugged in a room temp yields 4.4V or 21.3 C. Though, if I unplug the temp. sensor the voltage drops to 1.4V yet the moving

Moving average with changing period in R

三世轮回 提交于 2019-12-13 02:28:04
问题 I have a data frame named abc on which I'm doing moving average using rollapply . The following code works: forecast <- rollapply(abc, width=12, FUN=mean, align = "right", fill=NA) Now, I want to do the same thing with the width being variable, i.e. for the 1st month, it'll be empty, for the second month, first month's value will come. For the third month, it'll be (first month+second month/2), i.e. for the ith month, if i<=12 , the value will be (sum(1:i-1)/(i-1)) and for i>=12 it will be