Re: [R] tapply and error bars
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 AB 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 104 127415 115 123826 126 100029 137 76205 148 105162 159 119533 16 10 106490 17 -5 82322 18 -4 95591 19 -3 69378 20 -2 74281 21 -1 103261 220 92473 231 84344 242 127415 253 123826 264 100029 275 76205 286 105162 297 119533 308 106490 319 114771 32 10 55593 33 -5 85694 34 -4 65205 35 -3 80995 36 -2 51723 37 -1 62310 380 53401 391 65677 402 76094 413 64035 424 68290 435 73306 446 82176 457 75566 468 89762 479 88063 48 10 94395 49 -5 80651 50 -4 81291 51 -3 63702 52 -2 70297 53 -1 64117 540 71219 551 57354 562 62111 573 42252 584 35454 595 33469 606 38899 617 64981 628 85694 639 79452 64 10 85216 65 -5 71219 66 -4 57354 67 -3 62111 68 -2 42252 69 -1 35454 700 33469 711 38899 722 64981 733 85694 744 79452 755 85216 766 81721 777 91231 788 107074 799 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(5,11), 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 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(5,11), > 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(5,11), > 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 > ooplot.pdf Description: Adobe PDF document __ R-help@r-project.org 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.
Re: [R] tapply and error bars
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(5,11), 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(5,11), 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 On Sun, Jun 24, 2018 at 11:24 AM, Jim Lemon wrote: > Hi Ogbos, > If I use the example data that you sent, I get the error after this line: > > oose<-as.vector(by(oodf$B,oodf$A,std.error)) > Error in FUN(X[[i]], ...) : object 'std.error' not found > > The reason is that you have not defined std.error as a function, but > as the result of a calculation. When I rewrite it like this: > > 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(5,11), > xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day") > dispersion(-5:10,oomean,oose) > > I get the expected plot. > > Jim > > > On Sat, Jun 23, 2018 at 9:36 PM, Ogbos Okike > wrote: > > Hi Jim, > > > > Thanks for assisting. Here is what I did: > > > > A<-matrix(rep(-5:10,71)) > > B<-matrix(data) > > std.error = sd(B)/sqrt(sum(!is.na(B))) > > oodf<-data.frame(A,B) > > > > 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(5,11), > > xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day") > > dispersion(-5:10,oomean,oose) > > > > And the error says: > > Error in FUN(X[[1L]], ...) : could not find function "FUN" > > > > Please note that I use: > > std.error = sd(B)/sqrt(sum(!is.na(B))) > > to calculate the standard error as it requested for it. > > > > Thanks > > Ogbos > > > > On Sat, Jun 23, 2018 at 10:09 AM, Jim Lemon > wrote: > >> > >> Hi Ogbos, > >> This may help: > >> > >> # assume your data frame is named "oodf" > >> 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(5,11), > >> xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day") > >> dispersion(-5:10,oomean,oose) > >> > >> Jim > >> > >> On Sat, Jun 23, 2018 at 4:35 PM, Ogbos Okike > >> wrote: > >> > Dear workers, > >> > I have a data of length 1136. Below is the code I use to get the means > >> > B. > >> > It worked fine and I had the mean calculated and plotted. > >> > > >> > I wish to plot the error bars as well. I already plotted such means > with > >> > error bars before. Please see attached for example. > >> > > >> > I tried to redo the same plot but unlikely could not get around it as > I > >> > lost my system containing the script. > >> > Among many attempts, I tried: > >> > library(gplots) > >> > > >> > plotmeans(errors~AB,xlab="Factor A",ylab="mean errors", p=.68, > >> > main="Main > >> > effect Plot",barcol="black") > >> > Nothing worked. > >> > > >> > I would really be thankful should somebody return me to the track. > >> > Many, many thanks for your time. > >> > Ogbos > >> > > >> > A sample of the data is: > >> > S/N AB > >> > 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 > >> > 104 127415 > >> > 115 123826 > >> > 126 100029 > >> > 137 76205 > >> > 148 105162 > >> > 159 119533 > >> > 16 10 106490 > >> > 17 -5 82322 > >> > 18 -4 95591 > >> > 19 -3 69378 > >> > 20 -2 74281 > >> > 21 -1 103261 > >> > 220 92473 > >> > 231 84344 > >> > 242 127415 > >> > 253 123826 > >> > 264 100029 > >> > 275 76205 > >> > 286 105162 > >> > 297 119533 > >> > 308 106490 > >> > 319 114771 > >> > 32 10 55593 > >> > 33 -5 85694 > >> > 34 -4 65205 > >> > 35 -3 80995 > >> > 36 -2 51723 > >> > 37 -1 62310 > >> > 380 53401 > >> > 391 65677 > >> > 402 76094 > >> > 413 64035 > >> > 424 68290 > >> > 435 73306 > >> > 446 82176 > >> > 457 75566 > >> > 468 89762 > >> > 479 88063 > >> > 48 10 94395 > >>
Re: [R] tapply and error bars
Hi Ogbos, If I use the example data that you sent, I get the error after this line: oose<-as.vector(by(oodf$B,oodf$A,std.error)) Error in FUN(X[[i]], ...) : object 'std.error' not found The reason is that you have not defined std.error as a function, but as the result of a calculation. When I rewrite it like this: 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(5,11), xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day") dispersion(-5:10,oomean,oose) I get the expected plot. Jim On Sat, Jun 23, 2018 at 9:36 PM, Ogbos Okike wrote: > Hi Jim, > > Thanks for assisting. Here is what I did: > > A<-matrix(rep(-5:10,71)) > B<-matrix(data) > std.error = sd(B)/sqrt(sum(!is.na(B))) > oodf<-data.frame(A,B) > > 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(5,11), > xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day") > dispersion(-5:10,oomean,oose) > > And the error says: > Error in FUN(X[[1L]], ...) : could not find function "FUN" > > Please note that I use: > std.error = sd(B)/sqrt(sum(!is.na(B))) > to calculate the standard error as it requested for it. > > Thanks > Ogbos > > On Sat, Jun 23, 2018 at 10:09 AM, Jim Lemon wrote: >> >> Hi Ogbos, >> This may help: >> >> # assume your data frame is named "oodf" >> 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(5,11), >> xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day") >> dispersion(-5:10,oomean,oose) >> >> Jim >> >> On Sat, Jun 23, 2018 at 4:35 PM, Ogbos Okike >> wrote: >> > Dear workers, >> > I have a data of length 1136. Below is the code I use to get the means >> > B. >> > It worked fine and I had the mean calculated and plotted. >> > >> > I wish to plot the error bars as well. I already plotted such means with >> > error bars before. Please see attached for example. >> > >> > I tried to redo the same plot but unlikely could not get around it as I >> > lost my system containing the script. >> > Among many attempts, I tried: >> > library(gplots) >> > >> > plotmeans(errors~AB,xlab="Factor A",ylab="mean errors", p=.68, >> > main="Main >> > effect Plot",barcol="black") >> > Nothing worked. >> > >> > I would really be thankful should somebody return me to the track. >> > Many, many thanks for your time. >> > Ogbos >> > >> > A sample of the data is: >> > S/N AB >> > 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 >> > 104 127415 >> > 115 123826 >> > 126 100029 >> > 137 76205 >> > 148 105162 >> > 159 119533 >> > 16 10 106490 >> > 17 -5 82322 >> > 18 -4 95591 >> > 19 -3 69378 >> > 20 -2 74281 >> > 21 -1 103261 >> > 220 92473 >> > 231 84344 >> > 242 127415 >> > 253 123826 >> > 264 100029 >> > 275 76205 >> > 286 105162 >> > 297 119533 >> > 308 106490 >> > 319 114771 >> > 32 10 55593 >> > 33 -5 85694 >> > 34 -4 65205 >> > 35 -3 80995 >> > 36 -2 51723 >> > 37 -1 62310 >> > 380 53401 >> > 391 65677 >> > 402 76094 >> > 413 64035 >> > 424 68290 >> > 435 73306 >> > 446 82176 >> > 457 75566 >> > 468 89762 >> > 479 88063 >> > 48 10 94395 >> > 49 -5 80651 >> > 50 -4 81291 >> > 51 -3 63702 >> > 52 -2 70297 >> > 53 -1 64117 >> > 540 71219 >> > 551 57354 >> > 562 62111 >> > 573 42252 >> > 584 35454 >> > 595 33469 >> > 606 38899 >> > 617 64981 >> > 628 85694 >> > 639 79452 >> > 64 10 85216 >> > 65 -5 71219 >> > 66 -4 57354 >> > 67 -3 62111 >> > 68 -2 42252 >> > 69 -1 35454 >> > 700 33469 >> > 711 38899 >> > 722 64981 >> > 733 85694 >> > 744 79452 >> > 755 85216 >> > 766 81721 >> > 777 91231 >> > 788 107074 >> > 799 108103 >> > 80 10 7576 >> > >> > A<-matrix(rep(-5:10,71)) >> > B<-matrix(data) >> > AB<-data.frame(A,B) >> > >> > x= B >> > >> > f<-factor(A) >> > AB<- tapply(x,f,mean) >> > x<--5:10 >> > plot(x,AB,type="l") >> > >> > __ >> > R-help@r-project.org 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. >> > > > __ R-help@r-project.org 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.
Re: [R] tapply and error bars
Hi Ogbos, This may help: # assume your data frame is named "oodf" 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(5,11), xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day") dispersion(-5:10,oomean,oose) Jim On Sat, Jun 23, 2018 at 4:35 PM, Ogbos Okike wrote: > Dear workers, > I have a data of length 1136. Below is the code I use to get the means B. > It worked fine and I had the mean calculated and plotted. > > I wish to plot the error bars as well. I already plotted such means with > error bars before. Please see attached for example. > > I tried to redo the same plot but unlikely could not get around it as I > lost my system containing the script. > Among many attempts, I tried: > library(gplots) > > plotmeans(errors~AB,xlab="Factor A",ylab="mean errors", p=.68, main="Main > effect Plot",barcol="black") > Nothing worked. > > I would really be thankful should somebody return me to the track. > Many, many thanks for your time. > Ogbos > > A sample of the data is: > S/N AB > 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 > 104 127415 > 115 123826 > 126 100029 > 137 76205 > 148 105162 > 159 119533 > 16 10 106490 > 17 -5 82322 > 18 -4 95591 > 19 -3 69378 > 20 -2 74281 > 21 -1 103261 > 220 92473 > 231 84344 > 242 127415 > 253 123826 > 264 100029 > 275 76205 > 286 105162 > 297 119533 > 308 106490 > 319 114771 > 32 10 55593 > 33 -5 85694 > 34 -4 65205 > 35 -3 80995 > 36 -2 51723 > 37 -1 62310 > 380 53401 > 391 65677 > 402 76094 > 413 64035 > 424 68290 > 435 73306 > 446 82176 > 457 75566 > 468 89762 > 479 88063 > 48 10 94395 > 49 -5 80651 > 50 -4 81291 > 51 -3 63702 > 52 -2 70297 > 53 -1 64117 > 540 71219 > 551 57354 > 562 62111 > 573 42252 > 584 35454 > 595 33469 > 606 38899 > 617 64981 > 628 85694 > 639 79452 > 64 10 85216 > 65 -5 71219 > 66 -4 57354 > 67 -3 62111 > 68 -2 42252 > 69 -1 35454 > 700 33469 > 711 38899 > 722 64981 > 733 85694 > 744 79452 > 755 85216 > 766 81721 > 777 91231 > 788 107074 > 799 108103 > 80 10 7576 > > A<-matrix(rep(-5:10,71)) > B<-matrix(data) > AB<-data.frame(A,B) > > x= B > > f<-factor(A) > AB<- tapply(x,f,mean) > x<--5:10 > plot(x,AB,type="l") > > __ > R-help@r-project.org 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. > __ R-help@r-project.org 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.