[R] How to estimate weekly Variance

David Winsemius dwinsemius at comcast.net
Sat Feb 16 16:18:08 CET 2008


Felipe Carrillo <mazatlanmexico at yahoo.com> wrote in
news:735441.30138.qm at web56609.mail.re3.yahoo.com: 

> Dear All:
> Using the Excel formula below I am able to estimate
> daily variance(Daily VarPD)for PD,but I can't figure
> out how to estimate the Weekly variance for PD. Any
> hints?
> 
> Daily VarPD = (PD * (1 - TD))/TD + VarTD *
> ((PD*(1-TD)+ PD^2*TD))/TD^3
> 
> 
> WK     TD               VARTD      PD       Daily VarPD
> 28     0.014735     0.0000449     0     0
> 28     0.012421     0.0000449     0     0
> 28     0.014396     0.0000449     71     7005
> 28     0.014898     0.0000449     132     14016
> 28     0.013512     0.0000449     223     32506
> 28     0.013886     0.0000449     224     31287
> 28     0.013778     0.0000449     218     30528
> 29     0.013274     0.0000449     228     34505
> 29     0.013072     0.0000449     224     34531
> 29     0.012518     0.0000449     488     117720
> 29     0.013264     0.0000449     525     119323
> 29     0.013233     0.0000449     80     9134
> 29     0.010194     0.0000449     417     133067
> 29     0.012567     0.0000449     82     10184
> 30     0.014695     0.0000449     413     68893
> 30     0.010634     0.0000449     373     103688
> 30     0.013934     0.0000449     914     272719
> 30     0.014107     0.0000449     213     28473
> 30     0.014339     0.0000449     651     147016
> 30     0.014375     0.0000449     521     102429
> 30     0.016373     0.0000449     979     229104

I am going to assume on the basis of your earlier posts that you have 
gotten this into a dataframe. You should know, since Prof Ripley told 
you so six months ago, that variable names cannot have spaces. The  
formula you offer makes no sense to me, and I could not see what 
bearing it has on calculating a variance of a week's worth of PD 
values. In the future, you should offer code to create a minimal 
dataset.

Assuming your dataframe is fishwk, here is a method to get the 
variances of PD by week:

by(data=fishwk, INDICES=fishwk$WK, function(x) var(x$PD))


-- 
David Winsemius



More information about the R-help mailing list