Re: [R] Can't Get Lattice Histogram Minor Tick Marks to Work

2018-04-24 Thread Duncan Mackay
Hi

You may need to make a custom function for yscale.components; I think there
is an example in the help guides
Also have a look at
https://stat.ethz.ch/pipermail/r-help/2007-June/134524.html 

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350

 

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Donald
Macnaughton
Sent: Wednesday, 25 April 2018 14:13
To: 'Jeff Newmiller'; 'R-Help'
Subject: Re: [R] Can't Get Lattice Histogram Minor Tick Marks to Work

Thanks Jeff, 

I attached a file with the program to my earlier email because the posting
guide seemed to imply that non-binary attachments would work. But I see that
the file was stripped off. 

I installed the program file on a web site, but when I downloaded it, the
line breaks were stripped out. So I've included the program below:

---

# This R program illustrates a problem with the histogram function in 
# the lattice package.
# This program requires the  latticeExtra  package to be installed to
# generate the minor tickmarks.

library(lattice)
library(latticeExtra)  

# First, please run the program to see the problem.

# Note how the histogram shows minor tickmarks on the vertical axis. 
# I would like to show only a SINGLE minor tickmark between major tickmarks
on
# the vertical axis, which helps to show the viewer that all the bars
# in the left panel are at five percent.

# The yscale.components.subticks function in the latticeExtras package
# has arguments to contol the minor tickmarks, but I can't get them to work.
# How can a get a single minor tickmark between the major tickmarks on
# the vertical axis?

# Thanks for your help,

# Don Macnaughton don...@matstat.com


# Generate data in an 20 x 2 matrix for left panel. In my real application 
# the data file contains many more rows, but that's not necessary here.
for (i in 1:20) {
if (i == 1) {pmat = c(0.045,0)} else {
 pmat = rbind(pmat,c(i*0.05-0.001,0))}
}

# Generate data for the right panel in the same matrix.
counts = c(90, 12.5, 9, 8, 7, 6.5, 6, 5.5, 5, 4.5, 
   4, 3.5, 3, 2.8, 2.2, 2, 1.8, 1.6, 1.4, 1.0)
for (i in 1:20) {
maxCount = 100 * counts[i]
for (j in 1:maxCount){
pmat = rbind( pmat, c(i*0.05-0.001,2) )
 }
}

# Convert the matrix to a data frame and add column names.
pDat = data.frame(pmat)
colnames(pDat) = c("pValue","nonCent")


# Create a factor to enable titles on the two panels.
nonCent.f = factor(pDat$nonCent, 
  labels=c("Noncentrality = 0.0", "Noncentrality = 2.0"))

# Use the lattice histogram function to draw the histogram.
histogram( ~ pValue | nonCent.f, data = pDat, nint = 20,
   endpoints = c(0, 1), layout = c(2,1), 
   yscale.components=yscale.components.subticks,
   scales=list(alternating=FALSE,tck=c(1,0)),
   col="lightgray")

---


Don Macnaughton


-Original Message-
From: Jeff Newmiller  
Sent: Tuesday, April 24, 2018 11:28 PM
To: r-help@r-project.org; Donald Macnaughton ; R-Help

Subject: Re: [R] Can't Get Lattice Histogram Minor Tick Marks to Work

Per the Posting Guide, why didn't you post the reproducible R code example? 

On April 24, 2018 8:22:15 PM PDT, Donald Macnaughton 
wrote:
>I'm drawing a paneled histogram using the lattice package. I've 
>succeeded in adding minor tick marks to the vertical axis, but I can't 
>get the desired number of minor tick marks between the major tick 
>marks.
>
>I've attached a self-contained program to illustrate the problem.
>
>Thanks for your help,
>
>Don Macnaughton
>
>
>Here's my sessionInfo:
>
>R version 3.4.3 (2017-11-30)
>Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 
>(build 16299)
>
>Matrix products: default
>
>locale:
>[1] LC_COLLATE=English_United States.1252 
>[2] LC_CTYPE=English_United States.1252   
>[3] LC_MONETARY=English_United States.1252
>[4] LC_NUMERIC=C  
>[5] LC_TIME=English_United States.1252
>
>attached base packages:
>[1] graphics  grDevices utils datasets  stats methods   base   
> 
>
>other attached packages:
>[1] psych_1.7.8 latticeExtra_0.6-28 RColorBrewer_1.1-2 
>[4] Hmisc_4.0-3 ggplot2_2.2.1   Formula_1.2-2  
>[7] survival_2.41-3 lattice_0.20-35
>
>loaded via a namespace (and not attached):
> [1] Rcpp_0.12.14pillar_1.0.1compiler_3.4.3 
> [4] plyr_1.8.4  base64enc_0.1-3 tools_3.4.3
> [7] rpart_4.1-11digest_0.6.13   nlme_3.1-131   
>[10] tibble_1.4.1gtable_0.2.0checkmate_1.8.5
>[13] htmlTable_1.11.1rlang_0.1.6 Matrix_1.2-12  
>[16] rstudioapi_0.7  parallel_3.4.3  gridExtra_2.3  
>[19] stringr_1.2.0   

Re: [R] Can't Get Lattice Histogram Minor Tick Marks to Work

2018-04-24 Thread Donald Macnaughton
Thanks Jeff, 

I attached a file with the program to my earlier email because the posting 
guide seemed to imply that non-binary attachments would work. But I see that 
the file was stripped off. 

I installed the program file on a web site, but when I downloaded it, the line 
breaks were stripped out. So I've included the program below:

---

# This R program illustrates a problem with the histogram function in 
# the lattice package.
# This program requires the  latticeExtra  package to be installed to
# generate the minor tickmarks.

library(lattice)
library(latticeExtra)  

# First, please run the program to see the problem.

# Note how the histogram shows minor tickmarks on the vertical axis. 
# I would like to show only a SINGLE minor tickmark between major tickmarks on
# the vertical axis, which helps to show the viewer that all the bars
# in the left panel are at five percent.

# The yscale.components.subticks function in the latticeExtras package
# has arguments to contol the minor tickmarks, but I can't get them to work.
# How can a get a single minor tickmark between the major tickmarks on
# the vertical axis?

# Thanks for your help,

# Don Macnaughton don...@matstat.com


# Generate data in an 20 x 2 matrix for left panel. In my real application 
# the data file contains many more rows, but that's not necessary here.
for (i in 1:20) {
if (i == 1) {pmat = c(0.045,0)} else {
 pmat = rbind(pmat,c(i*0.05-0.001,0))}
}

# Generate data for the right panel in the same matrix.
counts = c(90, 12.5, 9, 8, 7, 6.5, 6, 5.5, 5, 4.5, 
   4, 3.5, 3, 2.8, 2.2, 2, 1.8, 1.6, 1.4, 1.0)
for (i in 1:20) {
maxCount = 100 * counts[i]
for (j in 1:maxCount){
pmat = rbind( pmat, c(i*0.05-0.001,2) )
 }
}

# Convert the matrix to a data frame and add column names.
pDat = data.frame(pmat)
colnames(pDat) = c("pValue","nonCent")


# Create a factor to enable titles on the two panels.
nonCent.f = factor(pDat$nonCent, 
  labels=c("Noncentrality = 0.0", "Noncentrality = 2.0"))

# Use the lattice histogram function to draw the histogram.
histogram( ~ pValue | nonCent.f, data = pDat, nint = 20,
   endpoints = c(0, 1), layout = c(2,1), 
   yscale.components=yscale.components.subticks,
   scales=list(alternating=FALSE,tck=c(1,0)),
   col="lightgray")

---


Don Macnaughton


-Original Message-
From: Jeff Newmiller  
Sent: Tuesday, April 24, 2018 11:28 PM
To: r-help@r-project.org; Donald Macnaughton ; R-Help 

Subject: Re: [R] Can't Get Lattice Histogram Minor Tick Marks to Work

Per the Posting Guide, why didn't you post the reproducible R code example? 

On April 24, 2018 8:22:15 PM PDT, Donald Macnaughton  wrote:
>I'm drawing a paneled histogram using the lattice package. I've 
>succeeded in adding minor tick marks to the vertical axis, but I can't 
>get the desired number of minor tick marks between the major tick 
>marks.
>
>I've attached a self-contained program to illustrate the problem.
>
>Thanks for your help,
>
>Don Macnaughton
>
>
>Here's my sessionInfo:
>
>R version 3.4.3 (2017-11-30)
>Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 
>(build 16299)
>
>Matrix products: default
>
>locale:
>[1] LC_COLLATE=English_United States.1252 
>[2] LC_CTYPE=English_United States.1252   
>[3] LC_MONETARY=English_United States.1252
>[4] LC_NUMERIC=C  
>[5] LC_TIME=English_United States.1252
>
>attached base packages:
>[1] graphics  grDevices utils datasets  stats methods   base   
> 
>
>other attached packages:
>[1] psych_1.7.8 latticeExtra_0.6-28 RColorBrewer_1.1-2 
>[4] Hmisc_4.0-3 ggplot2_2.2.1   Formula_1.2-2  
>[7] survival_2.41-3 lattice_0.20-35
>
>loaded via a namespace (and not attached):
> [1] Rcpp_0.12.14pillar_1.0.1compiler_3.4.3 
> [4] plyr_1.8.4  base64enc_0.1-3 tools_3.4.3
> [7] rpart_4.1-11digest_0.6.13   nlme_3.1-131   
>[10] tibble_1.4.1gtable_0.2.0checkmate_1.8.5
>[13] htmlTable_1.11.1rlang_0.1.6 Matrix_1.2-12  
>[16] rstudioapi_0.7  parallel_3.4.3  gridExtra_2.3  
>[19] stringr_1.2.0   cluster_2.0.6   knitr_1.18 
>[22] htmlwidgets_0.9 grid_3.4.3  nnet_7.3-12
>[25] data.table_1.10.4-3 foreign_0.8-69  magrittr_1.5   
>[28] backports_1.1.2 scales_0.5.0htmltools_0.3.6
>[31] splines_3.4.3   mnormt_1.5-5colorspace_1.3-2   
>[34] stringi_1.1.6   acepack_1.4.1   lazyeval_0.2.1 
>[37] munsell_0.4.3
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
>https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] Can't Get Lattice Histogram Minor Tick Marks to Work

2018-04-24 Thread Jeff Newmiller
Per the Posting Guide, why didn't you post the reproducible R code example? 

On April 24, 2018 8:22:15 PM PDT, Donald Macnaughton  wrote:
>I'm drawing a paneled histogram using the lattice package. I've
>succeeded in
>adding minor tick marks to the vertical axis, but I can't get the
>desired
>number of minor tick marks between the major tick marks. 
>
>I've attached a self-contained program to illustrate the problem.
>
>Thanks for your help,
>
>Don Macnaughton
>
>
>Here's my sessionInfo:
>
>R version 3.4.3 (2017-11-30)
>Platform: x86_64-w64-mingw32/x64 (64-bit)
>Running under: Windows 10 x64 (build 16299)
>
>Matrix products: default
>
>locale:
>[1] LC_COLLATE=English_United States.1252 
>[2] LC_CTYPE=English_United States.1252   
>[3] LC_MONETARY=English_United States.1252
>[4] LC_NUMERIC=C  
>[5] LC_TIME=English_United States.1252
>
>attached base packages:
>[1] graphics  grDevices utils datasets  stats methods   base   
> 
>
>other attached packages:
>[1] psych_1.7.8 latticeExtra_0.6-28 RColorBrewer_1.1-2 
>[4] Hmisc_4.0-3 ggplot2_2.2.1   Formula_1.2-2  
>[7] survival_2.41-3 lattice_0.20-35
>
>loaded via a namespace (and not attached):
> [1] Rcpp_0.12.14pillar_1.0.1compiler_3.4.3 
> [4] plyr_1.8.4  base64enc_0.1-3 tools_3.4.3
> [7] rpart_4.1-11digest_0.6.13   nlme_3.1-131   
>[10] tibble_1.4.1gtable_0.2.0checkmate_1.8.5
>[13] htmlTable_1.11.1rlang_0.1.6 Matrix_1.2-12  
>[16] rstudioapi_0.7  parallel_3.4.3  gridExtra_2.3  
>[19] stringr_1.2.0   cluster_2.0.6   knitr_1.18 
>[22] htmlwidgets_0.9 grid_3.4.3  nnet_7.3-12
>[25] data.table_1.10.4-3 foreign_0.8-69  magrittr_1.5   
>[28] backports_1.1.2 scales_0.5.0htmltools_0.3.6
>[31] splines_3.4.3   mnormt_1.5-5colorspace_1.3-2   
>[34] stringi_1.1.6   acepack_1.4.1   lazyeval_0.2.1 
>[37] munsell_0.4.3
>__
>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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] Can't Get Lattice Histogram Minor Tick Marks to Work

2018-04-24 Thread Donald Macnaughton
I'm drawing a paneled histogram using the lattice package. I've succeeded in
adding minor tick marks to the vertical axis, but I can't get the desired
number of minor tick marks between the major tick marks. 

I've attached a self-contained program to illustrate the problem.

Thanks for your help,

Don Macnaughton


Here's my sessionInfo:

R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C  
[5] LC_TIME=English_United States.1252

attached base packages:
[1] graphics  grDevices utils datasets  stats methods   base 

other attached packages:
[1] psych_1.7.8 latticeExtra_0.6-28 RColorBrewer_1.1-2 
[4] Hmisc_4.0-3 ggplot2_2.2.1   Formula_1.2-2  
[7] survival_2.41-3 lattice_0.20-35

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14pillar_1.0.1compiler_3.4.3 
 [4] plyr_1.8.4  base64enc_0.1-3 tools_3.4.3
 [7] rpart_4.1-11digest_0.6.13   nlme_3.1-131   
[10] tibble_1.4.1gtable_0.2.0checkmate_1.8.5
[13] htmlTable_1.11.1rlang_0.1.6 Matrix_1.2-12  
[16] rstudioapi_0.7  parallel_3.4.3  gridExtra_2.3  
[19] stringr_1.2.0   cluster_2.0.6   knitr_1.18 
[22] htmlwidgets_0.9 grid_3.4.3  nnet_7.3-12
[25] data.table_1.10.4-3 foreign_0.8-69  magrittr_1.5   
[28] backports_1.1.2 scales_0.5.0htmltools_0.3.6
[31] splines_3.4.3   mnormt_1.5-5colorspace_1.3-2   
[34] stringi_1.1.6   acepack_1.4.1   lazyeval_0.2.1 
[37] munsell_0.4.3
__
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: [ESS] ess-dump-object-into-edit-buffer

2018-04-24 Thread Patrick Connolly
On Tue, 24-Apr-2018 at 08:20AM -0400, Ista Zahn wrote:

|> On Tue, Apr 24, 2018 at 4:13 AM, Patrick Connolly
|>  wrote:
|> > On Mon, 16-Apr-2018 at 09:02AM -0400, Ista Zahn wrote:
|> >
|> > [...]
|> >
|> > |> This suggests to me that you did _not_ start with emacs -q, so indeed
|> > |> you should start looking at your configuration to see where the
|> > |> problem is. Did you try commenting out the 'ess-source-directory'
|> > |> setting to see if that is the problem?
|> >
|> > I tried that, half-expecting it to make the difference.  But it didn't
|> > -- which was only half-unexpected.  However, I *still* get the problem
|> > even starting with emacs -q.  That was completely unexpected since it
|> > would indicate that the problem is not with my .emacs file.
|> >
|> > Where else is there to investigate?  It's getting curiouser and
|> > curiouser.
|> 
|> Hi Patrick,
|> 
|> What I've been trying to tell you is that we need explicit
|> step-by-step instructions for reproducing the problem, as well as the
|> details of your set up such as operating system and emacs and ess
|> versions. Basically, please provide a standard, reproducible, and
|> complete bugreport.

Well, I thought I did that with what I posted on 16/4/18, though I did
neglect to give the system information:

GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.8)
 of 2017-09-20 on lcy01-35, modified by Debian

ess-17.11 

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

Matrix products: default
BLAS: /home/pat/local/R-3.4.4/lib/libRblas.so
LAPACK: /home/pat/local/R-3.4.4/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_NZ.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_NZ.UTF-8LC_COLLATE=en_NZ.UTF-8
 [5] LC_MONETARY=en_NZ.UTF-8LC_MESSAGES=en_NZ.UTF-8   
 [7] LC_PAPER=en_NZ.UTF-8   LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_NZ.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] utils stats grDevices graphics  methods   base 

other attached packages:
[1] lattice_0.20-35

loaded via a namespace (and not attached):
 [1] compiler_3.4.4   magrittr_1.5   
https://www.antiaging-systems.com/articles/31-bec-5-the-treatment-of-choice-for-non-melanoma-skin-cancers
  assertthat_0.2.0 R6_2.2.1
 [5] tools_3.4.4  pillar_1.2.1 bindrcpp_0.2.2   glue_1.2.0  
 [9] dplyr_0.7.4  tibble_1.4.2 Rcpp_0.12.16 grid_3.4.4  
[13] pkgconfig_2.0.1  rlang_0.2.0  bindr_0.1.1 
> 


best
Patrick


-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R] Rolling window difference for zoo time series

2018-04-24 Thread Achim Zeileis

On Tue, 24 Apr 2018, Eric Berger wrote:


Zoo_TS/lag(Zoo_TS) - 1


Or:

diff(Zoo_TS, arithmetic = FALSE) - 1



On Tue, Apr 24, 2018 at 9:29 PM, Christofer Bogaso <
bogaso.christo...@gmail.com> wrote:


Hi,

I have a 'zoo' time series as below :

Zoo_TS = zoo(5:1, as.Date(Sys.time())+0:4)

Now I want to calculate First order difference of order 1, rolling
window basis i.e.

(Zoo_TS[2] - Zoo_TS[1] ) / Zoo_TS[1]
(Zoo_TS[3] - Zoo_TS[2] ) / Zoo_TS[2]
.

Is there any direct function available to achieve this?

Thanks,

__
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.



[[alternative HTML version deleted]]

__
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] Copy text from Script syntax into .txt

2018-04-24 Thread Greg Snow
Look at the spin and stitch functions in the knitr package if you want
to process an existing script into an output that mixes the code run
with the output.

Look at the txtStart and related functions in the TeachingDemos
package if you want the code and output saved in a file from a session
where you are typing in commands.

If in general you want text, code, and output mixed, learn the knitr
and/or rmarkdown packages for how to write a file that can be
processed into a report.  Also consider learning about RStudio
notebook documents where you can have the output mixed into the
"script" file.

On Tue, Apr 24, 2018 at 3:23 AM, P. Roberto Bakker
 wrote:
> Hi everybody,
>
> How can I get text from RScript (e.g. syntax, reminder) into the result
> text.
> Sink() does not do that - I only read the results and therefore I have to
> 'guess' which syntax was used where - reminders I wrote are lost.
>
> Bw and thank you in advance,
>
> Roberto
>
> [[alternative HTML version deleted]]
>
> __
> 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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

__
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] Rolling window difference for zoo time series

2018-04-24 Thread Eric Berger
Zoo_TS/lag(Zoo_TS) - 1


On Tue, Apr 24, 2018 at 9:29 PM, Christofer Bogaso <
bogaso.christo...@gmail.com> wrote:

> Hi,
>
> I have a 'zoo' time series as below :
>
> Zoo_TS = zoo(5:1, as.Date(Sys.time())+0:4)
>
> Now I want to calculate First order difference of order 1, rolling
> window basis i.e.
>
> (Zoo_TS[2] - Zoo_TS[1] ) / Zoo_TS[1]
> (Zoo_TS[3] - Zoo_TS[2] ) / Zoo_TS[2]
> .
>
> Is there any direct function available to achieve this?
>
> Thanks,
>
> __
> 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.
>

[[alternative HTML version deleted]]

__
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] Rolling window difference for zoo time series

2018-04-24 Thread Christofer Bogaso
Hi,

I have a 'zoo' time series as below :

Zoo_TS = zoo(5:1, as.Date(Sys.time())+0:4)

Now I want to calculate First order difference of order 1, rolling
window basis i.e.

(Zoo_TS[2] - Zoo_TS[1] ) / Zoo_TS[1]
(Zoo_TS[3] - Zoo_TS[2] ) / Zoo_TS[2]
.

Is there any direct function available to achieve this?

Thanks,

__
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] TukeyHSD and glht differ for models with a covariate

2018-04-24 Thread Nicholas Negovetich
I have a question about TukeyHSD and the glht function because I'm 
getting different answers when a covariate is included in model for 
ANCOVA.  I'm using the cabbages dataset in the 'MASS' package for 
repeatability.  If I include HeadWt as a covariate, then I get different 
answers when performing multiple comparisons using TukeyHSD and the glht 
function. The difference appears related to the predicted means used in 
the Tukey posthoc test. The glht function uses the marginal means, which 
I can obtain using the effect function in the 'effects' package.  
TukeyHSD generates the means using the model.tables function.  Per the 
help file, "the implementation is incomplete, and only simpler cases 
have been tested thoroughly". Does this mean that TukeyHSD shouldn't be 
used when covariates are included in the model? Could anyone elaborate 
on why the model.tables function is generating means that differ from 
the effect function?  Thanks...


#
# Load libraries and data
library(multcomp)
library(effects)
data(cabbages, package='MASS')

#create the model
mod1 <- lm(VitC~HeadWt+Cult+Date, data=cabbages)

# Using TukeyHSD
TukeyHSD(aov(mod1), which='Date')

#  Tukey multiple comparisons of means
#   95% family-wise confidence level
#
#Fit: aov(formula = mod1)
#
#$Date
#  diff    lwr  upr p adj
#d20-d16 -0.9216847 -5.5216345 3.678265 0.8797985
#d21-d16  3.4237706 -1.1761792 8.023720 0.1814431
#d21-d20  4.3454553 -0.2544945 8.945405 0.0678038

# Tukey contrasts in glht should generate the same difference in means, 
but it does not

summary(glht(mod1, linfct=mcp(Date='Tukey')))

#
# Simultaneous Tests for General Linear Hypotheses
#
#Multiple Comparisons of Means: Tukey Contrasts
#
#
#Fit: lm(formula = VitC ~ HeadWt + Cult + Date, data = cabbages)
#
#Linear Hypotheses:
#   Estimate Std. Error t value Pr(>|t|)
#d20 - d16 == 0   -1.213  1.926  -0.630   0.8042
#d21 - d16 == 0    4.186  2.018   2.074   0.1044
#d21 - d20 == 0    5.400  2.112   2.556   0.0351 *
#---
#Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#(Adjusted p values reported -- single-step method)

# Differences used for glht could be obtained with the effect function
effect('Date', mod1)

#
# Date effect
#Date
# d16  d20  d21
#56.95889 55.74578 61.14533

# model.tables() is used to generate the means for TukeyHSD
model.tables(aov(mod1), type='means')$tables$Date

#Date
# d16  d20  d21
#57.11597 56.19429 60.53974
#Warning message:
#In replications(paste("~", xx), data = mf) : non-factors ignored: HeadWt

__
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] TEST message

2018-04-24 Thread Ted Harding
Apologies for disturbance! Just checking that I can
get through to r-help.
Ted.

__
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] [FORGED] Extracting specified pages from a lattice ("trellis") object.

2018-04-24 Thread Duncan Mackay
Hi Rolf

do you need to use the  layout argument?

The layout is conditioned by the levels of a or unique values if not a factor. 
easier with factor

unique(dta$a)
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l"
data.frame( a= unique(dta$a), page = rep(1:3, ea = 4), col = 1:2,row  = 
rep(1:2, ea = 2))
   a page col row
1  a1   1   1
2  b1   2   1
3  c1   1   2
4  d1   2   2
5  e2   1   1
6  f2   2   1
7  g2   1   2
8  h2   2   2
9  i3   1   1
10 j3   2   1
11 k3   1   2
12 l3   2   2

I hope I have got the order right

full dataset
xyplot(y~x|a,data=dta)


 bar  = xyplot(y~x|a,data = subset(dta, a %in% c("e","f","g","h")) ))

print(bar)
(missed the dotplot requirement) but principle is the same.

you can use packet.number or which.packet if needed to make it simpler

use par.settings to do colours lines etc as well as spacing.

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rolf Turner
Sent: Tuesday, 24 April 2018 15:52
To: Paul Murrell
Cc: r-help@r-project.org; deepayan.sar...@r-project.org
Subject: Re: [R] [FORGED] Extracting specified pages from a lattice ("trellis") 
object.


On 24/04/18 15:17, Paul Murrell wrote:

> Hi
> 
> I think the subsetting works by giving you the panels for the 
> corresponding levels of the conditioning variable(s).  Note that, if 
> there is more than one conditioning variable, you will need more than 
> one subsetting index.
> 
> For example, taking this plot with two conditioning variables and 12 
> panels in total ...
> 
> dotplot(variety ~ yield | year * site, data=barley)
> 
> ... this produces three pages ...
> 
> dotplot(variety ~ yield | year * site, data=barley,
>  layout=c(2,2))
> 
> ... and this produces the second page (both panels for the first 
> conditioning variable and the third and fourth panels for the second 
> conditioning variable) ...
> 
> dotplot(variety ~ yield | year * site, data=barley,
>  layout=c(2,2))[1:2, 3:4]
> 
> Hope that helps.

Hmm.  Thanks Paul.  I may be able to work with that.  But what I really 
wanted was to take

 bar <- dotplot(variety ~ yield | year * site, data=barley)

and then do (something like)

 foo <- bar[]

so that foo contains only the second page of bar, and then do print(foo)
to get a plot of (just) the second page.  Without re-issuing a 
(modified) plot command.

Is that not at all possible?

cheers,

Rolf.

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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: [ESS] ess-dump-object-into-edit-buffer

2018-04-24 Thread Ista Zahn
On Tue, Apr 24, 2018 at 4:13 AM, Patrick Connolly
 wrote:
> On Mon, 16-Apr-2018 at 09:02AM -0400, Ista Zahn wrote:
>
> [...]
>
> |> This suggests to me that you did _not_ start with emacs -q, so indeed
> |> you should start looking at your configuration to see where the
> |> problem is. Did you try commenting out the 'ess-source-directory'
> |> setting to see if that is the problem?
>
> I tried that, half-expecting it to make the difference.  But it didn't
> -- which was only half-unexpected.  However, I *still* get the problem
> even starting with emacs -q.  That was completely unexpected since it
> would indicate that the problem is not with my .emacs file.
>
> Where else is there to investigate?  It's getting curiouser and
> curiouser.

Hi Patrick,

What I've been trying to tell you is that we need explicit
step-by-step instructions for reproducing the problem, as well as the
details of your set up such as operating system and emacs and ess
versions. Basically, please provide a standard, reproducible, and
complete bugreport.

Best,
Ista

>
> Thanks for looking into it.
>
> --
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>___Patrick Connolly
>  {~._.~}   Great minds discuss ideas
>  _( Y )_ Average minds discuss events
> (:_~*~_:)  Small minds discuss people
>  (_)-(_)  . Eleanor Roosevelt
>
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R] How to visualise what code is processed within a for loop

2018-04-24 Thread Luca Meyer
Hi Bob,

Thank you for your suggestion. Actually d0 is a dataframe, does that change
something in the code you propose?

Kind regards,

Luca

2018-04-24 10:19 GMT+02:00 Bob O'Hara :

> The loop never assigns anything to d0, only t. The first line makes t
> a character string "d0$V1" (or "d0$V2" etc.). The second line assigns
> either 0 or 1 to t.
>
> Looking at this, I don't think you've got into the R psychology (bad
> news if you want to use R, good news in many other ways). I assume d0
> is a list, so could you put the V's into a vector, and then just use
> this:
>
> d0$V <- sapply(d1[1:10,1], grepl, d0$X0)
>
> (I haven't checked it, but it looks,like it will do the trick. It
> returns a logical vector, so if you need integers, then use an
> as.numeric() around the right hand side. Or hope that R does type
> conversion for you when you need it)
>
> HTH
>
> Bob
>
> On 24 April 2018 at 09:30, Luca Meyer  wrote:
> > Hi,
> >
> > I am trying to debug the following code:
> >
> > for (i in 1:10){
> >   t <- paste("d0$V",i,sep="")
> >   t <- ifelse(regexpr(d1[i,1],d0$X0)>0,1,0)
> > }
> >
> > and I would like to see what code is actually processing R, how can I do
> > that?
> >
> > More to the point, I am trying to update my variables d0$V1 to d0$V10
> > according to the presence or absence of some text (contained in the file
> > d1) within the d0$X0 variable.
> >
> > The code seem to run ok, if I add print(table(t)) within the loop I can
> see
> > that the ifelse procedure is working and to some cases within the d0$V1
> to
> > d0$V10 variable range a 1 is assigned. But when checking my d0$V1 to
> d0$V10
> > after the for loop they are all still equal to zero...
> >
> > Thanks,
> >
> > Luca
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > 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.
>
>
>
> --
> Bob O'Hara
> NOTE NEW ADDRESS!!!
> Institutt for matematiske fag
> NTNU
> 7491 Trondheim
> Norway
>
> Mobile: +49 1515 888 5440
> Journal of Negative Results - EEB: www.jnr-eeb.org
>

[[alternative HTML version deleted]]

__
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] Copy text from Script syntax into .txt

2018-04-24 Thread Thierry Onkelinx
Dear Roberto,

The easiest way IMHO is to convert your script into an R markdown
document. See https://rmarkdown.rstudio.com/

Best regards,

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
AND FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkel...@inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be

///
To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey
///




2018-04-24 11:23 GMT+02:00 P. Roberto Bakker :
> Hi everybody,
>
> How can I get text from RScript (e.g. syntax, reminder) into the result
> text.
> Sink() does not do that - I only read the results and therefore I have to
> 'guess' which syntax was used where - reminders I wrote are lost.
>
> Bw and thank you in advance,
>
> Roberto
>
> [[alternative HTML version deleted]]
>
> __
> 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.


[R] Copy text from Script syntax into .txt

2018-04-24 Thread P. Roberto Bakker
Hi everybody,

How can I get text from RScript (e.g. syntax, reminder) into the result
text.
Sink() does not do that - I only read the results and therefore I have to
'guess' which syntax was used where - reminders I wrote are lost.

Bw and thank you in advance,

Roberto

[[alternative HTML version deleted]]

__
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] How to visualise what code is processed within a for loop

2018-04-24 Thread Bob O'Hara
The loop never assigns anything to d0, only t. The first line makes t
a character string "d0$V1" (or "d0$V2" etc.). The second line assigns
either 0 or 1 to t.

Looking at this, I don't think you've got into the R psychology (bad
news if you want to use R, good news in many other ways). I assume d0
is a list, so could you put the V's into a vector, and then just use
this:

d0$V <- sapply(d1[1:10,1], grepl, d0$X0)

(I haven't checked it, but it looks,like it will do the trick. It
returns a logical vector, so if you need integers, then use an
as.numeric() around the right hand side. Or hope that R does type
conversion for you when you need it)

HTH

Bob

On 24 April 2018 at 09:30, Luca Meyer  wrote:
> Hi,
>
> I am trying to debug the following code:
>
> for (i in 1:10){
>   t <- paste("d0$V",i,sep="")
>   t <- ifelse(regexpr(d1[i,1],d0$X0)>0,1,0)
> }
>
> and I would like to see what code is actually processing R, how can I do
> that?
>
> More to the point, I am trying to update my variables d0$V1 to d0$V10
> according to the presence or absence of some text (contained in the file
> d1) within the d0$X0 variable.
>
> The code seem to run ok, if I add print(table(t)) within the loop I can see
> that the ifelse procedure is working and to some cases within the d0$V1 to
> d0$V10 variable range a 1 is assigned. But when checking my d0$V1 to d0$V10
> after the for loop they are all still equal to zero...
>
> Thanks,
>
> Luca
>
> [[alternative HTML version deleted]]
>
> __
> 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.



-- 
Bob O'Hara
NOTE NEW ADDRESS!!!
Institutt for matematiske fag
NTNU
7491 Trondheim
Norway

Mobile: +49 1515 888 5440
Journal of Negative Results - EEB: www.jnr-eeb.org

__
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: [ESS] ess-dump-object-into-edit-buffer

2018-04-24 Thread Patrick Connolly
On Mon, 16-Apr-2018 at 09:02AM -0400, Ista Zahn wrote:

[...]

|> This suggests to me that you did _not_ start with emacs -q, so indeed
|> you should start looking at your configuration to see where the
|> problem is. Did you try commenting out the 'ess-source-directory'
|> setting to see if that is the problem?

I tried that, half-expecting it to make the difference.  But it didn't
-- which was only half-unexpected.  However, I *still* get the problem
even starting with emacs -q.  That was completely unexpected since it
would indicate that the problem is not with my .emacs file.

Where else is there to investigate?  It's getting curiouser and
curiouser.

Thanks for looking into it.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


[R] How to visualise what code is processed within a for loop

2018-04-24 Thread Luca Meyer
Hi,

I am trying to debug the following code:

for (i in 1:10){
  t <- paste("d0$V",i,sep="")
  t <- ifelse(regexpr(d1[i,1],d0$X0)>0,1,0)
}

and I would like to see what code is actually processing R, how can I do
that?

More to the point, I am trying to update my variables d0$V1 to d0$V10
according to the presence or absence of some text (contained in the file
d1) within the d0$X0 variable.

The code seem to run ok, if I add print(table(t)) within the loop I can see
that the ifelse procedure is working and to some cases within the d0$V1 to
d0$V10 variable range a 1 is assigned. But when checking my d0$V1 to d0$V10
after the for loop they are all still equal to zero...

Thanks,

Luca

[[alternative HTML version deleted]]

__
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.