tapply and error bars: Problem Fixed

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

tapply and error bars: Problem Fixed

Ogbos
HI Jim,

This is great!! It is also tricky!!! The problem lies in the choice of
ylim. And looking at the data and choosing ylim based on the maximum and
minimum values of y is a waste of time. And choosing it by other means was
yet much more difficult.

I had to start plotting part of the data with incremental step of 80 data
points and manually varying ylim till I got to the last data point 1136,
where I finally used ylim=c(150000,162000) which has nothing to do with the
raw data.

Many, many thanks.
Best wishes
Ogbos

On Sun, Jun 24, 2018 at 9:51 PM, Jim Lemon <[hidden email]> wrote:

> Hi Ogbos,
> The problem is almost certainly with the data. I get the plot I expect
> with the sample data that you first posted, so I know that the code
> works. If you try thIs what do you get?
>
> oodf<-read.table(text="S/N      A        B
> 1    -5  64833
> 2    -4  95864
> 3    -3  82322
> 4    -2  95591
> 5    -1  69378
> 6     0  74281
> 7     1 103261
> 8     2  92473
> 9     3  84344
> 10    4 127415
> 11    5 123826
> 12    6 100029
> 13    7  76205
> 14    8 105162
> 15    9 119533
> 16   10 106490
> 17   -5  82322
> 18   -4  95591
> 19   -3  69378
> 20   -2  74281
> 21   -1 103261
> 22    0  92473
> 23    1  84344
> 24    2 127415
> 25    3 123826
> 26    4 100029
> 27    5  76205
> 28    6 105162
> 29    7 119533
> 30    8 106490
> 31    9 114771
> 32   10  55593
> 33   -5  85694
> 34   -4  65205
> 35   -3  80995
> 36   -2  51723
> 37   -1  62310
> 38    0  53401
> 39    1  65677
> 40    2  76094
> 41    3  64035
> 42    4  68290
> 43    5  73306
> 44    6  82176
> 45    7  75566
> 46    8  89762
> 47    9  88063
> 48   10  94395
> 49   -5  80651
> 50   -4  81291
> 51   -3  63702
> 52   -2  70297
> 53   -1  64117
> 54    0  71219
> 55    1  57354
> 56    2  62111
> 57    3  42252
> 58    4  35454
> 59    5  33469
> 60    6  38899
> 61    7  64981
> 62    8  85694
> 63    9  79452
> 64   10  85216
> 65   -5  71219
> 66   -4  57354
> 67   -3  62111
> 68   -2  42252
> 69   -1  35454
> 70    0  33469
> 71    1  38899
> 72    2  64981
> 73    3  85694
> 74    4  79452
> 75    5  85216
> 76    6  81721
> 77    7  91231
> 78    8 107074
> 79    9 108103
> 80   10  7576",
> header=TRUE)
> library(plotrix)
> std.error<-function(x) return(sd(x)/(sum(!is.na(x))))
> oomean<-as.vector(by(oodf$B,oodf$A,mean))
> oose<-as.vector(by(oodf$B,oodf$A,std.error))
> plot(-5:10,oomean,type="b",ylim=c(50000,110000),
>  xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
> dispersion(-5:10,oomean,oose)
>
> I get the attached plot;
>
> Jim
>
> On Mon, Jun 25, 2018 at 1:58 AM, Ogbos Okike <[hidden email]>
> wrote:
> > Hi Jim
> >
> > Thanks again for returning to this.
> > please not that the line "oomean<-as.vector(by(oodf$B,oodf$A,mean))" was
> > omitted (not sure whether deliberate)  after you introduced the standard
> > error function.
> > When I used it, empty plot window with the correct axes were generated
> but
> > no data was displayed. No error too.
> >
> > library(plotrix)
> > std.error<-function(x) return(sd(x)/(sum(!is.na(x))))
> > oose<-as.vector(by(oodf$B,oodf$A,std.error))
> > plot(-5:10,oomean,type="b",ylim=c(50000,110000),
> >  xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
> > dispersion(-5:10,oomean,oose)
> >
> > When I included the line, the same empty graph window was generated but
> with
> > the former error "Error in FUN(X[[1L]], ...) : could not find function
> > "FUN""
> > library(plotrix)
> > std.error<-function(x) return(sd(x)/(sum(!is.na(x))))
> > oomean<-as.vector(by(oodf$B,oodf$A,mean))
> > oose<-as.vector(by(oodf$B,oodf$A,std.error))
> > plot(-5:10,oomean,type="b",ylim=c(50000,110000),
> >  xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
> > dispersion(-5:10,oomean,oose)
> >
> > I am sure am missing something but can't place it. Please have a look
> again
> > to track my mistake.
> >
> > Warmest regards
> > Ogbos
> >
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.