Re: [R] How to estimate weekly Variance

From: jim holtman <jholtman_at_gmail.com>
Date: Sat, 16 Feb 2008 11:52:27 -0500

Here is one way of doing it:

> x <- read.table(textConnection("WK TD VARTD PD DailyVarPD

+ 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"), header=TRUE)

> closeAllConnections()
> # daily using your formula
> x$newDaily <- with(x, (PD * (1 - TD))/TD + VARTD * ((PD*(1-TD)+ PD^2*TD))/TD^3)
> x
   WK       TD    VARTD  PD DailyVarPD   newDaily
1  28 0.014735 4.49e-05   0          0      0.000
2  28 0.012421 4.49e-05   0          0      0.000
3  28 0.014396 4.49e-05  71       7005   7006.197
4  28 0.014898 4.49e-05 132      14016  14018.783
5  28 0.013512 4.49e-05 223      32506  32514.484
6  28 0.013886 4.49e-05 224      31287  31295.424
7  28 0.013778 4.49e-05 218      30528  30535.647
8  29 0.013274 4.49e-05 228      34505  34514.170
9  29 0.013072 4.49e-05 224      34531  34539.992
10 29 0.012518 4.49e-05 488     117720 117762.642
11 29 0.013264 4.49e-05 525     119323 119365.443
12 29 0.013233 4.49e-05  80       9134   9136.090
13 29 0.010194 4.49e-05 417     133067 133116.531
14 29 0.012567 4.49e-05  82      10184  10186.465
15 30 0.014695 4.49e-05 413      68893  68915.217
16 30 0.010634 4.49e-05 373     103688 103724.478
17 30 0.013934 4.49e-05 914     272719 272829.966
18 30 0.014107 4.49e-05 213      28473  28480.576
19 30 0.014339 4.49e-05 651     147016 147070.746
20 30 0.014375 4.49e-05 521     102429 102464.631
21 30 0.016373 4.49e-05 979     229104 229195.063

> # not sure what you want for weekly, but we can take the averages of the values
> x.wk <- aggregate(x, list(x$WK), mean)
> x.wk$var <- with(x.wk, (PD * (1 - TD))/TD + VARTD * ((PD*(1-TD)+ PD^2*TD))/TD^3)
> x.wk
  Group.1 WK         TD    VARTD       PD DailyVarPD  newDaily       var
1      28 28 0.01394657 4.49e-05 124.0000   16477.43  16481.51  14340.27
2      29 29 0.01258886 4.49e-05 292.0000   65494.86  65517.33  53548.78
3      30 30 0.01406529 4.49e-05 580.5714  136046.00 136097.24 126432.61

>
>

On Feb 16, 2008 11:17 AM, Felipe Carrillo <mazatlanmexico_at_yahoo.com> wrote:
> Jim:
> I actually would like to know how can I estimate Daily
> and Weekly Variance for PD using R and not Excel.I
> have read about R's variance function but I don't know
> how to apply it to PD in my dataset. I hope my
> question is clearer. Thanks
>
>
> > > 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
> > >
> > >
> > > Felipe D. Carrillo
> > > Fishery Biologist
> > > US Fish & Wildlife Service
> > > California, USA
> > >
> > >
> > >
> > >
> >
> ____________________________________________________________________________________
> > > Be a better friend, newshound, and
> > >
> > > ______________________________________________
> > > R-help_at_r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained,
> > reproducible code.
> > >
> >
> >
> > --
> > Jim Holtman
> > Cincinnati, OH
> > +1 513 646 9390
> >
> > What is the problem you are trying to solve?
> >
>
>
> Felipe D. Carrillo
> Fishery Biologist
> US Fish & Wildlife Service
> California, USA
>
>
>
> ____________________________________________________________________________________
> Never miss a thing. Make Yahoo your home page.
> http://www.yahoo.com/r/hs
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 16 Feb 2008 - 16:55:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 16 Feb 2008 - 17:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive