Re: [R] font size in graphs...can R read Windows settings?

2016-07-27 Thread Duncan Mackay
Hi  Dan

For devices png, pdf, postscript and ? others the pointsize argument
controls the font size which is modified by cex

For lattice there are the settings in trellis.par.get()

trellis.par.get()$fontsize
$text
[1] 12

$points
[1] 8

which you can set and there is no real need to change font size except if
you need to change main.
trellis.par.get()$grid.pars  are the settings for grid elements if used  eg
text

these could be set globally by trellis.par.set() or individually with
argument par.settings eg
xyplot(y ~ x, data = datm,
 par.settings = list(strip.background = list(col =
"transparent"),
 fontsize = list(text = 16,
 
points = 12),  # large size;  need to refine   
superpose.polygon= list(col
= c("red","blue"),
 
border = c("red","blue"))),  
type = "b")

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
Daniel
Sent: Thursday, 28 July 2016 07:02
To: r-help@R-project.org (r-help@r-project.org)
Subject: [R] font size in graphs...can R read Windows settings?

Hi All,
I am putting together a package that (among other things) draws some nice
graphs for users. I place some explanatory text on figs using "text" and
"mtext". But the size of the text depends on the Windows display settings:
Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
panel | Appearance and personalization | Display | Make text and other
items smaller or larger). If I create figs that look good with one setting,
the text is too big (or too small) if another setting is used in Windows.
If I know the Windows setting, I can use cex in R to make the right sized
labels, but if I don't know a user's Windows display size setting...is
there a way for R to read the setting? Or is there another way to control
label size so that text labels on graphs look good regardless of WIndows
display size setting?

Many thanks for Ideas,

-Dan
-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] Lattice barchart legend with panel.barchart

2016-07-27 Thread Duncan Mackay
Hi

Following Pauls reply you may like to increase the panel space available by
using useOuterStrips which makes the smaller proportions easier to see and
compare
If you also wanted to change colours auto.key is the better option. Colours
are a bit garish 
See
 ?xyplot
and 
panel.barchart

library(latticeExtra) 

useOuterStrips(
barchart(Class~Freq|Sex + Age, Titan,
  groups=Survived,
  panel = titanpanel,
  par.settings = list(strip.background = list(col = "transparent"),
  superpose.polygon= list(col = c("red","blue"),
  border =
c("red","blue"))),
  stack=TRUE, layout=c(4,1),
  auto.key=list(title="Survived", text=levels(Titan$Survived),
rectangles=TRUE, points=FALSE, columns=2)
)
)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Seth Bigelow
Sent: Thursday, 28 July 2016 07:02
To: r-help@r-project.org
Subject: [R] Lattice barchart legend with panel.barchart

I have constructed a barchart that requires a panel call, but the panel
reduces the facsimiles of bars in the legend to small colored circles. You
can see this behavior in the following example:

Titan <- as.data.frame(Titanic)

titanpanel <- function(x,y,...){
panel.barchart(x,y,...)
}

barchart(Class~Freq|Sex + Age, Titan,
groups=Survived,
panel = titanpanel,
stack=TRUE, layout=c(4,1),
auto.key=list(title="Survived", columns=2))

...if you comment out the panel and run the barchart statement you will see
nice blocks displayed in the legend. Is there any easy way to retain these
blocks with panel.barchart?


-- 
Seth W. Bigelow, Ph.D.
Assistant Scientist of Forest Ecology
Joseph W. Jones Ecological Research Center
Newton, GA

[[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] [FORGED] Lattice barchart legend with panel.barchart

2016-07-27 Thread Seth Bigelow
Works great, thank you Paul!

On Wed, Jul 27, 2016 at 5:24 PM, Paul Murrell 
wrote:

> Hi
>
> Try this ...
>
> barchart(Class~Freq|Sex + Age, Titan,
>  groups=Survived,
>  panel = titanpanel,
>  stack=TRUE, layout=c(4,1),
>  key=simpleKey(title="Survived", text=levels(Titan$Survived),
>rectangles=TRUE, points=FALSE, columns=2))
>
> Paul
>
> On 28/07/16 09:02, Seth Bigelow wrote:
>
>> I have constructed a barchart that requires a panel call, but the panel
>> reduces the facsimiles of bars in the legend to small colored circles. You
>> can see this behavior in the following example:
>>
>> Titan <- as.data.frame(Titanic)
>>
>> titanpanel <- function(x,y,...){
>> panel.barchart(x,y,...)
>> }
>>
>> barchart(Class~Freq|Sex + Age, Titan,
>> groups=Survived,
>> panel = titanpanel,
>> stack=TRUE, layout=c(4,1),
>> auto.key=list(title="Survived", columns=2))
>>
>> ...if you comment out the panel and run the barchart statement you will
>> see
>> nice blocks displayed in the legend. Is there any easy way to retain these
>> blocks with panel.barchart?
>>
>>
>>
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> p...@stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/
>



-- 
Seth W. Bigelow, Ph.D.
Assistant Scientist of Forest Ecology
Joseph W. Jones Ecological Research Center
Newton, GA
(229)-734-4706 x-270

[[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] Aggregate matrix in a 2 by 2 manor

2016-07-27 Thread David Winsemius

> On Jul 27, 2016, at 12:02 PM, Jeff Newmiller  wrote:
> 
> An alternative (more compact, not necessarily faster, because apply is still 
> a for loop inside):
> 
> f <- function( m, nx, ny ) {
>  # redefine the dimensions of my
>  a <- array( m
> , dim = c( ny
>, nrow( m ) %/% ny
>, ncol( m ) %/% nx )
>)
>  # apply mean over dim 1
>  apply( a, c( 2, 3 ), FUN=mean )
> }
> f( tst, nx, ny )

Here's an apparently loopless strategy, although I suspect the code for 
interaction (and maybe tapply as well?) uses a loop.


tst_2X2 <- matrix(NA, ,ncol=4,nrow=2)

 tst_2x2[] <- tapply( tst, interaction( (row(tst)+1) %/% 2, (col(tst)+1) %/% 2 
), mean)

 tst_2x2

 [,1] [,2] [,3] [,4]
[1,]  3.5 11.5 19.5 27.5
[2,]  5.5 13.5 21.5 29.5

-- 
David.


> 
> -- 
> Sent from my phone. Please excuse my brevity.
> 
> On July 27, 2016 9:08:32 AM PDT, David L Carlson  wrote:
>> This should be faster. It uses apply() across the blocks. 
>> 
>>> ilon <- seq(1,8,nx)
>>> ilat <- seq(1,4,ny)
>>> cells <- as.matrix(expand.grid(ilat, ilon))
>>> blocks <- apply(cells, 1, function(x) tst[x[1]:(x[1]+1),
>> x[2]:(x[2]+1)])
>>> block.means <- colMeans(blocks)
>>> tst_2x2 <- matrix(block.means, 2, 4)
>>> tst_2x2
>>[,1] [,2] [,3] [,4]
>> [1,]  3.5 11.5 19.5 27.5
>> [2,]  5.5 13.5 21.5 29.5
>> 
>> -
>> David L Carlson
>> Department of Anthropology
>> Texas A University
>> College Station, TX 77840-4352
>> 
>> 
>> 
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-poject.org] On Behalf Of Anthoni,
>> Peter (IMK)
>> Sent: Wednesday, July 27, 2016 6:14 AM
>> To: r-help@r-project.org
>> Subject: [R] Aggregate matrix in a 2 by 2 manor
>> 
>> Hi all,
>> 
>> I need to aggregate some matrix data (1440x720) to a lower dimension
>> (720x360) for lots of years and variables
>> 
>> I can do double for loop, but that will be slow. Anybody know a quicker
>> way?
>> 
>> here an example with a smaller matrix size:
>> 
>> tst=matrix(1:(8*4),ncol=8,nrow=4)
>> tst_2x2=matrix(NA,ncol=4,nrow=2)
>> nx=2
>> ny=2
>> for(ilon in seq(1,8,nx)) {
>> for (ilat in seq(1,4,ny)) {
>>   ilon_2x2=1+(ilon-1)/nx
>>   ilat_2x2=1+(ilat-1)/ny
>>   tst_2x2[ilat_2x2,ilon_2x2] = mean(tst[ilat+0:1,ilon+0:1])
>> }
>> }
>> 
>> tst
>> tst_2x2
>> 
>>> tst
>>[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
>> [1,]159   13   17   21   25   29
>> [2,]26   10   14   18   22   26   30
>> [3,]37   11   15   19   23   27   31
>> [4,]48   12   16   20   24   28   32
>> 
>>> tst_2x2
>>[,1] [,2] [,3] [,4]
>> [1,]  3.5 11.5 19.5 27.5
>> [2,]  5.5 13.5 21.5 29.5
>> 
>> 
>> I though a cast to 3d-array might do the trick and apply over the new
>> dimension, but that does not work, since it casts the data along the
>> row.
>>> matrix(apply(array(tst,dim=c(nx,ny,8)),3,mean),nrow=nrow(tst)/ny)
>>[,1] [,2] [,3] [,4]
>> [1,]  2.5 10.5 18.5 26.5
>> [2,]  6.5 14.5 22.5 30.5
>> 
>> 
>> cheers
>> Peter
>> 
>> __
>> 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-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.

David Winsemius
Alameda, CA, USA

__
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] font size in graphs...can R read Windows settings?

2016-07-27 Thread Jeff Newmiller
What if it is being used on a platform other than Windows? This problem is more 
challenging than you seem to think it is. 

I would suggest including a kind of "par" argument to your function that lets 
the user change your defaults.
-- 
Sent from my phone. Please excuse my brevity.

On July 27, 2016 2:01:37 PM PDT, "Dalthorp, Daniel"  wrote:
>Hi All,
>I am putting together a package that (among other things) draws some
>nice
>graphs for users. I place some explanatory text on figs using "text"
>and
>"mtext". But the size of the text depends on the Windows display
>settings:
>Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
>panel | Appearance and personalization | Display | Make text and other
>items smaller or larger). If I create figs that look good with one
>setting,
>the text is too big (or too small) if another setting is used in
>Windows.
>If I know the Windows setting, I can use cex in R to make the right
>sized
>labels, but if I don't know a user's Windows display size setting...is
>there a way for R to read the setting? Or is there another way to
>control
>label size so that text labels on graphs look good regardless of
>WIndows
>display size setting?
>
>Many thanks for Ideas,
>
>-Dan

__
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] Reference for aov()

2016-07-27 Thread pdalgd
In general, some assembly is required. This stuff doesn't quit fit in a one 
page email. You may want to start playing around with model.matrix and qr() to 
see the light.

One tricky bit is how much you know already. There is some risk for me of 
having to rewrite a linear algebra textbook...

I'll assume that you know the betahat=(X'X)^{-1}X'y formula and the 
corresponding projection yhat = X (X'X)^{-1}X'y. Now assume that X is 
orthogonal, then X'X is the identity matrix so the whole thing becomes X X'Y = 
sum(x_i x_i'y) and the (uncorrected) sum of squares for regression is sum((x_i' 
y)^2). 

If you have an arbitrary design matrix X and orthgonalize it successively, then 
you have say Xtilde with the property that Xtilde is orthogonal and that, for 
any k, the first k columns of Xtilde spans the same subspace as the first k 
columns of X. This means that the projections onto the first k columns of X and 
the corresponding regression SS might as well be based on Xtilde and the 
simpler formulas for the orthogonal case. This also goes for differences 
between projections onto the first k1 and k2 columns.

In connection with stratified models, it happens that some terms of the 
systematic part are not estimable in all strata so e.g. in a paired design on 
individual subjects, you cannot estimate a gender effect from the 
within-subject stratum. This looks at differences within the same subject so a 
gender main effect cancels out. Technically, what happens is that the design 
matrix for the systematic model is projected (columnwise) onto each stratum and 
one or more of the resulting matrices may be singular, this is detected 
numerically and the corresponding terms are removed from the model. The 
difficulty here is to detect the aliasing reliably and get the DF right.

-pd



> On 27 Jul 2016, at 22:34 , Justin Thong  wrote:
> 
> Hi Peter, 
> 
> (EDIT)
> Thank you for your good answer. I am sorry for the late reply.
> 
> An ortogonalized model matrix generates a decomposition of the model space 
> into orthogonal subspaces corresponding to the terms of the model. 
> Projections onto each of the subspaces are easily worked out.  E.g., for a 
> two-way analysis (Y~row+col+row:col) you can decompose the model effect as a 
> row effect, a column effect, and an interaction effect. This allows 
> straightforward calculation of the sums of squares of the ANOVA table. As you 
> are probably well aware, if the design is unbalanced, the results will depend 
> on the order of terms -- col + row + col:row gives a different result.
> 
> It may be a stupid question. How are projections of each subspace easily 
> worked out and how does the sums of squares follow easily? Does it matter 
> that certain parameters of the model are not estimated. R appears to just 
> give a sums of squares despite some of the parameters being non-estimable.
> 
> Thank you 
> 
> On 27 July 2016 at 21:34, Justin Thong  wrote:
> Hi Peter, 
> 
> 
> Thank you for your good answer. I am sorry for the late reply.
> 
> An ortogonalized model matrix generates a decomposition of the model space 
> into orthogonal subspaces corresponding to the terms of the model. 
> Projections onto each of the subspaces are easily worked out.  E.g., for a 
> two-way analysis (Y~row+col+row:col) you can decompose the model effect as a 
> row effect, a column effect, and an interaction effect. This allows 
> straightforward calculation of the sums of squares of the ANOVA table. As you 
> are probably well aware, if the design is unbalanced, the results will depend 
> on the order of terms -- col + row + col:row gives a different result.
> 
> It may be a stupid question. How are projections of each sums of squares 
> easily worked out and how does the sums of squares follow easily? Does it 
> matter that certain parameters of the model are not estimated. R appears to 
> just give a sums of squares despite some of the parameters being 
> non-estimable.
> 
> Thank you 
> 
> 
> 
> 
> 
> On 14 July 2016 at 09:50, peter dalgaard  wrote:
> I am not aware of a detailed documentation of this beyond the actual source 
> code.
> However, the principles are fairly straightforward, except that the rules for 
> constructing the design matrix from the model formula can be a bit arcane at 
> times.
> 
> The two main tools are the design matrix constructor (model.matrix) and a 
> Gram-Schmidt type ortogonalization of its columns (the latter is called a QR 
> decomposition in R, which it is, but there are several algorithms for QR, and 
> the linear models codes depend on the QR algorithm being based on 
> orthogonalization - so LINPACK works and LAPACK doesn't).
> 
> An ortogonalized model matrix generates a decomposition of the model space 
> into orthogonal subspaces corresponding to the terms of the model. 
> Projections onto each of the subspaces are easily worked out.  E.g., for a 
> two-way analysis 

Re: [R] [FORGED] Lattice barchart legend with panel.barchart

2016-07-27 Thread Paul Murrell

Hi

Try this ...

barchart(Class~Freq|Sex + Age, Titan,
 groups=Survived,
 panel = titanpanel,
 stack=TRUE, layout=c(4,1),
 key=simpleKey(title="Survived", text=levels(Titan$Survived),
   rectangles=TRUE, points=FALSE, columns=2))

Paul

On 28/07/16 09:02, Seth Bigelow wrote:

I have constructed a barchart that requires a panel call, but the panel
reduces the facsimiles of bars in the legend to small colored circles. You
can see this behavior in the following example:

Titan <- as.data.frame(Titanic)

titanpanel <- function(x,y,...){
panel.barchart(x,y,...)
}

barchart(Class~Freq|Sex + Age, Titan,
groups=Survived,
panel = titanpanel,
stack=TRUE, layout=c(4,1),
auto.key=list(title="Survived", columns=2))

...if you comment out the panel and run the barchart statement you will see
nice blocks displayed in the legend. Is there any easy way to retain these
blocks with panel.barchart?




--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

__
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] Lattice barchart legend with panel.barchart

2016-07-27 Thread Seth Bigelow
I have constructed a barchart that requires a panel call, but the panel
reduces the facsimiles of bars in the legend to small colored circles. You
can see this behavior in the following example:

Titan <- as.data.frame(Titanic)

titanpanel <- function(x,y,...){
panel.barchart(x,y,...)
}

barchart(Class~Freq|Sex + Age, Titan,
groups=Survived,
panel = titanpanel,
stack=TRUE, layout=c(4,1),
auto.key=list(title="Survived", columns=2))

...if you comment out the panel and run the barchart statement you will see
nice blocks displayed in the legend. Is there any easy way to retain these
blocks with panel.barchart?


-- 
Seth W. Bigelow, Ph.D.
Assistant Scientist of Forest Ecology
Joseph W. Jones Ecological Research Center
Newton, GA

[[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] font size in graphs...can R read Windows settings?

2016-07-27 Thread Dalthorp, Daniel
Hi All,
I am putting together a package that (among other things) draws some nice
graphs for users. I place some explanatory text on figs using "text" and
"mtext". But the size of the text depends on the Windows display settings:
Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
panel | Appearance and personalization | Display | Make text and other
items smaller or larger). If I create figs that look good with one setting,
the text is too big (or too small) if another setting is used in Windows.
If I know the Windows setting, I can use cex in R to make the right sized
labels, but if I don't know a user's Windows display size setting...is
there a way for R to read the setting? Or is there another way to control
label size so that text labels on graphs look good regardless of WIndows
display size setting?

Many thanks for Ideas,

-Dan
-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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 on improving an algorithm

2016-07-27 Thread li li
Hi all,
 I have four matrix tmp_a, tmp_b, tmp_c and tmp_d whose dimensions are
shown as below.
I want to take one row from each of these matrices and then put the four
selected rows into a matrix.
I want to count the number of such matrices for which the vector of row sum
is less than or equal to (8,8,8,8,8) (componentwise).
Below is the code I use now. Is there a way to make this more efficient and
faster?
 Thanks for the help in advance.

> dim(tmp_a);dim(tmp_b); dim(tmp_c); dim(tmp_d)[1] 252   6
[1] 126   6
[1] 126   6
[1] 126   6


p <- 0
for (i in 1:dim(tmp_a)[1]){
for (j in 1:dim(tmp_b)[1]){
for (k in 1:dim(tmp_c)[1]){
for (l in 1:dim(tmp_c)[1]){
conti <- rbind(tmp_a[i,], tmp_b[j,], tmp_c[k,],tmp_d[l,])
if (sum(apply(conti,1,sum)>8)==0)
p <- p+1
print(p)

[[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] Reference for aov()

2016-07-27 Thread Justin Thong
Hi Peter,


Thank you for your good answer. I am sorry for the late reply.

*An ortogonalized model matrix generates a decomposition of the model space
into orthogonal subspaces corresponding to the terms of the model.
Projections onto each of the subspaces are easily worked out.  E.g., for a
two-way analysis (Y~row+col+row:col) you can decompose the model effect as
a row effect, a column effect, and an interaction effect. This allows
straightforward calculation of the sums of squares of the ANOVA table. As
you are probably well aware, if the design is unbalanced, the results will
depend on the order of terms -- col + row + col:row gives a different
result.*

It may be a stupid question. How are projections of each sums of squares
easily worked out and how does the sums of squares follow easily? Does it
matter that certain parameters of the model are not estimated. R appears to
just give a sums of squares despite some of the parameters being
non-estimable.

Thank you





On 14 July 2016 at 09:50, peter dalgaard  wrote:

> I am not aware of a detailed documentation of this beyond the actual
> source code.
> However, the principles are fairly straightforward, except that the rules
> for constructing the design matrix from the model formula can be a bit
> arcane at times.
>
> The two main tools are the design matrix constructor (model.matrix) and a
> Gram-Schmidt type ortogonalization of its columns (the latter is called a
> QR decomposition in R, which it is, but there are several algorithms for
> QR, and the linear models codes depend on the QR algorithm being based on
> orthogonalization - so LINPACK works and LAPACK doesn't).
>
> An ortogonalized model matrix generates a decomposition of the model space
> into orthogonal subspaces corresponding to the terms of the model.
> Projections onto each of the subspaces are easily worked out.  E.g., for a
> two-way analysis (Y~row+col+row:col) you can decompose the model effect as
> a row effect, a column effect, and an interaction effect. This allows
> straightforward calculation of the sums of squares of the ANOVA table. As
> you are probably well aware, if the design is unbalanced, the results will
> depend on the order of terms -- col + row + col:row gives a different
> result.
>
> What aov() does is that it first decomposes the observations according to
> the Error() term, forming the error strata, then fits the systematic part
> of the model to each stratum in turn. In the nice cases, each term of the
> model will be estimable in exactly one stratum, and part of the aov() logic
> is to detect and remove unestimable terms. E.g., if you have a balanced two
> way layout, say individual x treatment, the variable gender is a subfactor
> of individual, so Y ~ gender * treatment + Error(individual/treatment), the
> gender effect is estimated in the individual stratum, whereas treatment and
> gender:treatment are estimated in the individual:treatment stratum.
>
> It should be noted that it is very hard to interpret the results of aov()
> unless the Error() part of the model corresponds to a balanced experimental
> design. Or put more sharply: The model implied by the decomposition into
> error strata becomes nonsensical otherwise. If you do have a balanced
> design, the error strata reduce to simple combinations of means and
> observation, so the aov() algorithm is quite inefficient, but to my
> knowledge nobody has bothered to try and do better.
>
> -pd
>
> > On 13 Jul 2016, at 18:18 , Justin Thong  wrote:
> >
> > Hi
> >
> > *I have been looking for a reference to explain how R uses the aov
> > command(at a deeper level)*. More specifically, how R reads the formulae
> > and R computes the sums of squares. I am not interested in understanding
> > what the difference of Type 1,2,3 sum of squares are. I am more
> interested
> > in finding out about how R computes ~x1:x2:x3  or how R computes ~A:x1
> > emphasizing sequential nature of the way it computes, and models even
> more
> > complicated than this.
> >
> > Yours sincerely,
> > Justin
> >
> > *I check my email at 9AM and 4PM everyday*
> > *If you have an EMERGENCY, contact me at +447938674419(UK) or
> > +60125056192(Malaysia)*
> >
> >   [[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.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>


-- 
Yours sincerely,
Justin

*I check my email at 9AM and 4PM everyday*
*If you have an EMERGENCY, contact me at +447938674419(UK) or

Re: [R] Windows 10 Application Compatibility Check | FreeWare R Statistical Environment v3.2.2

2016-07-27 Thread John C Frain
Sorry if my earlier remarks were unfair to City but their request reminded
me of some problems that I had with using R, similar software and the
obstacles placed in my way by an IT Department many years ago. If it is of
any help I have R installed on a Desktop and two laptops (running 64-bit
Windows 10) and one very modest Tablet (running 32-bit Windows 10). Perhaps
I have been lucky as I have not encountered any problems.

Rstudio clearly supports Windows 10 (See supported packages on
https://www.rstudio.com/products/rstudio/download2/).  Microsoft have
"Microsoft R Open" (formerly Revolution R) available at
https://mran.revolutionanalytics.com/. These are based on a fixed CRAN
repository date. The version available there is said to be compatible
with Windows
7.0 (SP1), 8.1, 10 and Windows Server® 2008 R2 (SP1), 2012 (64-bit versions
only).


John C Frain
3 Aranleigh Park
Rathfarnham
Dublin 14
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@gmail.com

On 27 July 2016 at 17:09, Marc Schwartz  wrote:

> Hi,
>
> With the caveat that I speak for myself only, a few comments:
>
> 1. Given that Citi appears to have been running R on Windows 7 for some
> period of time, I am not sure that they are looking for reasons to deny
> users access to R. They are simply looking for some indication that R will
> run on Windows 10.
>
> 2. There is nothing presently in the relevant R for Windows FAQ:
>
>
> https://cran.r-project.org/bin/windows/base/rw-FAQ.html#Does-R-run-under-Windows-Vista_003f
>
> that explicitly indicates that R will run on Windows 10. At some point,
> presumably, that would be updated to reflect more recent experience by R
> Core.
>
> 3. Besides Robert's comment below on his experience (n of 1), there are
> other comments that I see via a Google search that would suggest that his
> experience is not unique (e.g. https://rpubs.com/kartykr/rrproject) and
> there are threads in the R-Help archives from last September:
>
>   https://stat.ethz.ch/pipermail/r-help/2015-September/431809.html
>   https://stat.ethz.ch/pipermail/r-help/2015-September/431825.html
>
> that also support the notion that R will run on Windows 10.
>
> 4. If Citi, wants to pursue a more "commercial-like" approach to paid
> support for R, there are commercial versions of R available, which I shall
> not mention here, but a quick Google search would avail them of more
> details.
>
> 5. Lastly and perhaps most importantly, R is not Freeware. R (as made
> available by the R Foundation) is free open source software (FOSS) and is
> distributed under relevant open source licenses. The label "Freeware",
> which typically refers to proprietary software, only means that the binary
> application itself is free of charge. It does not mean that the source code
> for the application is also available. There is a very large functional and
> philosophical difference between FOSS and Freeware.
>
> Regards,
>
> Marc Schwartz
>
>
> > On Jul 27, 2016, at 9:47 AM, John C Frain  wrote:
> >
> > When I first graduated some 50 years ago I worked in the Department of
> > Finance. On small piece of my work involved getting CPI data from the CSO
> > and doing some calculations. A specific person in the CSO (Central
> > Statistics Office) usually supplied this information and this fact was
> > always recorded on the file. On one occasion I could not contact that
> > person and I visited the department library and extracted the information
> > myself. When my boss saw that I had not contacted the CSO I was
> instructed
> > to contact them and repeat the calculation. It was explained to me that
> if
> > I contacted the CSO we could blame someone outside the Department of
> > Finance if they supplied the information.
> >
> > It appears that Citi Architecture & Technology Engineering are behaving
> in
> > a similar way.  Are they trying to find some excuse to deny their users
> > access to R on the grounds that it is not "properly" supported. This does
> > happen in large organisations.
> >
> > If any one knows of some organisation that is willing to provide support
> to
> > Citi (for a respectable fee) there might be a bit of money to be made.
> >
> > John C Frain
> > 3 Aranleigh Park
> > Rathfarnham
> > Dublin 14
> > Ireland
> > www.tcd.ie/Economics/staff/frainj/home.html
> > mailto:fra...@tcd.ie
> > mailto:fra...@gmail.com
> >
> > On 26 July 2016 at 23:49, Robert Baer  wrote:
> >
> >> Runs fine on Windows 10 for me.
> >>
> >>
> >> On 7/25/2016 7:18 AM, Ramar, Rohini wrote:
> >>
> >>> Hello Team,
> >>>
> >>> We are, Citi Application Readiness Team, need your assistance in order
> to
> >>> gather info about below application compatibility and support for Win
> 10 as
> >>> part of Window 10 Readiness initiative. CITI Bank has been using below
> >>> "FreeWare R Statistical Environment v3.2.2"  software products
> currently on
> >>> Win 7 operating system.
> >>>
> >>> We would 

Re: [R] how to create column names for the matrix

2016-07-27 Thread lily li
Thanks, this works. I thought the code should put in the for loop, but it
turns out an extra line.

On Wed, Jul 27, 2016 at 12:50 PM,  wrote:

> Hello,
>
> Try
>
>
> chars = c('A','B','C','D')
> matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
> k = 0
> for(i in 1:length(1:5)){  # or more simply just for(i in 1:5)
>   for(j in 1:length(chars)){
> k = k+1
> matrix1[,k] = k
>   }
> }
> matrix1
> tmp <- expand.grid(chars, 1:5, stringsAsFactors = FALSE)
> nms <- paste(tmp[[2]], tmp[[1]], sep = "-")
> rm(tmp)
> colnames(matrix1) <- nms
>
> head(matrix1)
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Citando lily li :
>
> Hi all,
>
> I want to ask that how to create column names for a matrix. For example,
> the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A, 2-B,
> 2-C, 2-D, 3-A, etc. Thanks for your help.
>
> chars = c('A','B','C','D')
> matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
> k = 0
> for(i in seq(1:length(1:5))){
> for(j in seq(1:length(chars))){
>k = k+1
>matrix1[,k] = c(1:100)[k]
> }
> }
>
> [[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.htmland 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.


Re: [R] Reduce woes

2016-07-27 Thread David Winsemius

> On Jul 27, 2016, at 8:20 AM, Stefan Kruger  wrote:
> 
> Hi -
> 
> I'm new to R.
> 
> In other functional languages I'm familiar with you can often seed a call
> to reduce() with a custom accumulator. Here's an example in Elixir:
> 
> map = %{"one" => [1, 1], "three" => [3], "two" => [2, 2]}
> map |> Enum.reduce(%{}, fn ({k,v}, acc) -> Map.update(acc, k,
> Enum.count(v), nil) end)
> # %{"one" => 2, "three" => 1, "two" => 2}
> 
> In R-terms that's reducing a list of vectors to become a new list mapping
> the names to the vector lengths.
> 
> Even in JavaScript, you can do similar things:
> 
> list = { one: [1, 1], three: [3], two: [2, 2] };
> var result = Object.keys(list).reduceRight(function (acc, item) {
>  acc[item] = list[item].length;
>  return acc;
> }, {});
> // result == { two: 2, three: 1, one: 2 }
> 
> In R, from what I can gather, Reduce() is restricted such that any init
> value you feed it is required to be of the same type as the elements of the
> vector you're reducing -- so I can't build up. So whilst I can do, say
> 
>> Reduce(function(acc, item) { acc + item }, c(1,2,3,4,5), 96)
> [1] 111
> 
> I can't use Reduce to build up a list, vector or data frame?
> 
> What am I missing?
> 
> Many thanks for any pointers,

This builds a list:

> Reduce(function(acc, item) { c(acc , item) }, c(1,2,3,4,5), 96, 
> accumulate=TRUE)
[[1]]
[1] 96

[[2]]
[1] 96  1

[[3]]
[1] 96  1  2

[[4]]
[1] 96  1  2  3

[[5]]
[1] 96  1  2  3  4

[[6]]
[1] 96  1  2  3  4  5

But you are not saying what you want. The other examples were doing something 
with names but you provided no names for the R example.

This would return a list of named vectors:

> Reduce(function(acc, item) { setNames( c(acc,item), 1:(item+1))  }, 
> c(1,2,3,4,5), 96, accumulate=TRUE)
[[1]]
[1] 96

[[2]]
 1  2 
96  1 

[[3]]
 1  2  3 
96  1  2 

[[4]]
 1  2  3  4 
96  1  2  3 

[[5]]
 1  2  3  4  5 
96  1  2  3  4 

[[6]]
 1  2  3  4  5  6 
96  1  2  3  4  5 




> Stefan
> 
> 
> 
> -- 
> Stefan Kruger 
> 
>   [[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.

David Winsemius
Alameda, CA, USA

__
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] Time format issue

2016-07-27 Thread David Winsemius

> On Jul 27, 2016, at 5:03 AM, Ismail SEZEN  wrote:
> 
> 
>>> The time column is factor. I want to convert each time to the following
>>> format:
>>> 
>>> 20111211003000
>>> 
>>> 20111211013000
>>> 
>>> 2011121102
>>> 
>>> (Year)(month)(date)(hr)(min)(sec)
>> 
>>> newTimeDt <- strptime(Time, format="%d%b%y:%H:%M")
>>> newTimeDt
>> [1] "2011-12-27 00:30:00 PST" "2011-12-27 01:30:00 PST" "2011-12-27 02:00:00 
>> PST"
>>> newTimeDt <- as.POSIXct(Time, format="%d%b%y:%H:%M")
>>> newTimeDt
>> [1] "2011-12-27 00:30:00 PST" "2011-12-27 01:30:00 PST" "2011-12-27 02:00:00 
>> PST"
>>> newOut <- format(newTimeDt, "%Y%m%d%H%M")
>>> newOut
>> [1] "201112270030" "201112270130" "201112270200"
>>> newOut <- format(newTimeDt, "%Y%m%d%H%M%S")
>>> newOut
>> [1] "20111227003000" "20111227013000" "2011122702"
> 
> Addition to David, if you use functions similar to read.csv or read.table to 
> read dates from a file, you have to set 
> 

I am not opposed to using stringsAsFactors=FALSE at the time of data input, but 
since there is an as.POSIXct.factor function it was not needed here.


> stringsAsFactors = T

Wrong: It would need to be FALSE to be anything other than the default. And you 
would not be reading Dates but rather character values.

> 
> in function parameters or set data.frame column as character seperately.

I did test my code on a factor vector.


-- 

David Winsemius
Alameda, CA, USA

__
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] Reducing execution time

2016-07-27 Thread jeremiah rounds
Correction to my code. I created a "doc" variable because I was thinking of
doing something faster, but I never did the change.  grep needed to work on
the original source "dat" to be used for counting.

 Fixed:

combs = structure(list(V1 = c(65L, 77L, 55L, 23L, 34L), V2 = c(23L, 34L,
34L, 77L, 65L), V3 = c(77L, 65L, 23L, 34L, 55L)), .Names = c("V1",
"V2", "V3"), class = "data.frame", row.names = c(NA, -5L))

dat = list(
c(77,65,34,23,55, 65,23,77, 44),
c(65,23,77,65,55,34, 77, 34,65, 10),
c(77,34,65),
c(55,78,56),
c(98,23,77,65,34, 65, 23, 77, 34))


words = unlist(apply(combs, 1 , function(d) paste(as.character(d),
collapse=" ")))
dat = lapply(dat, function(d) paste( as.character(d), collapse= " "))
#doc = paste(dat, collapse = " ## ") # just some arbitrary separator
character that isn't in your words
counts = sapply(words, function(w) length(grep(w, dat)))
names(counts) = words
counts
cbind(combs, data.frame(N = counts))


On Wed, Jul 27, 2016 at 11:27 AM, sri vathsan  wrote:

> Hi,
>
> It is not a just 79 triplets. As I said, there are 79 codes. I am making
> triplets out of that 79 codes and matching the triplets in the list.
>
> Please find the dput of the data below.
>
> > dput(head(newd,10))
> structure(list(uniq_id = c("1", "2", "3", "4", "5", "6", "7",
> "8", "9", "10"), hi = c("11,  22,  84,  85,  108,  111", "18,  84,  85,
> 87,  122,  134",
> "2,  18,  22", "18,  108,  122,  134,  176", "19,  85,  87,  100,  107",
> "79,  85,  111", "11,  88,  108", "19,  88,  96", "19,  85,  96",
> "19,  100,  103")), .Names = c("uniq_id", "hi"), row.names = c(NA,
> -10L), class = c("tbl_df", "tbl", "data.frame"))
> >
>
> I am trying to count the frequency of the triplets in the above data using
> the below code.
>
> # split column into a list
> myList <- strsplit(newd$hi, split=",")
> # get all pairwise combinations
> myCombos <- t(combn(unique(unlist(myList)), 3))
> # count the instances where the pair is present
> myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
>   sum(sapply(myList, function(j) {
> sum(!is.na(match(c(myCombos[i,]), j)))})==3)})
> #final matrix
> final <- cbind(matrix(as.integer(myCombos), nrow(myCombos)), myCounts)
>
> I hope I made my point clear. Please let me know if I miss anything.
>
> Regards,
> Sri
>
>
>
>
> On Wed, Jul 27, 2016 at 11:19 PM, Sarah Goslee 
> wrote:
>
> > You said you had 79 triplets and 8000 records.
> >
> > When I compared 100 triplets to 1 records it took 86 seconds.
> >
> > So obviously there is something you're not telling us about the format
> > of your data.
> >
> > If you use dput() to provide actual examples, you will get better
> > results than if we on Rhelp have to guess. Because we tend to guess in
> > ways that make the most sense after extensive R experience, and that's
> > probably not what you have.
> >
> > Sarah
> >
> > On Wed, Jul 27, 2016 at 1:29 PM, sri vathsan 
> wrote:
> > > Hi,
> > >
> > > Thanks for the solution. But I am afraid that after running this code
> > still
> > > it takes more time. It has been an hour and still it is executing. I
> > > understand the delay because each triplet has to compare almost 9000
> > > elements.
> > >
> > > Regards,
> > > Sri
> > >
> > > On Wed, Jul 27, 2016 at 9:02 PM, Sarah Goslee 
> > > wrote:
> > >>
> > >> Hi,
> > >>
> > >> It's really a good idea to use dput() or some other reproducible way
> > >> to provide data. I had to guess as to what your data looked like.
> > >>
> > >> It appears that order doesn't matter?
> > >>
> > >> Given than, here's one approach:
> > >>
> > >> combs <- structure(list(V1 = c(65L, 77L, 55L, 23L, 34L), V2 = c(23L,
> > 34L,
> > >> 34L, 77L, 65L), V3 = c(77L, 65L, 23L, 34L, 55L)), .Names = c("V1",
> > >> "V2", "V3"), class = "data.frame", row.names = c(NA, -5L))
> > >>
> > >> dat <- list(
> > >> c(77,65,34,23,55),
> > >> c(65,23,77,65,55,34),
> > >> c(77,34,65),
> > >> c(55,78,56),
> > >> c(98,23,77,65,34))
> > >>
> > >>
> > >> sapply(seq_len(nrow(combs)), function(i)sum(sapply(dat,
> > >> function(j)all(combs[i,] %in% j
> > >>
> > >> On a dataset of comparable time to yours, it takes me under a minute
> > and a
> > >> half.
> > >>
> > >> > combs <- combs[rep(1:nrow(combs), length=100), ]
> > >> > dat <- dat[rep(1:length(dat), length=1)]
> > >> >
> > >> > dim(combs)
> > >> [1] 100   3
> > >> > length(dat)
> > >> [1] 1
> > >> >
> > >> > system.time(test <- sapply(seq_len(nrow(combs)),
> > >> > function(i)sum(sapply(dat, function(j)all(combs[i,] %in% j)
> > >>user  system elapsed
> > >>  86.380   0.006  86.391
> > >>
> > >>
> > >>
> > >>
> > >> On Wed, Jul 27, 2016 at 10:47 AM, sri vathsan 
> > wrote:
> > >> > Hi,
> > >> >
> > >> > Apologizes for the less information.
> > >> >
> > >> > Basically, myCombos is a matrix with 3 variables which is a triplet
> > that
> > >> > is
> > >> > a combination of 79 codes. There are around 3lakh 

Re: [R] Reducing execution time

2016-07-27 Thread jeremiah rounds
If I understood the request this is the same programming  task as counting
words in a document and counting character sequences in a string or
matching bytes in byte arrays (though you don't want to go down that far)
 You can do something like what follows.  There are also vectorized greps
in stringr.

combs = structure(list(V1 = c(65L, 77L, 55L, 23L, 34L), V2 = c(23L, 34L,
34L, 77L, 65L), V3 = c(77L, 65L, 23L, 34L, 55L)), .Names = c("V1",
"V2", "V3"), class = "data.frame", row.names = c(NA, -5L))

dat = list(
c(77,65,34,23,55, 65,23,77, 44),
c(65,23,77,65,55,34, 77, 34,65, 10),
c(77,34,65),
c(55,78,56),
c(98,23,77,65,34, 65, 23, 77, 34))


words = unlist(apply(combs, 1 , function(d) paste(as.character(d),
collapse=" ")))
dat = lapply(dat, function(d) paste( as.character(d), collapse= " "))
doc = paste(dat, collapse = " ## ") # just some arbitrary separator
character that isn't in your words
counts = sapply(words, function(w) length(grep(w, doc)))
names(counts) = words
counts
cbind(combs, data.frame(N = counts))



On Wed, Jul 27, 2016 at 8:32 AM, Sarah Goslee 
wrote:

> Hi,
>
> It's really a good idea to use dput() or some other reproducible way
> to provide data. I had to guess as to what your data looked like.
>
> It appears that order doesn't matter?
>
> Given than, here's one approach:
>
> combs <- structure(list(V1 = c(65L, 77L, 55L, 23L, 34L), V2 = c(23L, 34L,
> 34L, 77L, 65L), V3 = c(77L, 65L, 23L, 34L, 55L)), .Names = c("V1",
> "V2", "V3"), class = "data.frame", row.names = c(NA, -5L))
>
> dat <- list(
> c(77,65,34,23,55),
> c(65,23,77,65,55,34),
> c(77,34,65),
> c(55,78,56),
> c(98,23,77,65,34))
>
>
> sapply(seq_len(nrow(combs)), function(i)sum(sapply(dat,
> function(j)all(combs[i,] %in% j
>
> On a dataset of comparable time to yours, it takes me under a minute and a
> half.
>
> > combs <- combs[rep(1:nrow(combs), length=100), ]
> > dat <- dat[rep(1:length(dat), length=1)]
> >
> > dim(combs)
> [1] 100   3
> > length(dat)
> [1] 1
> >
> > system.time(test <- sapply(seq_len(nrow(combs)),
> function(i)sum(sapply(dat, function(j)all(combs[i,] %in% j)
>user  system elapsed
>  86.380   0.006  86.391
>
>
>
>
> On Wed, Jul 27, 2016 at 10:47 AM, sri vathsan  wrote:
> > Hi,
> >
> > Apologizes for the less information.
> >
> > Basically, myCombos is a matrix with 3 variables which is a triplet that
> is
> > a combination of 79 codes. There are around 3lakh combination as such and
> > it looks like below.
> >
> > V1 V2 V3
> > 65 23 77
> > 77 34 65
> > 55 34 23
> > 23 77 34
> > 34 65 55
> >
> > Each triplet will compare in a list (mylist) having 8177 elements which
> > will looks like below.
> >
> > 77,65,34,23,55
> > 65,23,77,65,55,34
> > 77,34,65
> > 55,78,56
> > 98,23,77,65,34
> >
> > Now I want to count the no of occurrence of the triplet in the above
> list.
> > I.e., the triplet 65 23 77 is seen 3 times in the list. So my output
> looks
> > like below
> >
> > V1 V2 V3 Freq
> > 65 23 77  3
> > 77 34 65  4
> > 55 34 23  2
> >
> > I hope, I made it clear this time.
> >
> >
> > On Wed, Jul 27, 2016 at 7:00 PM, Bert Gunter 
> wrote:
> >
> >> Not entirely sure I understand, but match() is already vectorized, so
> you
> >> should be able to lose the supply(). This would speed things up a lot.
> >> Please re-read ?match *carefully* .
> >>
> >> Bert
> >>
> >> On Jul 27, 2016 6:15 AM, "sri vathsan"  wrote:
> >>
> >> Hi,
> >>
> >> I created list of 3 combination numbers (mycombos, around 3 lakh
> >> combinations) and counting the occurrence of those combination in
> another
> >> list. This comparision list (mylist) is having around 8000 records.I am
> >> using the following code.
> >>
> >> myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
> >>   sum(sapply(myList, function(j) {
> >> sum(!is.na(match(c(myCombos[i,]), j)))})==3)})
> >>
> >> The above code takes very long time to execute and is there any other
> >> effecting method which will reduce the time.
> >> --
> >>
> >> Regards,
> >> Srivathsan.K
> >>
>
> __
> 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.


Re: [R] Stack dataframes into a matrix

2016-07-27 Thread David Winsemius

> On Jul 27, 2016, at 8:56 AM, Anamika Chaudhuri  wrote:
> 
> 
> Y<-matrix(1:40,ncol=2)
> Y1<-Y/60 # estimates of p
> 
> #print(Y1)
> 
> sigma2<- 
> matrix(c(var(Y1[,1]),cov(Y1[,1],Y1[,2]),cov(Y1[,1],Y1[,2]),var(Y1[,2])),2,2)
> #print(sigma2)
> 
> rho<-sigma2[1,2]/sqrt(sigma2[1,1]*sigma2[2,2])
> #rho
> 
> mean(Y1[,1])
> mean(Y1[,2])
> 
> #within<-matrix(data=0,nrow=20,ncol=1)
> 
> for (rate3 in 1:20){
> 
> rate<-Y1[i,]
> #print(rate)
> 
> 
> rate1<-rate/(1-rate)
> 
> 
> rate2<-log(rate1)
> 
> 
> Sigma11<-(1/(rate[1]*(1-rate[1]))^2)*sigma2[1,1]
> Sigma22<-(1/(rate[2]*(1-rate[2]))^2)*sigma2[2,2]
> Sigma12<-(1/((rate[1]*(1-rate[1]))*(rate[2]*(1-rate[2]*sigma2[1,2]
> 
> Sigma2<-matrix(c(Sigma11,Sigma12,Sigma12,Sigma22),2,2)
> #print(Sigma2)
> 
> rate3<-mvrnorm(1000, mu=c(rate2[1],rate2[2]), Sigma2)
> 
> #print(rate3)
> 
> x<-exp(rate3[,1])/(1+exp(rate3[,1]))
> y<-exp(rate3[,2])/(1+exp(rate3[,2]))
> print(x) # Need to be able to stack the x's to produce one matrix
> }

Not reproducible. 
No loading of package for mvnorm (probably MASS) and suspect that you meant the 
loop to be over 'i' rather than 'rate3' since Y1[i,] throws an error. If my 
guesses are correct then perhaps:

require(MASS)
X <- matrix(NA, nrow=20, ncol=1000)  # predimentsion with NA's
Y<-matrix(1:40,ncol=2)
Y1<-Y/60 
sigma2<- 
matrix(c(var(Y1[,1]),cov(Y1[,1],Y1[,2]),cov(Y1[,1],Y1[,2]),var(Y1[,2])),2,2)
rho<-sigma2[1,2]/sqrt(sigma2[1,1]*sigma2[2,2])
mean(Y1[,1])
mean(Y1[,2])
for (rate3 in 1:20){

rate<-Y1[rate3,]
rate1<-rate/(1-rate)
rate2<-log(rate1)
Sigma11<-(1/(rate[1]*(1-rate[1]))^2)*sigma2[1,1]
Sigma22<-(1/(rate[2]*(1-rate[2]))^2)*sigma2[2,2]
Sigma12<-(1/((rate[1]*(1-rate[1]))*(rate[2]*(1-rate[2]*sigma2[1,2]

Sigma2<-matrix(c(Sigma11,Sigma12,Sigma12,Sigma22),2,2)
rate3<-mvrnorm(1000, mu=c(rate2[1],rate2[2]), Sigma2)
x<-exp(rate3[,1])/(1+exp(rate3[,1])) 

# this is not really "stacking" 
# because your code was overwriting x values each time through the loop.
 X[ rate3 , ] <- x   # save to single row at a time

y<-exp(rate3[,2])/(1+exp(rate3[,2]))  # not sure what you wanted to do with 
these
# print(x)# and DO NOT PRINT 1000 item vectors to screen!
}


David Winsemius
Alameda, CA, USA

__
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] Aggregate matrix in a 2 by 2 manor

2016-07-27 Thread Jeff Newmiller
An alternative (more compact, not necessarily faster, because apply is still a 
for loop inside):

f <- function( m, nx, ny ) {
  # redefine the dimensions of my
  a <- array( m
 , dim = c( ny
, nrow( m ) %/% ny
, ncol( m ) %/% nx )
)
  # apply mean over dim 1
  apply( a, c( 2, 3 ), FUN=mean )
}
f( tst, nx, ny )

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

On July 27, 2016 9:08:32 AM PDT, David L Carlson  wrote:
>This should be faster. It uses apply() across the blocks. 
>
>> ilon <- seq(1,8,nx)
>> ilat <- seq(1,4,ny)
>> cells <- as.matrix(expand.grid(ilat, ilon))
>> blocks <- apply(cells, 1, function(x) tst[x[1]:(x[1]+1),
>x[2]:(x[2]+1)])
>> block.means <- colMeans(blocks)
>> tst_2x2 <- matrix(block.means, 2, 4)
>> tst_2x2
> [,1] [,2] [,3] [,4]
>[1,]  3.5 11.5 19.5 27.5
>[2,]  5.5 13.5 21.5 29.5
>
>-
>David L Carlson
>Department of Anthropology
>Texas A University
>College Station, TX 77840-4352
>
>
>
>-Original Message-
>From: R-help [mailto:r-help-boun...@r-poject.org] On Behalf Of Anthoni,
>Peter (IMK)
>Sent: Wednesday, July 27, 2016 6:14 AM
>To: r-help@r-project.org
>Subject: [R] Aggregate matrix in a 2 by 2 manor
>
>Hi all,
>
>I need to aggregate some matrix data (1440x720) to a lower dimension
>(720x360) for lots of years and variables
>
>I can do double for loop, but that will be slow. Anybody know a quicker
>way?
>
>here an example with a smaller matrix size:
>
>tst=matrix(1:(8*4),ncol=8,nrow=4)
>tst_2x2=matrix(NA,ncol=4,nrow=2)
>nx=2
>ny=2
>for(ilon in seq(1,8,nx)) {
>  for (ilat in seq(1,4,ny)) {
>ilon_2x2=1+(ilon-1)/nx
>ilat_2x2=1+(ilat-1)/ny
>tst_2x2[ilat_2x2,ilon_2x2] = mean(tst[ilat+0:1,ilon+0:1])
>  }
>}
>
>tst
>tst_2x2
>
>> tst
> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
>[1,]159   13   17   21   25   29
>[2,]26   10   14   18   22   26   30
>[3,]37   11   15   19   23   27   31
>[4,]48   12   16   20   24   28   32
>
>> tst_2x2
> [,1] [,2] [,3] [,4]
>[1,]  3.5 11.5 19.5 27.5
>[2,]  5.5 13.5 21.5 29.5
>
>
>I though a cast to 3d-array might do the trick and apply over the new
>dimension, but that does not work, since it casts the data along the
>row.
>> matrix(apply(array(tst,dim=c(nx,ny,8)),3,mean),nrow=nrow(tst)/ny)
> [,1] [,2] [,3] [,4]
>[1,]  2.5 10.5 18.5 26.5
>[2,]  6.5 14.5 22.5 30.5
>
>
>cheers
>Peter
>
>__
>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-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 create column names for the matrix

2016-07-27 Thread Hervé Pagès

On 07/27/2016 11:49 AM, lily li wrote:

If replace 1:5 to char2 = c('east','west','south','north','central'),
how to put on column names with the original structure? Thanks again.


Have you tried to actually "replace 1:5 with char2", literally?

You need to try things before you ask. That's the only way to learn!

H.




On Wed, Jul 27, 2016 at 12:40 PM, Hervé Pagès > wrote:

Hi,


On 07/27/2016 11:17 AM, lily li wrote:

Hi all,

I want to ask that how to create column names for a matrix. For
example,
the matrix below, the column names should be: 1-A, 1-B, 1-C,
1-D, 2-A, 2-B,
2-C, 2-D, 3-A, etc. Thanks for your help.

chars = c('A','B','C','D')
matrix1 = matrix(nrow = length(1:100), ncol =
length(1:5)*length(chars))
k = 0
for(i in seq(1:length(1:5))){
  for(j in seq(1:length(chars))){
k = k+1
matrix1[,k] = c(1:100)[k]
  }
}


Also how could you possibly use such level of code obfuscation to
perform such simple initialization of your matrix?

My 1st advice would be that you slow down and take the time to compare
seq(1:length(1:5)) with 1:length(1:5) with 1:5. It will be a great
learning experience!

As for initializing your matrix, what about doing

  ncol <- 5 * length(chars)
  matrix1 <- matrix(seq_len(ncol), nrow=100, ncol=ncol, byrow=TRUE)

instead?

Then set the colnames with:

  colnames(matrix1) <- paste(rep(1:5, length(chars)), chars, sep="-")

Cheers,
H.


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


--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org 
Phone:  (206) 667-5791 
Fax:(206) 667-1319 




--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

__
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 create column names for the matrix

2016-07-27 Thread Hervé Pagès

I see. But please understand that initializing the values is not the
same as setting the colnames. How providing this almost-impossible-
to-read initialization code helps with respect to your question which
is about setting the colnames?

I know people often asked you to show the code in your previous
questions on this site. They're right: showing the code helps.
But only the code that is relevant to your question. Code that is
not relevant to your question is only distracting and confusing.

H.

On 07/27/2016 11:45 AM, lily li wrote:

Thanks. I shorten a more complex matrix to this example, but use the
original structure of the code. The original matrix has all characters
instead of 1:5.


On Wed, Jul 27, 2016 at 12:42 PM, Hervé Pagès > wrote:

On 07/27/2016 11:40 AM, Hervé Pagès wrote:

Hi,

On 07/27/2016 11:17 AM, lily li wrote:

Hi all,

I want to ask that how to create column names for a matrix.
For example,
the matrix below, the column names should be: 1-A, 1-B, 1-C,
1-D, 2-A,
2-B,
2-C, 2-D, 3-A, etc. Thanks for your help.

chars = c('A','B','C','D')
matrix1 = matrix(nrow = length(1:100), ncol =
length(1:5)*length(chars))
k = 0
for(i in seq(1:length(1:5))){
  for(j in seq(1:length(chars))){
k = k+1
matrix1[,k] = c(1:100)[k]
  }
}


Also how could you possibly use such level of code obfuscation to
perform such simple initialization of your matrix?

My 1st advice would be that you slow down and take the time to
compare
seq(1:length(1:5)) with 1:length(1:5) with 1:5. It will be a great
learning experience!

As for initializing your matrix, what about doing

  ncol <- 5 * length(chars)
  matrix1 <- matrix(seq_len(ncol), nrow=100, ncol=ncol, byrow=TRUE)

instead?

Then set the colnames with:

  colnames(matrix1) <- paste(rep(1:5, length(chars)), chars,
sep="-")


or maybe

  colnames(matrix1) <- paste(rep(1:5, each=length(chars)), chars,
sep="-")

is what you're after.

H.



Cheers,
H.


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



--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org 
Phone:  (206) 667-5791 
Fax:(206) 667-1319 




--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

__
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 create column names for the matrix

2016-07-27 Thread ruipbarradas
Hello,

Try

chars = c('A','B','C','D')
matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
k = 0
for(i in 1:length(1:5)){  # or more simply just for(i in 1:5)
  for(j in 1:length(chars)){
    k = k+1
    matrix1[,k] = k
  }
}
matrix1
tmp <- expand.grid(chars, 1:5, stringsAsFactors = FALSE)
nms <- paste(tmp[[2]], tmp[[1]], sep = "-")
rm(tmp)
colnames(matrix1) <- nms

head(matrix1)

Hope this helps,

Rui Barradas
 

Citando lily li :

> Hi all,
>
> I want to ask that how to create column names for a matrix. For example,
> the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A, 2-B,
> 2-C, 2-D, 3-A, etc. Thanks for your help.
>
> chars = c('A','B','C','D')
> matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
> k = 0
> for(i in seq(1:length(1:5))){
> for(j in seq(1:length(chars))){
>    k = k+1
>    matrix1[,k] = c(1:100)[k]
> }
> }
>
>         [[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.htmland 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.

Re: [R] how to create column names for the matrix

2016-07-27 Thread lily li
If replace 1:5 to char2 = c('east','west','south','north','central'), how
to put on column names with the original structure? Thanks again.


On Wed, Jul 27, 2016 at 12:40 PM, Hervé Pagès  wrote:

> Hi,
>
>
> On 07/27/2016 11:17 AM, lily li wrote:
>
>> Hi all,
>>
>> I want to ask that how to create column names for a matrix. For example,
>> the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A,
>> 2-B,
>> 2-C, 2-D, 3-A, etc. Thanks for your help.
>>
>> chars = c('A','B','C','D')
>> matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
>> k = 0
>> for(i in seq(1:length(1:5))){
>>   for(j in seq(1:length(chars))){
>> k = k+1
>> matrix1[,k] = c(1:100)[k]
>>   }
>> }
>>
>
> Also how could you possibly use such level of code obfuscation to
> perform such simple initialization of your matrix?
>
> My 1st advice would be that you slow down and take the time to compare
> seq(1:length(1:5)) with 1:length(1:5) with 1:5. It will be a great
> learning experience!
>
> As for initializing your matrix, what about doing
>
>   ncol <- 5 * length(chars)
>   matrix1 <- matrix(seq_len(ncol), nrow=100, ncol=ncol, byrow=TRUE)
>
> instead?
>
> Then set the colnames with:
>
>   colnames(matrix1) <- paste(rep(1:5, length(chars)), chars, sep="-")
>
> Cheers,
> H.
>
>
>> [[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.
>>
>>
> --
> Hervé Pagès
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: hpa...@fredhutch.org
> Phone:  (206) 667-5791
> Fax:(206) 667-1319
>

[[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 create column names for the matrix

2016-07-27 Thread lily li
Thanks. I shorten a more complex matrix to this example, but use the
original structure of the code. The original matrix has all characters
instead of 1:5.


On Wed, Jul 27, 2016 at 12:42 PM, Hervé Pagès  wrote:

> On 07/27/2016 11:40 AM, Hervé Pagès wrote:
>
>> Hi,
>>
>> On 07/27/2016 11:17 AM, lily li wrote:
>>
>>> Hi all,
>>>
>>> I want to ask that how to create column names for a matrix. For example,
>>> the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A,
>>> 2-B,
>>> 2-C, 2-D, 3-A, etc. Thanks for your help.
>>>
>>> chars = c('A','B','C','D')
>>> matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
>>> k = 0
>>> for(i in seq(1:length(1:5))){
>>>   for(j in seq(1:length(chars))){
>>> k = k+1
>>> matrix1[,k] = c(1:100)[k]
>>>   }
>>> }
>>>
>>
>> Also how could you possibly use such level of code obfuscation to
>> perform such simple initialization of your matrix?
>>
>> My 1st advice would be that you slow down and take the time to compare
>> seq(1:length(1:5)) with 1:length(1:5) with 1:5. It will be a great
>> learning experience!
>>
>> As for initializing your matrix, what about doing
>>
>>   ncol <- 5 * length(chars)
>>   matrix1 <- matrix(seq_len(ncol), nrow=100, ncol=ncol, byrow=TRUE)
>>
>> instead?
>>
>> Then set the colnames with:
>>
>>   colnames(matrix1) <- paste(rep(1:5, length(chars)), chars, sep="-")
>>
>
> or maybe
>
>   colnames(matrix1) <- paste(rep(1:5, each=length(chars)), chars, sep="-")
>
> is what you're after.
>
> H.
>
>
>
>> Cheers,
>> H.
>>
>>
>>> [[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.
>>>
>>>
>>
> --
> Hervé Pagès
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: hpa...@fredhutch.org
> Phone:  (206) 667-5791
> Fax:(206) 667-1319
>

[[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 create column names for the matrix

2016-07-27 Thread Hervé Pagès

On 07/27/2016 11:40 AM, Hervé Pagès wrote:

Hi,

On 07/27/2016 11:17 AM, lily li wrote:

Hi all,

I want to ask that how to create column names for a matrix. For example,
the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A,
2-B,
2-C, 2-D, 3-A, etc. Thanks for your help.

chars = c('A','B','C','D')
matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
k = 0
for(i in seq(1:length(1:5))){
  for(j in seq(1:length(chars))){
k = k+1
matrix1[,k] = c(1:100)[k]
  }
}


Also how could you possibly use such level of code obfuscation to
perform such simple initialization of your matrix?

My 1st advice would be that you slow down and take the time to compare
seq(1:length(1:5)) with 1:length(1:5) with 1:5. It will be a great
learning experience!

As for initializing your matrix, what about doing

  ncol <- 5 * length(chars)
  matrix1 <- matrix(seq_len(ncol), nrow=100, ncol=ncol, byrow=TRUE)

instead?

Then set the colnames with:

  colnames(matrix1) <- paste(rep(1:5, length(chars)), chars, sep="-")


or maybe

  colnames(matrix1) <- paste(rep(1:5, each=length(chars)), chars, sep="-")

is what you're after.

H.



Cheers,
H.



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





--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

__
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 create column names for the matrix

2016-07-27 Thread Hervé Pagès

Hi,

On 07/27/2016 11:17 AM, lily li wrote:

Hi all,

I want to ask that how to create column names for a matrix. For example,
the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A, 2-B,
2-C, 2-D, 3-A, etc. Thanks for your help.

chars = c('A','B','C','D')
matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
k = 0
for(i in seq(1:length(1:5))){
  for(j in seq(1:length(chars))){
k = k+1
matrix1[,k] = c(1:100)[k]
  }
}


Also how could you possibly use such level of code obfuscation to
perform such simple initialization of your matrix?

My 1st advice would be that you slow down and take the time to compare
seq(1:length(1:5)) with 1:length(1:5) with 1:5. It will be a great
learning experience!

As for initializing your matrix, what about doing

  ncol <- 5 * length(chars)
  matrix1 <- matrix(seq_len(ncol), nrow=100, ncol=ncol, byrow=TRUE)

instead?

Then set the colnames with:

  colnames(matrix1) <- paste(rep(1:5, length(chars)), chars, sep="-")

Cheers,
H.



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



--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

__
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] Reducing execution time

2016-07-27 Thread sri vathsan
Hi,

It is not a just 79 triplets. As I said, there are 79 codes. I am making
triplets out of that 79 codes and matching the triplets in the list.

Please find the dput of the data below.

> dput(head(newd,10))
structure(list(uniq_id = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10"), hi = c("11,  22,  84,  85,  108,  111", "18,  84,  85,
87,  122,  134",
"2,  18,  22", "18,  108,  122,  134,  176", "19,  85,  87,  100,  107",
"79,  85,  111", "11,  88,  108", "19,  88,  96", "19,  85,  96",
"19,  100,  103")), .Names = c("uniq_id", "hi"), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
>

I am trying to count the frequency of the triplets in the above data using
the below code.

# split column into a list
myList <- strsplit(newd$hi, split=",")
# get all pairwise combinations
myCombos <- t(combn(unique(unlist(myList)), 3))
# count the instances where the pair is present
myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
  sum(sapply(myList, function(j) {
sum(!is.na(match(c(myCombos[i,]), j)))})==3)})
#final matrix
final <- cbind(matrix(as.integer(myCombos), nrow(myCombos)), myCounts)

I hope I made my point clear. Please let me know if I miss anything.

Regards,
Sri




On Wed, Jul 27, 2016 at 11:19 PM, Sarah Goslee 
wrote:

> You said you had 79 triplets and 8000 records.
>
> When I compared 100 triplets to 1 records it took 86 seconds.
>
> So obviously there is something you're not telling us about the format
> of your data.
>
> If you use dput() to provide actual examples, you will get better
> results than if we on Rhelp have to guess. Because we tend to guess in
> ways that make the most sense after extensive R experience, and that's
> probably not what you have.
>
> Sarah
>
> On Wed, Jul 27, 2016 at 1:29 PM, sri vathsan  wrote:
> > Hi,
> >
> > Thanks for the solution. But I am afraid that after running this code
> still
> > it takes more time. It has been an hour and still it is executing. I
> > understand the delay because each triplet has to compare almost 9000
> > elements.
> >
> > Regards,
> > Sri
> >
> > On Wed, Jul 27, 2016 at 9:02 PM, Sarah Goslee 
> > wrote:
> >>
> >> Hi,
> >>
> >> It's really a good idea to use dput() or some other reproducible way
> >> to provide data. I had to guess as to what your data looked like.
> >>
> >> It appears that order doesn't matter?
> >>
> >> Given than, here's one approach:
> >>
> >> combs <- structure(list(V1 = c(65L, 77L, 55L, 23L, 34L), V2 = c(23L,
> 34L,
> >> 34L, 77L, 65L), V3 = c(77L, 65L, 23L, 34L, 55L)), .Names = c("V1",
> >> "V2", "V3"), class = "data.frame", row.names = c(NA, -5L))
> >>
> >> dat <- list(
> >> c(77,65,34,23,55),
> >> c(65,23,77,65,55,34),
> >> c(77,34,65),
> >> c(55,78,56),
> >> c(98,23,77,65,34))
> >>
> >>
> >> sapply(seq_len(nrow(combs)), function(i)sum(sapply(dat,
> >> function(j)all(combs[i,] %in% j
> >>
> >> On a dataset of comparable time to yours, it takes me under a minute
> and a
> >> half.
> >>
> >> > combs <- combs[rep(1:nrow(combs), length=100), ]
> >> > dat <- dat[rep(1:length(dat), length=1)]
> >> >
> >> > dim(combs)
> >> [1] 100   3
> >> > length(dat)
> >> [1] 1
> >> >
> >> > system.time(test <- sapply(seq_len(nrow(combs)),
> >> > function(i)sum(sapply(dat, function(j)all(combs[i,] %in% j)
> >>user  system elapsed
> >>  86.380   0.006  86.391
> >>
> >>
> >>
> >>
> >> On Wed, Jul 27, 2016 at 10:47 AM, sri vathsan 
> wrote:
> >> > Hi,
> >> >
> >> > Apologizes for the less information.
> >> >
> >> > Basically, myCombos is a matrix with 3 variables which is a triplet
> that
> >> > is
> >> > a combination of 79 codes. There are around 3lakh combination as such
> >> > and
> >> > it looks like below.
> >> >
> >> > V1 V2 V3
> >> > 65 23 77
> >> > 77 34 65
> >> > 55 34 23
> >> > 23 77 34
> >> > 34 65 55
> >> >
> >> > Each triplet will compare in a list (mylist) having 8177 elements
> which
> >> > will looks like below.
> >> >
> >> > 77,65,34,23,55
> >> > 65,23,77,65,55,34
> >> > 77,34,65
> >> > 55,78,56
> >> > 98,23,77,65,34
> >> >
> >> > Now I want to count the no of occurrence of the triplet in the above
> >> > list.
> >> > I.e., the triplet 65 23 77 is seen 3 times in the list. So my output
> >> > looks
> >> > like below
> >> >
> >> > V1 V2 V3 Freq
> >> > 65 23 77  3
> >> > 77 34 65  4
> >> > 55 34 23  2
> >> >
> >> > I hope, I made it clear this time.
> >> >
> >> >
> >> > On Wed, Jul 27, 2016 at 7:00 PM, Bert Gunter 
> >> > wrote:
> >> >
> >> >> Not entirely sure I understand, but match() is already vectorized, so
> >> >> you
> >> >> should be able to lose the supply(). This would speed things up a
> lot.
> >> >> Please re-read ?match *carefully* .
> >> >>
> >> >> Bert
> >> >>
> >> >> On Jul 27, 2016 6:15 AM, "sri vathsan"  wrote:
> >> >>
> >> >> Hi,
> >> >>
> >> >> I created list of 3 combination numbers (mycombos, around 3 lakh
> >> 

[R] how to create column names for the matrix

2016-07-27 Thread lily li
Hi all,

I want to ask that how to create column names for a matrix. For example,
the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A, 2-B,
2-C, 2-D, 3-A, etc. Thanks for your help.

chars = c('A','B','C','D')
matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
k = 0
for(i in seq(1:length(1:5))){
  for(j in seq(1:length(chars))){
k = k+1
matrix1[,k] = c(1:100)[k]
  }
}

[[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] Have any of you succesfully used VS Code with R? How have you set this up?

2016-07-27 Thread Ista Zahn
Hi Luis,

What features do you want? What did you try? What was missing?

I've not used VSCode, but for Atom check out
https://atom.io/packages/repl, https://atom.io/packages/language-r,
https://atom.io/packages/autocomplete-r, and possibly
https://atom.io/packages/hydrogen

Best,
Ista

On Wed, Jul 27, 2016 at 10:41 AM, Luis Cota  wrote:
> I've been keen to use either VSCode or Atom and have not had much success. 
> Any suggestions?
>
> Regards,
>
> - Luis
>
> 
>
>
>
>
>
> ---
> This communication may contain confidential and/or privileged information. If 
> you are not the intended recipient (or have received this communication in 
> error) please notify the sender immediately and destroy this communication. 
> Any unauthorized copying, disclosure or distribution of the material in this 
> communication is strictly forbidden.
>
> Deutsche Bank does not render legal or tax advice, and the information 
> contained in this communication should not be regarded as such.
>
> __
> 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] Reducing execution time

2016-07-27 Thread Sarah Goslee
You said you had 79 triplets and 8000 records.

When I compared 100 triplets to 1 records it took 86 seconds.

So obviously there is something you're not telling us about the format
of your data.

If you use dput() to provide actual examples, you will get better
results than if we on Rhelp have to guess. Because we tend to guess in
ways that make the most sense after extensive R experience, and that's
probably not what you have.

Sarah

On Wed, Jul 27, 2016 at 1:29 PM, sri vathsan  wrote:
> Hi,
>
> Thanks for the solution. But I am afraid that after running this code still
> it takes more time. It has been an hour and still it is executing. I
> understand the delay because each triplet has to compare almost 9000
> elements.
>
> Regards,
> Sri
>
> On Wed, Jul 27, 2016 at 9:02 PM, Sarah Goslee 
> wrote:
>>
>> Hi,
>>
>> It's really a good idea to use dput() or some other reproducible way
>> to provide data. I had to guess as to what your data looked like.
>>
>> It appears that order doesn't matter?
>>
>> Given than, here's one approach:
>>
>> combs <- structure(list(V1 = c(65L, 77L, 55L, 23L, 34L), V2 = c(23L, 34L,
>> 34L, 77L, 65L), V3 = c(77L, 65L, 23L, 34L, 55L)), .Names = c("V1",
>> "V2", "V3"), class = "data.frame", row.names = c(NA, -5L))
>>
>> dat <- list(
>> c(77,65,34,23,55),
>> c(65,23,77,65,55,34),
>> c(77,34,65),
>> c(55,78,56),
>> c(98,23,77,65,34))
>>
>>
>> sapply(seq_len(nrow(combs)), function(i)sum(sapply(dat,
>> function(j)all(combs[i,] %in% j
>>
>> On a dataset of comparable time to yours, it takes me under a minute and a
>> half.
>>
>> > combs <- combs[rep(1:nrow(combs), length=100), ]
>> > dat <- dat[rep(1:length(dat), length=1)]
>> >
>> > dim(combs)
>> [1] 100   3
>> > length(dat)
>> [1] 1
>> >
>> > system.time(test <- sapply(seq_len(nrow(combs)),
>> > function(i)sum(sapply(dat, function(j)all(combs[i,] %in% j)
>>user  system elapsed
>>  86.380   0.006  86.391
>>
>>
>>
>>
>> On Wed, Jul 27, 2016 at 10:47 AM, sri vathsan  wrote:
>> > Hi,
>> >
>> > Apologizes for the less information.
>> >
>> > Basically, myCombos is a matrix with 3 variables which is a triplet that
>> > is
>> > a combination of 79 codes. There are around 3lakh combination as such
>> > and
>> > it looks like below.
>> >
>> > V1 V2 V3
>> > 65 23 77
>> > 77 34 65
>> > 55 34 23
>> > 23 77 34
>> > 34 65 55
>> >
>> > Each triplet will compare in a list (mylist) having 8177 elements which
>> > will looks like below.
>> >
>> > 77,65,34,23,55
>> > 65,23,77,65,55,34
>> > 77,34,65
>> > 55,78,56
>> > 98,23,77,65,34
>> >
>> > Now I want to count the no of occurrence of the triplet in the above
>> > list.
>> > I.e., the triplet 65 23 77 is seen 3 times in the list. So my output
>> > looks
>> > like below
>> >
>> > V1 V2 V3 Freq
>> > 65 23 77  3
>> > 77 34 65  4
>> > 55 34 23  2
>> >
>> > I hope, I made it clear this time.
>> >
>> >
>> > On Wed, Jul 27, 2016 at 7:00 PM, Bert Gunter 
>> > wrote:
>> >
>> >> Not entirely sure I understand, but match() is already vectorized, so
>> >> you
>> >> should be able to lose the supply(). This would speed things up a lot.
>> >> Please re-read ?match *carefully* .
>> >>
>> >> Bert
>> >>
>> >> On Jul 27, 2016 6:15 AM, "sri vathsan"  wrote:
>> >>
>> >> Hi,
>> >>
>> >> I created list of 3 combination numbers (mycombos, around 3 lakh
>> >> combinations) and counting the occurrence of those combination in
>> >> another
>> >> list. This comparision list (mylist) is having around 8000 records.I am
>> >> using the following code.
>> >>
>> >> myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
>> >>   sum(sapply(myList, function(j) {
>> >> sum(!is.na(match(c(myCombos[i,]), j)))})==3)})
>> >>
>> >> The above code takes very long time to execute and is there any other
>> >> effecting method which will reduce the time.
>> >> --
>> >>
>> >> Regards,
>> >> Srivathsan.K
>> >>
>
>
>
>

__
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] Reducing execution time

2016-07-27 Thread sri vathsan
Hi,

Thanks for the solution. But I am afraid that after running this code still
it takes more time. It has been an hour and still it is executing. I
understand the delay because each triplet has to compare almost 9000
elements.

Regards,
Sri

On Wed, Jul 27, 2016 at 9:02 PM, Sarah Goslee 
wrote:

> Hi,
>
> It's really a good idea to use dput() or some other reproducible way
> to provide data. I had to guess as to what your data looked like.
>
> It appears that order doesn't matter?
>
> Given than, here's one approach:
>
> combs <- structure(list(V1 = c(65L, 77L, 55L, 23L, 34L), V2 = c(23L, 34L,
> 34L, 77L, 65L), V3 = c(77L, 65L, 23L, 34L, 55L)), .Names = c("V1",
> "V2", "V3"), class = "data.frame", row.names = c(NA, -5L))
>
> dat <- list(
> c(77,65,34,23,55),
> c(65,23,77,65,55,34),
> c(77,34,65),
> c(55,78,56),
> c(98,23,77,65,34))
>
>
> sapply(seq_len(nrow(combs)), function(i)sum(sapply(dat,
> function(j)all(combs[i,] %in% j
>
> On a dataset of comparable time to yours, it takes me under a minute and a
> half.
>
> > combs <- combs[rep(1:nrow(combs), length=100), ]
> > dat <- dat[rep(1:length(dat), length=1)]
> >
> > dim(combs)
> [1] 100   3
> > length(dat)
> [1] 1
> >
> > system.time(test <- sapply(seq_len(nrow(combs)),
> function(i)sum(sapply(dat, function(j)all(combs[i,] %in% j)
>user  system elapsed
>  86.380   0.006  86.391
>
>
>
>
> On Wed, Jul 27, 2016 at 10:47 AM, sri vathsan  wrote:
> > Hi,
> >
> > Apologizes for the less information.
> >
> > Basically, myCombos is a matrix with 3 variables which is a triplet that
> is
> > a combination of 79 codes. There are around 3lakh combination as such and
> > it looks like below.
> >
> > V1 V2 V3
> > 65 23 77
> > 77 34 65
> > 55 34 23
> > 23 77 34
> > 34 65 55
> >
> > Each triplet will compare in a list (mylist) having 8177 elements which
> > will looks like below.
> >
> > 77,65,34,23,55
> > 65,23,77,65,55,34
> > 77,34,65
> > 55,78,56
> > 98,23,77,65,34
> >
> > Now I want to count the no of occurrence of the triplet in the above
> list.
> > I.e., the triplet 65 23 77 is seen 3 times in the list. So my output
> looks
> > like below
> >
> > V1 V2 V3 Freq
> > 65 23 77  3
> > 77 34 65  4
> > 55 34 23  2
> >
> > I hope, I made it clear this time.
> >
> >
> > On Wed, Jul 27, 2016 at 7:00 PM, Bert Gunter 
> wrote:
> >
> >> Not entirely sure I understand, but match() is already vectorized, so
> you
> >> should be able to lose the supply(). This would speed things up a lot.
> >> Please re-read ?match *carefully* .
> >>
> >> Bert
> >>
> >> On Jul 27, 2016 6:15 AM, "sri vathsan"  wrote:
> >>
> >> Hi,
> >>
> >> I created list of 3 combination numbers (mycombos, around 3 lakh
> >> combinations) and counting the occurrence of those combination in
> another
> >> list. This comparision list (mylist) is having around 8000 records.I am
> >> using the following code.
> >>
> >> myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
> >>   sum(sapply(myList, function(j) {
> >> sum(!is.na(match(c(myCombos[i,]), j)))})==3)})
> >>
> >> The above code takes very long time to execute and is there any other
> >> effecting method which will reduce the time.
> >> --
> >>
> >> Regards,
> >> Srivathsan.K
> >>
>



-- 

Regards,
Srivathsan.K
Phone : 9600165206

[[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] Reduce woes

2016-07-27 Thread Peter Langfelder
If you have a simple list of vectors (call it lst), use

lengths = sapply(lst, length)

In general, you may want to look at functions lapply and sapply which
apply a function over a list, in this case the function length().

Peter

On Wed, Jul 27, 2016 at 8:20 AM, Stefan Kruger  wrote:
> Hi -
>
> I'm new to R.
>
> In other functional languages I'm familiar with you can often seed a call
> to reduce() with a custom accumulator. Here's an example in Elixir:
>
> map = %{"one" => [1, 1], "three" => [3], "two" => [2, 2]}
> map |> Enum.reduce(%{}, fn ({k,v}, acc) -> Map.update(acc, k,
> Enum.count(v), nil) end)
> # %{"one" => 2, "three" => 1, "two" => 2}
>
> In R-terms that's reducing a list of vectors to become a new list mapping
> the names to the vector lengths.
>
> Even in JavaScript, you can do similar things:
>
> list = { one: [1, 1], three: [3], two: [2, 2] };
> var result = Object.keys(list).reduceRight(function (acc, item) {
>   acc[item] = list[item].length;
>   return acc;
> }, {});
> // result == { two: 2, three: 1, one: 2 }
>
> In R, from what I can gather, Reduce() is restricted such that any init
> value you feed it is required to be of the same type as the elements of the
> vector you're reducing -- so I can't build up. So whilst I can do, say
>
>> Reduce(function(acc, item) { acc + item }, c(1,2,3,4,5), 96)
> [1] 111
>
> I can't use Reduce to build up a list, vector or data frame?
>
> What am I missing?
>
> Many thanks for any pointers,
>
> Stefan
>
>
>
> --
> Stefan Kruger 
>
> [[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] Stack dataframes into a matrix

2016-07-27 Thread Anamika Chaudhuri
Hi David,

Thanks for your response. rbind doesnot seem to work.
Here is a reproducible example

Y<-matrix(1:40,ncol=2)
Y1<-Y/60 # estimates of p

#print(Y1)

sigma2<-
matrix(c(var(Y1[,1]),cov(Y1[,1],Y1[,2]),cov(Y1[,1],Y1[,2]),var(Y1[,2])),2,2)
#print(sigma2)

rho<-sigma2[1,2]/sqrt(sigma2[1,1]*sigma2[2,2])
#rho

mean(Y1[,1])
mean(Y1[,2])

#within<-matrix(data=0,nrow=20,ncol=1)

for (rate3 in 1:20){

rate<-Y1[i,]
#print(rate)


rate1<-rate/(1-rate)


rate2<-log(rate1)


Sigma11<-(1/(rate[1]*(1-rate[1]))^2)*sigma2[1,1]
Sigma22<-(1/(rate[2]*(1-rate[2]))^2)*sigma2[2,2]
Sigma12<-(1/((rate[1]*(1-rate[1]))*(rate[2]*(1-rate[2]*sigma2[1,2]

Sigma2<-matrix(c(Sigma11,Sigma12,Sigma12,Sigma22),2,2)
#print(Sigma2)

rate3<-mvrnorm(1000, mu=c(rate2[1],rate2[2]), Sigma2)

#print(rate3)

x<-exp(rate3[,1])/(1+exp(rate3[,1]))
y<-exp(rate3[,2])/(1+exp(rate3[,2]))
print(x) # Need to be able to stack the x's to produce one matrix
}

Thanks
Anamika

On Wed, Jul 27, 2016 at 2:46 AM, David Winsemius 
wrote:

>
> > On Jul 26, 2016, at 8:07 PM, Anamika Chaudhuri 
> wrote:
> >
> > I have 100 datasets with 20 rows and 2 columns in each dataset.
> > I am looking for help to produce x and y below as 1000 X 20 matrix and
> then
> > repeat that across 100 datasets using R
> >
> > library(MASS)
> > library(car)
> > set.seed(1234)
> > library(mixtools)
> > library(sp)
> >
> >for (k in 1:1){  # k IS THE NO OF DATASETS
> >Y <- read.csv(file=paste0("MVNfreq",k,".csv"))
>
> So this is not reproducible but from the description seems like
>
> do.call( rbind,  # the list of dataframes might "work" assuming column
> names are _all_ the same.
>
> --
> David.
> >
> >Y<-as.matrix(Y)
> >Y <- ifelse(Y==0,Y+.5,Y)
> >
> >
> >Y1<-Y/60 # estimates of p
> >
> >#print(Y1)
> >
> >
> >
> sigma2<-matrix(c(var(Y1[,1]),cov(Y1[,1],Y1[,2]),cov(Y1[,1],Y1[,2]),var(Y1[,2])),2,2)
> >
> >rho<-sigma2[1,2]/sqrt(sigma2[1,1]*sigma2[2,2])
> >mean(Y1[,1])
> >mean(Y1[,2])
> >
> >#within<-matrix(data=0,nrow=20,ncol=1)
> >
> >for (rate3 in 1:20){
> >rate<-Y1[i,]
> >#print(rate)
> >rate1<-rate/(1-rate)
> >rate2<-log(rate1)
> >
> >Sigma11<-(1/(rate[1]*(1-rate[1]))^2)*sigma2[1,1]
> >Sigma22<-(1/(rate[2]*(1-rate[2]))^2)*sigma2[2,2]
> >
> > Sigma12<-(1/((rate[1]*(1-rate[1]))*(rate[2]*(1-rate[2]*sigma2[1,2]
> >
> >Sigma2<-matrix(c(Sigma11,Sigma12,Sigma12,Sigma22),2,2)
> >
> >rate3<-mvrnorm(1000, mu=c(rate2[1],rate2[2]), Sigma2)
> >x<-exp(rate3[,1])/(1+exp(rate3[,1]))
> >y<-exp(rate3[,2])/(1+exp(rate3[,2]))
> >x<-as.data.frame(x)
> >stack(x) # Need help to stack x into a single matrix
> >print(x)
> >print(y)
> >}
> >}
> >
> >   [[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.
>
> David Winsemius
> Alameda, CA, USA
>
>

[[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] Reduce woes

2016-07-27 Thread Stefan Kruger
Hi -

I'm new to R.

In other functional languages I'm familiar with you can often seed a call
to reduce() with a custom accumulator. Here's an example in Elixir:

map = %{"one" => [1, 1], "three" => [3], "two" => [2, 2]}
map |> Enum.reduce(%{}, fn ({k,v}, acc) -> Map.update(acc, k,
Enum.count(v), nil) end)
# %{"one" => 2, "three" => 1, "two" => 2}

In R-terms that's reducing a list of vectors to become a new list mapping
the names to the vector lengths.

Even in JavaScript, you can do similar things:

list = { one: [1, 1], three: [3], two: [2, 2] };
var result = Object.keys(list).reduceRight(function (acc, item) {
  acc[item] = list[item].length;
  return acc;
}, {});
// result == { two: 2, three: 1, one: 2 }

In R, from what I can gather, Reduce() is restricted such that any init
value you feed it is required to be of the same type as the elements of the
vector you're reducing -- so I can't build up. So whilst I can do, say

> Reduce(function(acc, item) { acc + item }, c(1,2,3,4,5), 96)
[1] 111

I can't use Reduce to build up a list, vector or data frame?

What am I missing?

Many thanks for any pointers,

Stefan



-- 
Stefan Kruger 

[[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] Have any of you succesfully used VS Code with R? How have you set this up?

2016-07-27 Thread Luis Cota
I've been keen to use either VSCode or Atom and have not had much success. Any 
suggestions?

Regards,

- Luis







---
This communication may contain confidential and/or privileged information. If 
you are not the intended recipient (or have received this communication in 
error) please notify the sender immediately and destroy this communication. Any 
unauthorized copying, disclosure or distribution of the material in this 
communication is strictly forbidden.

Deutsche Bank does not render legal or tax advice, and the information 
contained in this communication should not be regarded as such.

__
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] How to set up a dynamic panel data model with pgmm from plm pacakge?

2016-07-27 Thread Striessnig, Erich
\n<<



Hi,



I am trying to set up a dynamic panel data model using the pgmm function from 
the plm package. The formula that I want to estimate is something like this:



[y(t) - y(t-1)] ~ [x(t) - x(t-1)] + [x(t-1) - y(t-1)]



where the lagged value of the dependent variable should be instrumented by its 
4th and 5th lag.

Can anyone please tell me which one of the five formulas in the R-code below 
does that?





###

library(plm)



value.x <- rnorm(336)

value.y <- rnorm(336)

diff.xy <- value.x - value.y

my.data <- data.frame(expand.grid(ids=1:28,times=1:12),value.x,value.y,diff.xy)



form1 <- diff(value.y) ~ diff(value.x) + lag(I(value.x-value.y),1) | 
lag(value.y,4:5)

form2 <- diff(value.y) ~ diff(value.x) + lag(I(value.x-value.y),4:5) | 
lag(value.y,4:5)

form3 <- diff(value.y) ~ diff(value.x) + diff.xy | lag(diff.xy,4:5)

form4 <- diff(value.y) ~ diff(value.x) + lag(diff.xy,1) | lag(diff.xy,4:5)

form5 <- diff(value.y) ~ diff(value.x) + lag(diff.xy,1) | 
lag(I(value.x-value.y),4:5)



mod1 <- pgmm(formula=form1,data=my.data,index=c('ids','times'),

 effect="individual", model="twosteps")

summary(mod1)

###



Kind regards,

Erich







>>\n\n \n<> 
>>\n<>\n\n\n\n

--please do not edit the information below--



R Version:

platform = x86_64-w64-mingw32

arch = x86_64

os = mingw32

system = x86_64, mingw32

status =

 major = 3

minor = 2.5

year = 2016

month = 04

day = 14

svn rev = 70478

language = R

version.string = R version 3.2.5 (2016-04-14)

nickname = Very, Very Secure Dishes



Windows 7 x64 (build 7601) Service Pack 1



Locale:

LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252



Search Path:

.GlobalEnv, package:plm, package:TinnRcom, package:Hmisc, package:ggplot2, 
package:Formula, package:survival, package:lattice,

package:grid, package:R2HTML, package:formatR, package:svSocket, package:stats, 
package:graphics, package:grDevices, package:utils,

package:datasets, package:methods, SciViews:TempEnv, Autoloads, package:base

[[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] How to use fuzzy_partition with fuzzy_trapezoid

2016-07-27 Thread Arthur Stilben
Hello, guys!

I tried to do that:

> teste = fuzzy_partition( varnames = c( "a", "b" ), FUN = fuzzy_trapezoid, 
> corners = c( 0, 1, 2, 3), corners = c(4, 5, 6, 7))
Error in FUN(i, ...) :
  argumento formal "corners" corresponde a múltiplos argumentos especificados


So, how can I use fuzzy_partitions to generate multiples trapezoids?

-- 
Arthur Rodrigues Stilben
Geoinformática - LENEP
(22) 2765-6555

__
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] probelm with xlab ylab and xaxp barplot

2016-07-27 Thread Abdoulaye Sarr
Hi Marc,

I have something very close now, and think to leave it like that.

Thank you so much for your help to solve the problem.

Cheers,

asarr

On Mon, Jul 25, 2016 at 6:03 PM, Marc Schwartz  wrote:

> Hi,
>
> First, I noted again that you still have:
>
>xaxp=c(181,2005,1)
>
> in the first barplot() call. Get rid of that, as barplot() does not use
> normal axis ranges for the bar midpoints.
>
> Second, I do not see an indication that you are using the 'names.arg'
> argument in barplot(), which supplies the vector of text to place below
> each bar. If this is correct, then you want the basic barplot() call to
> look something like:
>
>   barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei",
>   names.arg = 1981:2005,
>   col=ifelse(z1>0,"green","brown"))
>
> where names.arg on the second line is the vector of years from 1981 to
> 2005. If the data passed to barplot() have name attributes (for example,
> they are the result of using table() on a vector), those would be used, but
> I am guessing that your z* vectors are just numeric vectors without labels.
>
> If you then need to further adjust the axes to make more room below the
> plots, adjust the first element of par(mar) until the default axes show.
>
> For example:
>
>   par(mar = c(6, 4, 4, 2))
>
> where 6 replaces the default 5 for the first element. You may need to go
> higher if the text is still not showing. If need be, increase it further
> slowly to view the impact. You can also change by less than a full integer
> (e.g. 5.5, 6.25, etc.) as you may need. At some point, you will overshoot
> with too much room and you can then back down slowly.
>
> Using this approach, each plot will have a similar size as you adjust the
> margins and then look similar visually, presuming that the axis ranges are
> the same for each.
>
> Regards,
>
> Marc
>
>
> > On Jul 25, 2016, at 11:56 AM, Abdoulaye SARR 
> wrote:
> >
> > Hi Marc,
> >
> > According to your guidance the labels are almost at the right place when
> adjusting mar values.
> >
> > A remaining need is to have the x axis at least for the two bottom
> figures as date from 1981 to 2005. Do you think this is doable. Ylim is
> fine but how tots in this case xlim.
> >
> > Best regards,
> >
> > asarr
> > Le 25 juil. 2016 à 14:28, Marc Schwartz  a écrit :
> >
> >> Hi,
> >>
> >> If your code below is a verbatim copy and paste, you still have the
> following two lines active:
> >>
> >>  par(mar=rep(2,4))
> >>
> >> and
> >>
> >>  op <- par(oma=c(1,2,3,5))
> >>
> >> Comment out both of those lines and then see what the result looks like.
> >>
> >> As I noted before, try the plot **without any modifications** to the
> default margin values. Then adjust from there, which may require you to
> increase, not decrease, the values from their defaults in order to have
> room for your text.
> >>
> >> The values you have for par(mar) above, for example, reduce the values
> to 2 for each side from the default, which is:
> >>
> >>  c(5, 4, 4, 2) + 0.1.
> >>
> >> So that alone will likely result in there not being enough room for
> your axis labels.
> >>
> >> You may also have to create the barplot without any default annotation
> created by the function itself and then add it with ?axis, ?text and
> ?mtext. You may also have to reduce the size of the font itself, which is
> done via the cex* arguments to barplot() and the additional annotation
> functions mentioned in the prior sentence.
> >>
> >> Regards,
> >>
> >> Marc
> >>
> >>
> >>> On Jul 25, 2016, at 8:06 AM, Abdoulaye SARR 
> wrote:
> >>>
> >>>
> > Hi Marc and Others,
> >>>
> >>>
> >>> I am still struggling to have my slab and ylab displayed on a bar
> plot. Marc did useful advise on playing with mar settings. I tried may
> combinations and can�t have it work.
> >>>
> >>> I paste the code I am suing hoping guidance on solving this issue.
> >>>
> >>>
> >>>
> >>>
> >>> ## extract works for all time steps
> >>> d1<-read.nc(gp)
> >>>
> >>> d2<-read.nc(er)
> >>>
> >>> d3<-read.nc(me)
> >>>
> >>> d4<-read.nc(ne)
> >>>
> >>> d5<-read.nc(ar)
> >>>
> >>> d6<-read.nc(cc)
> >>>
> >>> d7<-read.nc(mr)
> >>>
> >>> d8<-read.nc(ic)
> >>>
> >>> z1<-d1$spei
> >>> z2<-d2$spei
> >>> z3<-d3$spei
> >>> z4<-d4$spei
> >>> z5<-d5$spei
> >>> z6<-d6$spei
> >>> z7<-d7$spei
> >>> z8<-d8$spei
> >>> #par(oma=c(2,2,2,2))  # all sides have 3 lines of space
> >>>
> >>> par(mar=rep(2,4))
> >>> #par(mar=c(5.1, 4.1, 2.1, 2.1))
> >>> #par(mai=c(1.02,0.82,0.82,0.42))
> >>> op <- par(oma=c(1,2,3,5))
> >>> #op <- par(oma=c(6,5,0,0))
> >>> par(mfrow=c(4,2))
> >>>
> >>> line = 3
> >>>
> >>> barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei",
> xaxp=c(181,2005,1), col=ifelse(z1>0,"green","brown"))
> >>>
> >>> mtext("a")
> >>> barplot(z2,xlab="Years", ylab="spei",  ylim=c(-2,2),
> col=ifelse(z2>0,"green","brown"))
> >>> mtext("b")
> >>> barplot(z3, ylim=c(-2,2), xlab="Years", ylab="spei",
> 

Re: [R] about netcdf files

2016-07-27 Thread lily li
Hi Jon,

The versions are: raster_2.5-2 sp_1.2-3


On Wed, Jul 27, 2016 at 9:31 AM, Jon Skoien 
wrote:

> Hi Lily,
>
> You can ignore the first three lines, they are just for information.
> Which version of raster do you have? I see that the attempt to read the
> crs-variable was not wrapped in a try-call in earlier versions. Upgrading
> might help.
>
> Best,
> Jon
>
>
>
> On 7/27/2016 5:13 PM, lily li wrote:
>
> Hi Jon,
>
> I still have problems. The brick function does not work well and I don't
> know where to check the problem. I put the error message below, thanks.
>
> > pre = brick("~/Downloads/sample_precip_daily.nc")
> [1] "vobjtovarid4: error #F: I could not find the requsted var (or dimvar)
> in the file!"
> [1] "var (or dimvar) name: crs"
> [1] "file name: /.../Downloads/sample_precip_daily.nc"
> Error in vobjtovarid4(nc, varid, allowdimvar = TRUE, verbose = verbose) :
>   Variable not found
>
>
> On Wed, Jul 27, 2016 at 1:10 AM, Jon Skoien 
> wrote:
>
>> I think you get the error because you passed the object from nc_open(),
>> you should rather pass the filename of the netCDF, so:
>>
>> pre = brick("sample_precip_daily.nc")
>> From the test-file, this gives you a RasterBrick-object with 5*9 pixels
>> and 7305 layers.
>> Then you can extract data.frames of each layer with:
>> dframe = rasterToPoints(pre[[1]])
>> where 1 is the first layer, or time series with:
>> tseries = pre[3,4]
>> where 3 and 4 are the pixels in x and y-direction.
>>
>> To write dframe to csv:
>> write.csv(dframe, filename = "csvfile.csv")
>> Check the function for more options.
>>
>> Hope this helps you a bit further.
>> Jon
>>
>>
>> On 7/26/2016 9:07 PM, lily li wrote:
>>
>> Thanks for your reply. But it says "Error in (function (classes, fdef,
>> mtable)):
>> unable to find an inherited method for function 'brick' for signature
>> 'ncdf4' "
>>
>> The dataset is attached. It contains daily precipitation data for 20
>> years, within a rectangle, so that there are several grid points. I use the
>> code to open it, but don't know how to get csv files, while each file
>> contains continuous daily precipitation data for each grid cell.
>> pre1 = nc_open('sample_precip_daily.nc')
>> pre1
>> pre1_rd = ncvar_get(pre1, 'precipitation')
>> nc_close(pre1)
>>
>> Thanks for your help.
>>
>> On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien <
>> jon.sko...@jrc.ec.europa.eu> wrote:
>>
>>> You could try with the brick function from the raster package.
>>>
>>> bvar = brick(netcdfName)
>>>
>>> This uses the ncdf4 functions for opening and reading the netcdf, but
>>> makes it easier to extract data for each day:
>>>
>>> p1 = rasterToPoints(bvar[[1]])
>>> and write p1 to csv.
>>>
>>> Best,
>>> Jon
>>>
>>>
>>>
>>> On 7/26/2016 6:54 AM, lily li wrote:
>>>
 Hi all,

 I have a problem in opening netcdf files. If one netcdf file contains
 longitude, latitude, and daily precipitation. How to relate each
 precipitation record to its associated location, and export them as csv
 files? Thanks.

 I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks
 for
 any ideas.

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


>>> --
>>> Jon Olav Skøien
>>> Joint Research Centre - European Commission
>>> Institute for Space, Security & Migration
>>> Disaster Risk Management Unit
>>>
>>> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
>>>
>>> jon.sko...@jrc.ec.europa.eu
>>> Tel:  +39 0332 789205 <%2B39%200332%20789205>
>>>
>>> Disclaimer: Views expressed in this email are those of the individual
>>> and do not necessarily represent official views of the European Commission.
>>>
>>
>>
>> --
>> Jon Olav Skøien
>> Joint Research Centre - European Commission
>> Institute for Space, Security & Migration
>> Disaster Risk Management Unit
>>
>> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
>> jon.sko...@jrc.ec.europa.eu
>> Tel:  +39 0332 789205
>>
>> Disclaimer: Views expressed in this email are those of the individual and do 
>> not necessarily represent official views of the European Commission.
>>
>>
>
> --
> Jon Olav Skøien
> Joint Research Centre - European Commission
> Institute for Space, Security & Migration
> Disaster Risk Management Unit
>
> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
> jon.sko...@jrc.ec.europa.eu
> Tel:  +39 0332 789205
>
> Disclaimer: Views expressed in this email are those of the individual and do 
> not necessarily represent official views of the European Commission.
>
>


Re: [R] Aggregate matrix in a 2 by 2 manor

2016-07-27 Thread David L Carlson
This should be faster. It uses apply() across the blocks. 

> ilon <- seq(1,8,nx)
> ilat <- seq(1,4,ny)
> cells <- as.matrix(expand.grid(ilat, ilon))
> blocks <- apply(cells, 1, function(x) tst[x[1]:(x[1]+1), x[2]:(x[2]+1)])
> block.means <- colMeans(blocks)
> tst_2x2 <- matrix(block.means, 2, 4)
> tst_2x2
 [,1] [,2] [,3] [,4]
[1,]  3.5 11.5 19.5 27.5
[2,]  5.5 13.5 21.5 29.5

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352



-Original Message-
From: R-help [mailto:r-help-boun...@r-poject.org] On Behalf Of Anthoni, Peter 
(IMK)
Sent: Wednesday, July 27, 2016 6:14 AM
To: r-help@r-project.org
Subject: [R] Aggregate matrix in a 2 by 2 manor

Hi all,

I need to aggregate some matrix data (1440x720) to a lower dimension (720x360) 
for lots of years and variables

I can do double for loop, but that will be slow. Anybody know a quicker way?

here an example with a smaller matrix size:

tst=matrix(1:(8*4),ncol=8,nrow=4)
tst_2x2=matrix(NA,ncol=4,nrow=2)
nx=2
ny=2
for(ilon in seq(1,8,nx)) {
  for (ilat in seq(1,4,ny)) {
ilon_2x2=1+(ilon-1)/nx
ilat_2x2=1+(ilat-1)/ny
tst_2x2[ilat_2x2,ilon_2x2] = mean(tst[ilat+0:1,ilon+0:1])
  }
}

tst
tst_2x2

> tst
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]159   13   17   21   25   29
[2,]26   10   14   18   22   26   30
[3,]37   11   15   19   23   27   31
[4,]48   12   16   20   24   28   32

> tst_2x2
 [,1] [,2] [,3] [,4]
[1,]  3.5 11.5 19.5 27.5
[2,]  5.5 13.5 21.5 29.5


I though a cast to 3d-array might do the trick and apply over the new 
dimension, but that does not work, since it casts the data along the row.
> matrix(apply(array(tst,dim=c(nx,ny,8)),3,mean),nrow=nrow(tst)/ny)
 [,1] [,2] [,3] [,4]
[1,]  2.5 10.5 18.5 26.5
[2,]  6.5 14.5 22.5 30.5


cheers
Peter

__
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] Windows 10 Application Compatibility Check | FreeWare R Statistical Environment v3.2.2

2016-07-27 Thread Marc Schwartz
Hi,

With the caveat that I speak for myself only, a few comments:

1. Given that Citi appears to have been running R on Windows 7 for some period 
of time, I am not sure that they are looking for reasons to deny users access 
to R. They are simply looking for some indication that R will run on Windows 10.

2. There is nothing presently in the relevant R for Windows FAQ:

  
https://cran.r-project.org/bin/windows/base/rw-FAQ.html#Does-R-run-under-Windows-Vista_003f

that explicitly indicates that R will run on Windows 10. At some point, 
presumably, that would be updated to reflect more recent experience by R Core.

3. Besides Robert's comment below on his experience (n of 1), there are other 
comments that I see via a Google search that would suggest that his experience 
is not unique (e.g. https://rpubs.com/kartykr/rrproject) and there are threads 
in the R-Help archives from last September:

  https://stat.ethz.ch/pipermail/r-help/2015-September/431809.html
  https://stat.ethz.ch/pipermail/r-help/2015-September/431825.html

that also support the notion that R will run on Windows 10.

4. If Citi, wants to pursue a more "commercial-like" approach to paid support 
for R, there are commercial versions of R available, which I shall not mention 
here, but a quick Google search would avail them of more details. 

5. Lastly and perhaps most importantly, R is not Freeware. R (as made available 
by the R Foundation) is free open source software (FOSS) and is distributed 
under relevant open source licenses. The label "Freeware", which typically 
refers to proprietary software, only means that the binary application itself 
is free of charge. It does not mean that the source code for the application is 
also available. There is a very large functional and philosophical difference 
between FOSS and Freeware.

Regards,

Marc Schwartz


> On Jul 27, 2016, at 9:47 AM, John C Frain  wrote:
> 
> When I first graduated some 50 years ago I worked in the Department of
> Finance. On small piece of my work involved getting CPI data from the CSO
> and doing some calculations. A specific person in the CSO (Central
> Statistics Office) usually supplied this information and this fact was
> always recorded on the file. On one occasion I could not contact that
> person and I visited the department library and extracted the information
> myself. When my boss saw that I had not contacted the CSO I was instructed
> to contact them and repeat the calculation. It was explained to me that if
> I contacted the CSO we could blame someone outside the Department of
> Finance if they supplied the information.
> 
> It appears that Citi Architecture & Technology Engineering are behaving in
> a similar way.  Are they trying to find some excuse to deny their users
> access to R on the grounds that it is not "properly" supported. This does
> happen in large organisations.
> 
> If any one knows of some organisation that is willing to provide support to
> Citi (for a respectable fee) there might be a bit of money to be made.
> 
> John C Frain
> 3 Aranleigh Park
> Rathfarnham
> Dublin 14
> Ireland
> www.tcd.ie/Economics/staff/frainj/home.html
> mailto:fra...@tcd.ie
> mailto:fra...@gmail.com
> 
> On 26 July 2016 at 23:49, Robert Baer  wrote:
> 
>> Runs fine on Windows 10 for me.
>> 
>> 
>> On 7/25/2016 7:18 AM, Ramar, Rohini wrote:
>> 
>>> Hello Team,
>>> 
>>> We are, Citi Application Readiness Team, need your assistance in order to
>>> gather info about below application compatibility and support for Win 10 as
>>> part of Window 10 Readiness initiative. CITI Bank has been using below
>>> "FreeWare R Statistical Environment v3.2.2"  software products currently on
>>> Win 7 operating system.
>>> 
>>> We would like to know whether the below listed application is compatible
>>> and supported even for Win 10 (64 Bit) or is there any other higher version
>>> of application which would be compatible for Win10. If you have not tested
>>> for Win 10, could you please provide us with a tentative date by when we
>>> can reach you.
>>> 
>>> Application Name : FreeWare R Statistical Environment v3.2.2
>>> 
>>> 
>>> Note: Kindly re-direct this email to appropriate team if we reached you
>>> wrongly.
>>> 
>>> 
>>> Regards,
>>> Rohini R
>>> Citi Architecture & Technology Engineering
>>> Client Computing
>>> Direct Phone #:+91 22 3346 1497
>>> Email ID: rohini.ra...@citi.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] Reducing execution time

2016-07-27 Thread Sarah Goslee
Hi,

It's really a good idea to use dput() or some other reproducible way
to provide data. I had to guess as to what your data looked like.

It appears that order doesn't matter?

Given than, here's one approach:

combs <- structure(list(V1 = c(65L, 77L, 55L, 23L, 34L), V2 = c(23L, 34L,
34L, 77L, 65L), V3 = c(77L, 65L, 23L, 34L, 55L)), .Names = c("V1",
"V2", "V3"), class = "data.frame", row.names = c(NA, -5L))

dat <- list(
c(77,65,34,23,55),
c(65,23,77,65,55,34),
c(77,34,65),
c(55,78,56),
c(98,23,77,65,34))


sapply(seq_len(nrow(combs)), function(i)sum(sapply(dat,
function(j)all(combs[i,] %in% j

On a dataset of comparable time to yours, it takes me under a minute and a half.

> combs <- combs[rep(1:nrow(combs), length=100), ]
> dat <- dat[rep(1:length(dat), length=1)]
>
> dim(combs)
[1] 100   3
> length(dat)
[1] 1
>
> system.time(test <- sapply(seq_len(nrow(combs)), function(i)sum(sapply(dat, 
> function(j)all(combs[i,] %in% j)
   user  system elapsed
 86.380   0.006  86.391




On Wed, Jul 27, 2016 at 10:47 AM, sri vathsan  wrote:
> Hi,
>
> Apologizes for the less information.
>
> Basically, myCombos is a matrix with 3 variables which is a triplet that is
> a combination of 79 codes. There are around 3lakh combination as such and
> it looks like below.
>
> V1 V2 V3
> 65 23 77
> 77 34 65
> 55 34 23
> 23 77 34
> 34 65 55
>
> Each triplet will compare in a list (mylist) having 8177 elements which
> will looks like below.
>
> 77,65,34,23,55
> 65,23,77,65,55,34
> 77,34,65
> 55,78,56
> 98,23,77,65,34
>
> Now I want to count the no of occurrence of the triplet in the above list.
> I.e., the triplet 65 23 77 is seen 3 times in the list. So my output looks
> like below
>
> V1 V2 V3 Freq
> 65 23 77  3
> 77 34 65  4
> 55 34 23  2
>
> I hope, I made it clear this time.
>
>
> On Wed, Jul 27, 2016 at 7:00 PM, Bert Gunter  wrote:
>
>> Not entirely sure I understand, but match() is already vectorized, so you
>> should be able to lose the supply(). This would speed things up a lot.
>> Please re-read ?match *carefully* .
>>
>> Bert
>>
>> On Jul 27, 2016 6:15 AM, "sri vathsan"  wrote:
>>
>> Hi,
>>
>> I created list of 3 combination numbers (mycombos, around 3 lakh
>> combinations) and counting the occurrence of those combination in another
>> list. This comparision list (mylist) is having around 8000 records.I am
>> using the following code.
>>
>> myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
>>   sum(sapply(myList, function(j) {
>> sum(!is.na(match(c(myCombos[i,]), j)))})==3)})
>>
>> The above code takes very long time to execute and is there any other
>> effecting method which will reduce the time.
>> --
>>
>> Regards,
>> Srivathsan.K
>>

__
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] about netcdf files

2016-07-27 Thread Jon Skoien
Hi Lily,

You can ignore the first three lines, they are just for information.
Which version of raster do you have? I see that the attempt to read the 
crs-variable was not wrapped in a try-call in earlier versions. 
Upgrading might help.

Best,
Jon


On 7/27/2016 5:13 PM, lily li wrote:
> Hi Jon,
>
> I still have problems. The brick function does not work well and I 
> don't know where to check the problem. I put the error message below, 
> thanks.
>
> > pre = brick("~/Downloads/sample_precip_daily.nc 
> ")
> [1] "vobjtovarid4: error #F: I could not find the requsted var (or 
> dimvar) in the file!"
> [1] "var (or dimvar) name: crs"
> [1] "file name: /.../Downloads/sample_precip_daily.nc 
> "
> Error in vobjtovarid4(nc, varid, allowdimvar = TRUE, verbose = verbose) :
>   Variable not found
>
>
> On Wed, Jul 27, 2016 at 1:10 AM, Jon Skoien 
> > wrote:
>
> I think you get the error because you passed the object from
> nc_open(), you should rather pass the filename of the netCDF, so:
>
> pre = brick("sample_precip_daily.nc ")
> From the test-file, this gives you a RasterBrick-object with 5*9
> pixels and 7305 layers.
> Then you can extract data.frames of each layer with:
> dframe = rasterToPoints(pre[[1]])
> where 1 is the first layer, or time series with:
> tseries = pre[3,4]
> where 3 and 4 are the pixels in x and y-direction.
>
> To write dframe to csv:
> write.csv(dframe, filename = "csvfile.csv")
> Check the function for more options.
>
> Hope this helps you a bit further.
> Jon
>
>
> On 7/26/2016 9:07 PM, lily li wrote:
>> Thanks for your reply. But it says "Error in (function (classes,
>> fdef, mtable)):
>> unable to find an inherited method for function 'brick' for
>> signature 'ncdf4' "
>>
>> The dataset is attached. It contains daily precipitation data for
>> 20 years, within a rectangle, so that there are several grid
>> points. I use the code to open it, but don't know how to get csv
>> files, while each file contains continuous daily precipitation
>> data for each grid cell.
>> pre1 = nc_open('sample_precip_daily.nc
>> ')
>> pre1
>> pre1_rd = ncvar_get(pre1, 'precipitation')
>> nc_close(pre1)
>>
>> Thanks for your help.
>>
>> On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien
>> > > wrote:
>>
>> You could try with the brick function from the raster package.
>>
>> bvar = brick(netcdfName)
>>
>> This uses the ncdf4 functions for opening and reading the
>> netcdf, but makes it easier to extract data for each day:
>>
>> p1 = rasterToPoints(bvar[[1]])
>> and write p1 to csv.
>>
>> Best,
>> Jon
>>
>>
>>
>> On 7/26/2016 6:54 AM, lily li wrote:
>>
>> Hi all,
>>
>> I have a problem in opening netcdf files. If one netcdf
>> file contains
>> longitude, latitude, and daily precipitation. How to
>> relate each
>> precipitation record to its associated location, and
>> export them as csv
>> files? Thanks.
>>
>> I just use nc_open(), ncvar_get(), but it is not very
>> helpful. Thanks for
>> any ideas.
>>
>> [[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.
>>
>>
>> -- 
>> Jon Olav Skøien
>> Joint Research Centre - European Commission
>> Institute for Space, Security & Migration
>> Disaster Risk Management Unit
>>
>> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
>>
>> jon.sko...@jrc.ec.europa.eu 
>> Tel: +39 0332 789205 
>>
>> Disclaimer: Views expressed in this email are those of the
>> individual and do not necessarily represent official views of
>> the European Commission.
>>
>>
>
> -- 
> Jon Olav Skøien
> Joint Research Centre - European Commission
> Institute for Space, Security & Migration
> Disaster Risk Management Unit
>
> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
>
> jon.sko...@jrc.ec.europa.eu 
> Tel:+39 0332 789205 

Re: [R] Reducing execution time

2016-07-27 Thread sri vathsan
Hi,

Apologizes for the less information.

Basically, myCombos is a matrix with 3 variables which is a triplet that is
a combination of 79 codes. There are around 3lakh combination as such and
it looks like below.

V1 V2 V3
65 23 77
77 34 65
55 34 23
23 77 34
34 65 55

Each triplet will compare in a list (mylist) having 8177 elements which
will looks like below.

77,65,34,23,55
65,23,77,65,55,34
77,34,65
55,78,56
98,23,77,65,34

Now I want to count the no of occurrence of the triplet in the above list.
I.e., the triplet 65 23 77 is seen 3 times in the list. So my output looks
like below

V1 V2 V3 Freq
65 23 77  3
77 34 65  4
55 34 23  2

I hope, I made it clear this time.


On Wed, Jul 27, 2016 at 7:00 PM, Bert Gunter  wrote:

> Not entirely sure I understand, but match() is already vectorized, so you
> should be able to lose the supply(). This would speed things up a lot.
> Please re-read ?match *carefully* .
>
> Bert
>
> On Jul 27, 2016 6:15 AM, "sri vathsan"  wrote:
>
> Hi,
>
> I created list of 3 combination numbers (mycombos, around 3 lakh
> combinations) and counting the occurrence of those combination in another
> list. This comparision list (mylist) is having around 8000 records.I am
> using the following code.
>
> myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
>   sum(sapply(myList, function(j) {
> sum(!is.na(match(c(myCombos[i,]), j)))})==3)})
>
> The above code takes very long time to execute and is there any other
> effecting method which will reduce the time.
> --
>
> Regards,
> Srivathsan.K
>
> [[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.
>
>
>


-- 

Regards,
Srivathsan.K
Phone : 9600165206

[[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] Windows 10 Application Compatibility Check | FreeWare R Statistical Environment v3.2.2

2016-07-27 Thread John C Frain
When I first graduated some 50 years ago I worked in the Department of
Finance. On small piece of my work involved getting CPI data from the CSO
and doing some calculations. A specific person in the CSO (Central
Statistics Office) usually supplied this information and this fact was
always recorded on the file. On one occasion I could not contact that
person and I visited the department library and extracted the information
myself. When my boss saw that I had not contacted the CSO I was instructed
to contact them and repeat the calculation. It was explained to me that if
I contacted the CSO we could blame someone outside the Department of
Finance if they supplied the information.

It appears that Citi Architecture & Technology Engineering are behaving in
a similar way.  Are they trying to find some excuse to deny their users
access to R on the grounds that it is not "properly" supported. This does
happen in large organisations.

If any one knows of some organisation that is willing to provide support to
Citi (for a respectable fee) there might be a bit of money to be made.

John C Frain
3 Aranleigh Park
Rathfarnham
Dublin 14
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@gmail.com

On 26 July 2016 at 23:49, Robert Baer  wrote:

> Runs fine on Windows 10 for me.
>
>
> On 7/25/2016 7:18 AM, Ramar, Rohini wrote:
>
>> Hello Team,
>>
>> We are, Citi Application Readiness Team, need your assistance in order to
>> gather info about below application compatibility and support for Win 10 as
>> part of Window 10 Readiness initiative. CITI Bank has been using below
>> "FreeWare R Statistical Environment v3.2.2"  software products currently on
>> Win 7 operating system.
>>
>> We would like to know whether the below listed application is compatible
>> and supported even for Win 10 (64 Bit) or is there any other higher version
>> of application which would be compatible for Win10. If you have not tested
>> for Win 10, could you please provide us with a tentative date by when we
>> can reach you.
>>
>> Application Name : FreeWare R Statistical Environment v3.2.2
>>
>>
>> Note: Kindly re-direct this email to appropriate team if we reached you
>> wrongly.
>>
>>
>> Regards,
>> Rohini R
>> Citi Architecture & Technology Engineering
>> Client Computing
>> Direct Phone #:+91 22 3346 1497
>> Email ID: rohini.ra...@citi.com
>>
>>
>>
>> [[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.
>

[[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-es] labs(caption) en ggplot2

2016-07-27 Thread Mauricio Monsalvo
Hola.
Tengo un problema que no logro identificar: no logro que se lea la leyenda
que está indicada en labs(caption="") de este script:
ggplot(data = total) +
  geom_point(mapping = aes(x = UniM, y = ValM, label = Producto,
   fill = Camara, color = Camara),
 stat = "identity", position = 'identity') + #No parece agregar
  facet_wrap( ~ Categoria) +
  theme_minimal(base_size = 18, base_family = "Tahoma") +
  geom_text(data=subset(total, UniM>1| ValM>200), hjust = 0, nudge_x =
0.05,
aes(x = UniM, y = ValM, label = Producto), check_overlap = T) +
  scale_color_manual(values = ColCamaras) +
  ggtitle('...')+
  ylab('Valores') +
  xlab('Unidades') +
  theme(legend.position = "bottom", legend.direction = "horizontal",
legend.title = element_blank())+
  labs(caption = 'Esta leyenda no se ve en el gráfico') +
  guides(fill = guide_legend(nrow = 1), color = guide_legend(nrow = 1))

La sintaxis modelo está tomada de la pirámide poblacional animada en este
post:
http://www.r-bloggers.com/idbr-access-the-us-census-bureau-international-data-base-in-r/?utm_source=feedburner_medium=email_campaign=Feed%3A+RBloggers+%28R+bloggers%29/
No estoy usando library(gganimate) ni library(animation) pero no creo que
el problema esté en no animar el gráfico, sino más bien en algún setteo de
los márgenes o algo así que no logro determinar.
Muchas gracias!
-- 
Mauricio

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Reducing execution time

2016-07-27 Thread Bert Gunter
Not entirely sure I understand, but match() is already vectorized, so you
should be able to lose the supply(). This would speed things up a lot.
Please re-read ?match *carefully* .

Bert

On Jul 27, 2016 6:15 AM, "sri vathsan"  wrote:

Hi,

I created list of 3 combination numbers (mycombos, around 3 lakh
combinations) and counting the occurrence of those combination in another
list. This comparision list (mylist) is having around 8000 records.I am
using the following code.

myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
  sum(sapply(myList, function(j) {
sum(!is.na(match(c(myCombos[i,]), j)))})==3)})

The above code takes very long time to execute and is there any other
effecting method which will reduce the time.
--

Regards,
Srivathsan.K

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

[[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] Reducing execution time

2016-07-27 Thread Thierry Onkelinx
A reproducible example makes your problem easier to understand.

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

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

2016-07-27 15:14 GMT+02:00 sri vathsan :

> Hi,
>
> I created list of 3 combination numbers (mycombos, around 3 lakh
> combinations) and counting the occurrence of those combination in another
> list. This comparision list (mylist) is having around 8000 records.I am
> using the following code.
>
> myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
>   sum(sapply(myList, function(j) {
> sum(!is.na(match(c(myCombos[i,]), j)))})==3)})
>
> The above code takes very long time to execute and is there any other
> effecting method which will reduce the time.
> --
>
> Regards,
> Srivathsan.K
>
> [[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.
>

[[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] Reducing execution time

2016-07-27 Thread sri vathsan
Hi,

I created list of 3 combination numbers (mycombos, around 3 lakh
combinations) and counting the occurrence of those combination in another
list. This comparision list (mylist) is having around 8000 records.I am
using the following code.

myCounts <- sapply(1:nrow(myCombos), FUN=function(i) {
  sum(sapply(myList, function(j) {
sum(!is.na(match(c(myCombos[i,]), j)))})==3)})

The above code takes very long time to execute and is there any other
effecting method which will reduce the time.
-- 

Regards,
Srivathsan.K

[[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] Likelihood ratio test in porl (MASS)

2016-07-27 Thread Faradj Koliev
Dear Achim Zeileis, dear John Fox,

Thank you for your time! Both worked well. 

lrtest(Restrict, Full)

  #Df  LogLik Df  Chisq Pr(>Chisq)
1  27 -882.00 
2  28 -866.39  1 31.212  2.313e-08 ***


anova(Restrict, Full)

  Resid. df Resid. Dev   TestDf LR stat.  Pr(Chi)
1  2121   1763.999   
2  2120   1732.787 1 vs 2 1 31.21204 2.313266e-08



And both seems to reject the null hypothesis.  Thanks again! 

Best, 
Faradj








> 27 jul 2016 kl. 13:35 skrev Fox, John :
> 
> Dear Faradj Koliev,
> 
> There is an anova() method for "polr" objects that computes LR chisquare 
> tests for nested models, so a short answer to your question is anova(Full, 
> Restricted).
> 
> The question, however, seems to reflect some misunderstandings. First aov() 
> fits linear analysis-of-variance models, which assume normally distributed 
> errors. These are different from the ordinal regression models, such as the 
> proportional-odds model, fit by polr(). For the former, F-tests *are* LR 
> tests; for the latter, F-tests aren't appropriate.
> 
> I hope this helps,
> John
> 
> -
> John Fox, Professor
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> Web: socserv.mcmaster.ca/jfox
> 
> 
> 
> 
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Faradj Koliev
>> Sent: July 27, 2016 4:50 AM
>> To: r-help@r-project.org
>> Subject: [R] Likelihood ratio test in porl (MASS)
>> 
>> Dear all,
>> 
>> A quick question: Let’s say I have a full and a restricted model that looks
>> something like this:
>> 
>> Full<- polr(Y ~ X1+X2+X3+X4, data=data, Hess = TRUE,  method="logistic”) #
>> ordered logistic regression
>> 
>> Restricted<- polr(Y ~ X1+X2+X3, data=data, Hess = TRUE,  method="logistic”) #
>> ordered logistic regression
>> 
>> I wanted to conduct the F-test (using aov command) in order to determine
>> whether the information from the X4 variable statistically improves our
>> understanding of Y.
>> However, I’ve been told that the likelihood ratio test is a better 
>> alternative. So,
>> I would like to conduct the LR test. In rms package this is easy -- 
>> lrest(Full,
>> Restricted) — I’m just curious how to perform the same using polr. Thanks!
>>  [[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.


[[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] Time format issue

2016-07-27 Thread Ismail SEZEN

>> The time column is factor. I want to convert each time to the following
>> format:
>> 
>> 20111211003000
>> 
>> 20111211013000
>> 
>> 2011121102
>> 
>> (Year)(month)(date)(hr)(min)(sec)
> 
>> newTimeDt <- strptime(Time, format="%d%b%y:%H:%M")
>> newTimeDt
> [1] "2011-12-27 00:30:00 PST" "2011-12-27 01:30:00 PST" "2011-12-27 02:00:00 
> PST"
>> newTimeDt <- as.POSIXct(Time, format="%d%b%y:%H:%M")
>> newTimeDt
> [1] "2011-12-27 00:30:00 PST" "2011-12-27 01:30:00 PST" "2011-12-27 02:00:00 
> PST"
>> newOut <- format(newTimeDt, "%Y%m%d%H%M")
>> newOut
> [1] "201112270030" "201112270130" "201112270200"
>> newOut <- format(newTimeDt, "%Y%m%d%H%M%S")
>> newOut
> [1] "20111227003000" "20111227013000" "2011122702"

Addition to David, if you use functions similar to read.csv or read.table to 
read dates from a file, you have to set 

stringsAsFactors = T

in function parameters or set data.frame column as character seperately.


[[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] Likelihood ratio test in porl (MASS)

2016-07-27 Thread Fox, John
Dear Faradj Koliev,

There is an anova() method for "polr" objects that computes LR chisquare tests 
for nested models, so a short answer to your question is anova(Full, 
Restricted).

The question, however, seems to reflect some misunderstandings. First aov() 
fits linear analysis-of-variance models, which assume normally distributed 
errors. These are different from the ordinal regression models, such as the 
proportional-odds model, fit by polr(). For the former, F-tests *are* LR tests; 
for the latter, F-tests aren't appropriate.

I hope this helps,
 John

-
John Fox, Professor
McMaster University
Hamilton, Ontario
Canada L8S 4M4
Web: socserv.mcmaster.ca/jfox




> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Faradj Koliev
> Sent: July 27, 2016 4:50 AM
> To: r-help@r-project.org
> Subject: [R] Likelihood ratio test in porl (MASS)
> 
> Dear all,
> 
> A quick question: Let’s say I have a full and a restricted model that looks
> something like this:
> 
> Full<- polr(Y ~ X1+X2+X3+X4, data=data, Hess = TRUE,  method="logistic”) #
> ordered logistic regression
> 
> Restricted<- polr(Y ~ X1+X2+X3, data=data, Hess = TRUE,  method="logistic”) #
> ordered logistic regression
> 
> I wanted to conduct the F-test (using aov command) in order to determine
> whether the information from the X4 variable statistically improves our
> understanding of Y.
> However, I’ve been told that the likelihood ratio test is a better 
> alternative. So,
> I would like to conduct the LR test. In rms package this is easy -- 
> lrest(Full,
> Restricted) — I’m just curious how to perform the same using polr. Thanks!
>   [[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] Aggregate matrix in a 2 by 2 manor

2016-07-27 Thread Anthoni, Peter (IMK)
Hi all,

I need to aggregate some matrix data (1440x720) to a lower dimension (720x360) 
for lots of years and variables

I can do double for loop, but that will be slow. Anybody know a quicker way?

here an example with a smaller matrix size:

tst=matrix(1:(8*4),ncol=8,nrow=4)
tst_2x2=matrix(NA,ncol=4,nrow=2)
nx=2
ny=2
for(ilon in seq(1,8,nx)) {
  for (ilat in seq(1,4,ny)) {
ilon_2x2=1+(ilon-1)/nx
ilat_2x2=1+(ilat-1)/ny
tst_2x2[ilat_2x2,ilon_2x2] = mean(tst[ilat+0:1,ilon+0:1])
  }
}

tst
tst_2x2

> tst
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]159   13   17   21   25   29
[2,]26   10   14   18   22   26   30
[3,]37   11   15   19   23   27   31
[4,]48   12   16   20   24   28   32

> tst_2x2
 [,1] [,2] [,3] [,4]
[1,]  3.5 11.5 19.5 27.5
[2,]  5.5 13.5 21.5 29.5


I though a cast to 3d-array might do the trick and apply over the new 
dimension, but that does not work, since it casts the data along the row.
> matrix(apply(array(tst,dim=c(nx,ny,8)),3,mean),nrow=nrow(tst)/ny)
 [,1] [,2] [,3] [,4]
[1,]  2.5 10.5 18.5 26.5
[2,]  6.5 14.5 22.5 30.5


cheers
Peter

__
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] Likelihood ratio test in porl (MASS)

2016-07-27 Thread Achim Zeileis

On Wed, 27 Jul 2016, Faradj Koliev wrote:

Dear all, 

A quick question: Let?s say I have a full and a restricted model that looks something like this: 

Full<- polr(Y ~ X1+X2+X3+X4, data=data, Hess = TRUE,  method="logistic?) # ordered logistic regression 

Restricted<- polr(Y ~ X1+X2+X3, data=data, Hess = TRUE,  method="logistic?) # ordered logistic regression 

I wanted to conduct the F-test (using aov command) in order to determine whether the information from the X4 variable statistically improves our understanding of Y. 
However, I?ve been told that the likelihood ratio test is a better alternative. So, I would like to conduct the LR test. In rms package this is easy -- lrest(Full, Restricted) ? I?m just curious how to perform the same using polr. Thanks!


One generic possibility to conduct the likelihood ratio test is the 
lrtest() function in package "lmtest", i.e.,


library("lmtest")
lrtest(Restricted, Full)


[[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] Likelihood ratio test in porl (MASS)

2016-07-27 Thread Faradj Koliev
Dear all, 

A quick question: Let’s say I have a full and a restricted model that looks 
something like this: 

Full<- polr(Y ~ X1+X2+X3+X4, data=data, Hess = TRUE,  method="logistic”) # 
ordered logistic regression 

Restricted<- polr(Y ~ X1+X2+X3, data=data, Hess = TRUE,  method="logistic”) # 
ordered logistic regression 

I wanted to conduct the F-test (using aov command) in order to determine 
whether the information from the X4 variable statistically improves our 
understanding of Y. 
However, I’ve been told that the likelihood ratio test is a better alternative. 
So, I would like to conduct the LR test. In rms package this is easy -- 
lrest(Full, Restricted) — I’m just curious how to perform the same using polr. 
Thanks!
[[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] about netcdf files

2016-07-27 Thread Jon Skoien
I think you get the error because you passed the object from nc_open(), 
you should rather pass the filename of the netCDF, so:

pre = brick("sample_precip_daily.nc")
 From the test-file, this gives you a RasterBrick-object with 5*9 pixels 
and 7305 layers.
Then you can extract data.frames of each layer with:
dframe = rasterToPoints(pre[[1]])
where 1 is the first layer, or time series with:
tseries = pre[3,4]
where 3 and 4 are the pixels in x and y-direction.

To write dframe to csv:
write.csv(dframe, filename = "csvfile.csv")
Check the function for more options.

Hope this helps you a bit further.
Jon

On 7/26/2016 9:07 PM, lily li wrote:
> Thanks for your reply. But it says "Error in (function (classes, fdef, 
> mtable)):
> unable to find an inherited method for function 'brick' for signature 
> 'ncdf4' "
>
> The dataset is attached. It contains daily precipitation data for 20 
> years, within a rectangle, so that there are several grid points. I 
> use the code to open it, but don't know how to get csv files, while 
> each file contains continuous daily precipitation data for each grid cell.
> pre1 = nc_open('sample_precip_daily.nc ')
> pre1
> pre1_rd = ncvar_get(pre1, 'precipitation')
> nc_close(pre1)
>
> Thanks for your help.
>
> On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien 
> > wrote:
>
> You could try with the brick function from the raster package.
>
> bvar = brick(netcdfName)
>
> This uses the ncdf4 functions for opening and reading the netcdf,
> but makes it easier to extract data for each day:
>
> p1 = rasterToPoints(bvar[[1]])
> and write p1 to csv.
>
> Best,
> Jon
>
>
>
> On 7/26/2016 6:54 AM, lily li wrote:
>
> Hi all,
>
> I have a problem in opening netcdf files. If one netcdf file
> contains
> longitude, latitude, and daily precipitation. How to relate each
> precipitation record to its associated location, and export
> them as csv
> files? Thanks.
>
> I just use nc_open(), ncvar_get(), but it is not very helpful.
> Thanks for
> any ideas.
>
> [[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.
>
>
> -- 
> Jon Olav Skøien
> Joint Research Centre - European Commission
> Institute for Space, Security & Migration
> Disaster Risk Management Unit
>
> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
>
> jon.sko...@jrc.ec.europa.eu 
> Tel: +39 0332 789205 
>
> Disclaimer: Views expressed in this email are those of the
> individual and do not necessarily represent official views of the
> European Commission.
>
>

-- 
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Space, Security & Migration
Disaster Risk Management Unit

Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY

jon.sko...@jrc.ec.europa.eu
Tel:  +39 0332 789205

Disclaimer: Views expressed in this email are those of the individual and do 
not necessarily represent official views of the European Commission.


[[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] Ocr

2016-07-27 Thread Shane Carey
Yep, I seen that!! Just don't know which one is best!! Any who, I'll try
them out and see how it goes!! I'm sure I'll be back looking for help!!!
Rhanks

On Wednesday, July 27, 2016, boB Rudis  wrote:

> https://cran.rstudio.com/web/packages/abbyyR/index.html
>
> https://github.com/greenore/ocR
>
> https://electricarchaeology.ca/2014/07/15/doing-ocr-within-r/
>
> that was from a Google "r ocr" search. So, yes, there are options.
>
> On Tue, Jul 26, 2016 at 6:43 PM, Achim Zeileis  > wrote:
> > On Wed, 27 Jul 2016, Shane Carey wrote:
> >
> >> Cool, thanks Jim!!
> >> I would love to be able to write my own script for this as I have many
> >> images/ pdf's in a folder and would like to batch process them using an
> R
> >> script!!
> >
> >
> > The underlying engine is "tesseract" which is also available as a
> > command-line tool and on other OSs. In principle, it is not hard to call
> it
> > with a system() command and then readLines() the resulting text.
> However, it
> > might be useful to play with the available options in the GUI first to
> see
> > what works best for your images.
> >
> >
> >> Thanks
> >>
> >> On Tuesday, July 26, 2016, Jim Lemon  > wrote:
> >>
> >>> Hi Shane,
> >>> FreeOCR is a really good place to start.
> >>>
> >>> http://www.paperfile.net/
> >>>
> >>> Jim
> >>>
> >>>
> >>> On Wed, Jul 27, 2016 at 6:11 AM, Shane Carey  
> >>> > wrote:
> 
>  Hi,
> 
>  Has anyone ever done any ocr in R?? I have some scanned images that I
> >>>
> >>> would
> 
>  like to convert to text!!
>  Thanks
> 
> 
>  --
>  Le gach dea ghui,
>  Shane
> 
>  [[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.
> >>>
> >>>
> >>
> >>
> >> --
> >> Le gach dea ghui,
> >> Shane
> >>
> >> [[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.
>


-- 
Le gach dea ghui,
Shane

[[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] Stack dataframes into a matrix

2016-07-27 Thread David Winsemius

> On Jul 26, 2016, at 8:07 PM, Anamika Chaudhuri  wrote:
> 
> I have 100 datasets with 20 rows and 2 columns in each dataset.
> I am looking for help to produce x and y below as 1000 X 20 matrix and then
> repeat that across 100 datasets using R
> 
> library(MASS)
> library(car)
> set.seed(1234)
> library(mixtools)
> library(sp)
> 
>for (k in 1:1){  # k IS THE NO OF DATASETS
>Y <- read.csv(file=paste0("MVNfreq",k,".csv"))

So this is not reproducible but from the description seems like 

do.call( rbind,  # the list of dataframes might "work" assuming column 
names are _all_ the same.

-- 
David.
> 
>Y<-as.matrix(Y)
>Y <- ifelse(Y==0,Y+.5,Y)
> 
> 
>Y1<-Y/60 # estimates of p
> 
>#print(Y1)
> 
> 
> sigma2<-matrix(c(var(Y1[,1]),cov(Y1[,1],Y1[,2]),cov(Y1[,1],Y1[,2]),var(Y1[,2])),2,2)
> 
>rho<-sigma2[1,2]/sqrt(sigma2[1,1]*sigma2[2,2])
>mean(Y1[,1])
>mean(Y1[,2])
> 
>#within<-matrix(data=0,nrow=20,ncol=1)
> 
>for (rate3 in 1:20){
>rate<-Y1[i,]
>#print(rate)
>rate1<-rate/(1-rate)
>rate2<-log(rate1)
> 
>Sigma11<-(1/(rate[1]*(1-rate[1]))^2)*sigma2[1,1]
>Sigma22<-(1/(rate[2]*(1-rate[2]))^2)*sigma2[2,2]
> 
> Sigma12<-(1/((rate[1]*(1-rate[1]))*(rate[2]*(1-rate[2]*sigma2[1,2]
> 
>Sigma2<-matrix(c(Sigma11,Sigma12,Sigma12,Sigma22),2,2)
> 
>rate3<-mvrnorm(1000, mu=c(rate2[1],rate2[2]), Sigma2)
>x<-exp(rate3[,1])/(1+exp(rate3[,1]))
>y<-exp(rate3[,2])/(1+exp(rate3[,2]))
>x<-as.data.frame(x)
>stack(x) # Need help to stack x into a single matrix
>print(x)
>print(y)
>}
>}
> 
>   [[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.

David Winsemius
Alameda, CA, USA

__
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] Stack dataframes into a matrix

2016-07-27 Thread Anamika Chaudhuri
I have 100 datasets with 20 rows and 2 columns in each dataset.
I am looking for help to produce x and y below as 1000 X 20 matrix and then
repeat that across 100 datasets using R

 library(MASS)
 library(car)
 set.seed(1234)
 library(mixtools)
 library(sp)

for (k in 1:1){  # k IS THE NO OF DATASETS
Y <- read.csv(file=paste0("MVNfreq",k,".csv"))

Y<-as.matrix(Y)
Y <- ifelse(Y==0,Y+.5,Y)


Y1<-Y/60 # estimates of p

#print(Y1)


sigma2<-matrix(c(var(Y1[,1]),cov(Y1[,1],Y1[,2]),cov(Y1[,1],Y1[,2]),var(Y1[,2])),2,2)

rho<-sigma2[1,2]/sqrt(sigma2[1,1]*sigma2[2,2])
mean(Y1[,1])
mean(Y1[,2])

#within<-matrix(data=0,nrow=20,ncol=1)

for (rate3 in 1:20){
rate<-Y1[i,]
#print(rate)
rate1<-rate/(1-rate)
rate2<-log(rate1)

Sigma11<-(1/(rate[1]*(1-rate[1]))^2)*sigma2[1,1]
Sigma22<-(1/(rate[2]*(1-rate[2]))^2)*sigma2[2,2]

Sigma12<-(1/((rate[1]*(1-rate[1]))*(rate[2]*(1-rate[2]*sigma2[1,2]

Sigma2<-matrix(c(Sigma11,Sigma12,Sigma12,Sigma22),2,2)

rate3<-mvrnorm(1000, mu=c(rate2[1],rate2[2]), Sigma2)
x<-exp(rate3[,1])/(1+exp(rate3[,1]))
y<-exp(rate3[,2])/(1+exp(rate3[,2]))
x<-as.data.frame(x)
stack(x) # Need help to stack x into a single matrix
print(x)
print(y)
}
}

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