Re: [R] (Fisher) Randomization Test for Matched Pairs: Permutation Data Setup Based on Signs

2012-03-11 Thread Petr Savicky
On Thu, Mar 08, 2012 at 09:49:20PM -0800, Ghandalf wrote:
 Hi,
 
 I am currently attempting to write a small program for a randomization test
 (based on rank/combination) for matched pairs. If you will please allow me
 to introduce you to some background information regarding the test prior to
 my question at hand, or you may skip down to the bold portion for my issue. 
 
 There are two sample sizes; the data, as I am sure you guessed, is matched
 into pairs and each pair's difference is denoted by Di. 
 
 The test statistic =*T* = Sum(Di) (only for those Di  0). 
 
 The issue I am having is based on the method required to use in R to setup
 the data into the proper structure. I am to consider the absolute value of
 Di, without regard to their sign. There are 2^n ways of assigning + or -
 signs to the set of absolute differences obtained, where n = the number of
 Dis. That is, we can assign + signs to all n of the |Di|, or we might assign
 + to |D1| but - signs to |D2| to |Dn|, and so forth.
 
  So, for example, if I have *D1=-16, D2=-4, D3=-7, D4=-3, D5=-5, D6=+1, and
 D7=-10 and n=7. *
 I need to consider the 2^7 ways of assigning signs that result in the lowest
 sum of the positive absolute difference. To exemplify further, we have
 *
 -16, -4, -7, -3, -5, -1, -10T = 0
 -16, -4, -7, -3, -5, +1, -10   T = 1
 -16, -4, -7, +3, -5, -1, -10   T = 3
 -16, -4, -7, +3, -5, +1, -10  T = 4 *
 ... and so on. 

Hi.

The minimum sum of positive absolute differencies is always
zero and is achieved for every sign combination, which
assigns -1 to all nonzero abs(Di) and any sign to zero abs(Di).
In particular, the combination rep(-1, times=7) is a solution.

I am not sure, whether this is, what you are asking for.
Can you give more detail?

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] (Fisher) Randomization Test for Matched Pairs: Permutation Data Setup Based on Signs

2012-03-11 Thread peter dalgaard

On Mar 11, 2012, at 03:17 , R. Michael Weylandt wrote:

 In general, I *think* this is a hard problem (it sounds knapsack-ish)
 but since you are on small enough data sets, that's probably not so
 important: if I understand you right, this little function will help
 you.
 
 plusminus - function(n){
t(as.matrix(do.call(expand.grid, rep(list(c(-1,1)), n
 }
 plusminus(3)
 plusminus(5)
 
 If you multiply the output of this function by your data set you will
 have rows corresponding to all possible sign choices: e.g.,
 
 plusminus(3) * c(1,2,3)
 
 Then you can colSums() using only the positive elements:
 
 x - plusminus(3) * c(1,2,3)
 x[x  0] - 0
 
 colSums(x)
 
 To wrap this all in one function: I'd do something like this:
 
 test.statistic - function(v){
m - t(as.matrix(do.call(expand.grid, rep(list(c(-1, 1)), length(v)
x - m * v
x[x0] - 0
out - rbind(m * v, colSums(x))
rownames(out)[length(rownames(out))] - Sum of Positive Elements
out
 }
 
 X - test.statistic(c(-16, -4, -7, -3, -5, +1, -10))
 X[,1:10]
 
 Hopefully that helps (I'm a little fuzzy on your overall goal -- so
 that second bit might be a red herring)

Looks pretty much OK to me. Just one note: In this sort of problem, you can do 
away with the business of the sum of the positive elements and just do the sum. 
This is because 

sum(x[x0])-sum(x[x0]) == sum(abs(x))
sum(x[x0])+sum(x[x0]) == sum(x)

and the sum(abs(x)) is of course the same, no matter how you assign signs to x. 
Add the two equations and divide by two and you get

sum(x[x0]) == (sum(x) + sum(abs(x))/2

This in turn means that you can just do 

allsums - as.matrix(do.call(expand.grid, rep(list(c(-1,1)), n))) %*% scores

and then mean(allsums = sum(scores)) to get the proportion of more extreme 
test statistics. You can even leave the signs on the scores in the computation 
of allsums because that will just affect the order of the sign-permuted samples.


 
 Michael
 
 
 On Fri, Mar 9, 2012 at 12:49 AM, Ghandalf mool...@hotmail.com wrote:
 Hi,
 
 I am currently attempting to write a small program for a randomization test
 (based on rank/combination) for matched pairs. If you will please allow me
 to introduce you to some background information regarding the test prior to
 my question at hand, or you may skip down to the bold portion for my issue.
 
 There are two sample sizes; the data, as I am sure you guessed, is matched
 into pairs and each pair's difference is denoted by Di.
 
 The test statistic =*T* = Sum(Di) (only for those Di  0).
 
 The issue I am having is based on the method required to use in R to setup
 the data into the proper structure. I am to consider the absolute value of
 Di, without regard to their sign. There are 2^n ways of assigning + or -
 signs to the set of absolute differences obtained, where n = the number of
 Dis. That is, we can assign + signs to all n of the |Di|, or we might assign
 + to |D1| but - signs to |D2| to |Dn|, and so forth.
 
  So, for example, if I have *D1=-16, D2=-4, D3=-7, D4=-3, D5=-5, D6=+1, and
 D7=-10 and n=7. *
 I need to consider the 2^7 ways of assigning signs that result in the lowest
 sum of the positive absolute difference. To exemplify further, we have
 *
 -16, -4, -7, -3, -5, -1, -10T = 0
 -16, -4, -7, -3, -5, +1, -10   T = 1
 -16, -4, -7, +3, -5, -1, -10   T = 3
 -16, -4, -7, +3, -5, +1, -10  T = 4 *
 ... and so on.
 
 So, if you are willing to help me, I am having trouble on setting up my data
 as illustrated above./ How do I create (a code for) the 2^n lines of data
 required with all the possible combinations of + and - in order to calculate
 the positive values in each line (the test statistic, T)?/ I have tried to
 use combn(d=data set, n=7) with a data set, d, consisting of both the
 positive and negative sign of the respective value, to no avail.
 
 I apologize if this is lengthy, I was not sure how to ask the aforementioned
 question without incorrectly portraying my thoughts. If any clarification is
 required then I will by more than willing to oblige with any further
 explanation. I have searched for possible solutions, but alas, came out
 empty handed.
 
 Thank you.
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Fisher-Randomization-Test-for-Matched-Pairs-Permutation-Data-Setup-Based-on-Signs-tp4458606p4458606.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

-- 

Re: [R] How do I do a pretty scatter plot using ggplot2?

2012-03-11 Thread Jim Lemon

On 03/10/2012 11:37 AM, Michael wrote:

Hi all,

I am trying hard to do the following and have already spent a few hours in
vain:

I wanted to do the scatter plot.

But given the high dispersion on those dots, I would like to bin the x-axis
and then for each bin of the x-axis, plot the quantiles of the y-values of
the data points in each bin:

1. Uniform bin size on the x-axis;
2. Equal number of observations in each bin;

How to do that in R? I guess for the sake of prettyness, I'd better do it
in ggplot2?


Hi Michael,
While it is not in ggplot2, a variation on the count.overplot function 
might do what you want. This function displays counts of closely spaced 
points rather than the points, but it applies the same area of 
aggregation across the whole plot. Getting the equal x bins is easy, and 
I assume that you mean equal observations within each bin, not across 
all bins. If you are stuck, I can probably hack up something from 
count.overplot.


Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Interfacing between Optimization Software and R

2012-03-11 Thread Renger van Nieuwkoop
Dear all

I was wondering, if there are reasons for R-Users to use (commercial) solver 
packages like GAMS, AMPL, Matlab, etc. 
These packages can solve all kind of mathematical optimization problems like 
(non-) linear problems, mixed complementarity problems, etc.

Why I want to know? GAMS corporation developed a R package to send data from 
GAMS to R (or vice versa). It is called gdxrxw.
I use this package a lot for my network models I solve with GAMS, sending the 
results from GAMS to R for plotting, generating tables in LaTeX and statistical 
analysis (see some of my post on blog.modelworks.ch). 
However, until now, for my personal use, I don't use the package the other way 
around (R - Gams).
I am writing a small article on this interface and was wondering if there are 
situations, where R-Users would be grateful for having the possibility to 
interact with solver software.
Any reaction would be very much appreciated.

Renger



Modelworks
Gewerbestrasse 15
3600 Thun - Switzerland
+41 79 818 53 73
i...@modelworks.ch
blog.modelworks.ch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Matrix negative fraction power

2012-03-11 Thread Ebrahim Jahanshiri
Dear list,

I understand that to raise matrix A to power (-1/2) we should use something
like this:

eigen(A)$vectors%*%diag(1/sqrt(eigen(A)$values))%*%t(eigen(A)$vectors)

[from previous discussions:
http://r.789695.n4.nabble.com/matrix-power-td900335.html]

But this will only do it for negative sqrt of the matrix not for other
fraction powers like (-3/2).
Seeing that these things be can done seamlessly in Matlab, I am wondering
if I am missing something in R.

Examples in Matlab:

A =
 1 1 1
 1 2 3
 1 3 6

 A^(-1/2 )=
1.5099   -0.82620.1937
   -0.82621.9586   -0.6937
0.1937   -0.69370.6937


 A^(-3/2)=
7.2020   -9.04813.3560
   -9.0481   13.6591   -5.4371
3.3560   -5.43712.2749

Thank you in advance.




-- 
Ebrahim Jahanshiri

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Interfacing between Optimization Software and R

2012-03-11 Thread Prof Brian Ripley

You missed a lot of indications, most prominently the task view

http://cran.r-project.org/web/views/Optimization.html


On 11/03/2012 07:18, Renger van Nieuwkoop wrote:

Dear all

I was wondering, if there are reasons for R-Users to use (commercial) solver 
packages like GAMS, AMPL, Matlab, etc.
These packages can solve all kind of mathematical optimization problems like 
(non-) linear problems, mixed complementarity problems, etc.

Why I want to know? GAMS corporation developed a R package to send data from 
GAMS to R (or vice versa). It is called gdxrxw.
I use this package a lot for my network models I solve with GAMS, sending the 
results from GAMS to R for plotting, generating tables in LaTeX and statistical 
analysis (see some of my post on blog.modelworks.ch).
However, until now, for my personal use, I don't use the package the other way 
around (R -  Gams).
I am writing a small article on this interface and was wondering if there are 
situations, where R-Users would be grateful for having the possibility to 
interact with solver software.
Any reaction would be very much appreciated.

Renger



Modelworks
Gewerbestrasse 15
3600 Thun - Switzerland
+41 79 818 53 73
i...@modelworks.ch
blog.modelworks.ch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [R-sig-eco] Landscape ecology in R

2012-03-11 Thread Sarah Goslee
Hi Manuel,

I've taken the liberty of adding the r-help list back to this email, even though
you sent your reply just to me, so that others may contribute.

On Fri, Mar 9, 2012 at 6:27 PM, Manuel Spínola mspinol...@gmail.com wrote:
 Thank you Sarah,

 I am thinking more on habitat mapping and landscape metrics.

Then you've probably seen the adehabitat* and SDMTools packages.

 I have been using several packages but I would like to see something more
 integrated for teaching.  It appear that there is a landscape package but I
 am trying to see where can I download it.

The R Way is to have many special-purpose packages: task views are very
useful to streamline installation. What specifically are you looking for that
what you're using doesn't provide?

I don't think there's a landscape package yet, just plans to create a landscape
package, although I have no idea what's it's intended to do.

Sarah

 2012/3/9 Sarah Goslee sarah.gos...@gmail.com

 What kind of landscape ecology analysis? There's a whole
 task view on spatial analysis. There's another task view
 on environmetrics. Both have material of interest to landscape
 ecologists. There are various packages
 that do habitat mapping, and landscape metrics, or interface
 with GIS software.

 Landscape ecology is such a broad discipline that we need
 more context to answer in more detail, but there's plenty of
 relevant material.

 I'm teaching a workshop on R for landscape ecologists
 at the US-IALE meeting next month, incidentally.

 Sarah

 On Fri, Mar 9, 2012 at 5:53 PM, Manuel Spínola mspinol...@gmail.com
 wrote:
  Dear list members,
 
  I am looking for any reference or material on landscape ecology analysis
  in
  R.
 
  Thank you very much in advance.
 
  Best,
 
  Manuel
 


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] function input as variable name (deparse/quote/paste) ??

2012-03-11 Thread Hans Ekbrand
On Sat, Mar 10, 2012 at 04:01:21PM -0800, casperyc wrote:
 Sorry if I wasn't stating what I really wanted or it was a bit confusing.
 
 Basically, there are MANY datasets to run suing the same function
 
 I have written a function to analyze it and returns a LIST of useful out put
 in the variable 'res' (to the workspace).
 
 I also created another script run.r such as
 
 myname(dat1)
 myname(dat2)
 myname(dat3)
 myname(dat4)
 myname(dat5) 
 
 For now, each time the output in the main workspace 'res' (the list) is over
 written.
 
 I want it to have different suffix to differentiate them. So I can have a
 look later after the batch is run.

I see no advantage in having that information in variable names. Just

- add the name of the data set to the information that is included in
  the returned list.

- run your function with sapply() and the returned list of sapply will
  be a list of lists.

-- 
Hans Ekbrand (http://sociologi.cjb.net) h...@sociologi.cjb.net

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] too many open devices

2012-03-11 Thread harold kincaid
Many thanks for your answer. I am using someone else's code that has
worked fine for some time and don't know much about R graphics.
Windows are being opened, the clutter is definitely there, and it
looks like dev.off is not being used. So at least it probably is not a
stupid attack on my part. So your response was helpful. Thanks for
taking the time to respond. Harold

On Sun, Mar 11, 2012 at 1:39 AM, Patrick Connolly
p_conno...@slingshot.co.nz wrote:
 On Sat, 10-Mar-2012 at 02:21PM -0600, harold kincaid wrote:

 | I am getting too many open devices after 60 graphs. The archived
 | comments on this problem were too sketchy to be helpful. Any ideas?

 With minimal information, my guess might not be correct, but I suspect
 you're plotting to a Windows device and a new one is opened for each
 of your plots.  That would be some clutter on your screen.

 You'd make life simpler if you used a pdf device that uses a new page
 for each of your plots which can be hundreds of pages if you like.

 Check out the help for pdf(), making sure you don't forget the
 dev.off() part.


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

 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Matrix negative fraction power

2012-03-11 Thread Peter Langfelder
On Sun, Mar 11, 2012 at 1:46 AM, Ebrahim Jahanshiri
e.jahansh...@gmail.com wrote:
 Dear list,

 I understand that to raise matrix A to power (-1/2) we should use something
 like this:

 eigen(A)$vectors%*%diag(1/sqrt(eigen(A)$values))%*%t(eigen(A)$vectors)

 [from previous discussions:
 http://r.789695.n4.nabble.com/matrix-power-td900335.html]

 But this will only do it for negative sqrt of the matrix not for other
 fraction powers like (-3/2).

Not sure why you think this won't work for -3/2 - simply use
eigen(A)$values^(-3/2) instead of the 1/sqrt(eigen(A)$values) and
you're good to go. Generalizations to other powers are left as
exercise for the reader :)

Peter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Matrix negative fraction power

2012-03-11 Thread Joshua Wiley
On Sun, Mar 11, 2012 at 8:56 AM, Peter Langfelder
peter.langfel...@gmail.com wrote:
 On Sun, Mar 11, 2012 at 1:46 AM, Ebrahim Jahanshiri
 e.jahansh...@gmail.com wrote:
 Dear list,

 I understand that to raise matrix A to power (-1/2) we should use something
 like this:

 eigen(A)$vectors%*%diag(1/sqrt(eigen(A)$values))%*%t(eigen(A)$vectors)

 [from previous discussions:
 http://r.789695.n4.nabble.com/matrix-power-td900335.html]

 But this will only do it for negative sqrt of the matrix not for other
 fraction powers like (-3/2).

 Not sure why you think this won't work for -3/2 - simply use
 eigen(A)$values^(-3/2) instead of the 1/sqrt(eigen(A)$values) and
 you're good to go. Generalizations to other powers are left as
 exercise for the reader :)

also please be kind to your poor computer and store and reuse
eigen(A), that is not trivial to compute!


 Peter

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Efficient access to elements of a list of lists

2012-03-11 Thread Benilton Carvalho
Hi,

I have a long list of lists from which I want to efficiently extract
and rbind elements. So I'm using the approach below:


f - function(i){
out - replicate(5, list(matrix(rnorm(80), nc=20)))
names(out) - letters[1:5]
out
}
set.seed(1)
lst - lapply(1:1.5e6, f)
(t0 - system.time(tmp - do.call(rbind, lapply(lst, '[[', 'b'


Is there anything better/faster than the do.call+rbind+lapply combo
above? On this example, the combo takes roughly 20s on my machine...
but on the data I'm working with, it takes more than 1 minute... And
given that I need to repeat the task several times, the cumul. amount
of time is significant for me.

Thank you for any suggestion/comment,

benilton

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Fwd: Matrix negative fraction power

2012-03-11 Thread Ebrahim Jahanshiri
Thank you very much Peter,

Indeed this should be left to the reader/practitioner. But I think -at
least for the sake of comparison with matlab- we could have it in the core
R. I would definitely try to learn more about R and implement it later.

Cheers,
Ebrahim


On Sun, Mar 11, 2012 at 11:56 PM, Peter Langfelder 
peter.langfel...@gmail.com wrote:

 On Sun, Mar 11, 2012 at 1:46 AM, Ebrahim Jahanshiri
 e.jahansh...@gmail.com wrote:
  Dear list,
 
  I understand that to raise matrix A to power (-1/2) we should use
 something
  like this:
 
  eigen(A)$vectors%*%diag(1/sqrt(eigen(A)$values))%*%t(eigen(A)$vectors)
 
  [from previous discussions:
  http://r.789695.n4.nabble.com/matrix-power-td900335.html]
 
  But this will only do it for negative sqrt of the matrix not for other
  fraction powers like (-3/2).

 Not sure why you think this won't work for -3/2 - simply use
 eigen(A)$values^(-3/2) instead of the 1/sqrt(eigen(A)$values) and
 you're good to go. Generalizations to other powers are left as
 exercise for the reader :)

 Peter




-- 
Ebrahim Jahanshiri
Spatial and Numerical lab
ITMA
Universiti Putra Malaysia
43300, Selangor,
Malaysia
+60172002427
e.jahansh...@gmail.com




-- 
Ebrahim Jahanshiri
Spatial and Numerical lab
ITMA
Universiti Putra Malaysia
43300, Selangor,
Malaysia
+60172002427
e.jahansh...@gmail.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Matrix negative fraction power

2012-03-11 Thread Spencer Graves
  If my memory is correct, the archives of this list contains 
several discussions of round off error problems associated with 
different methods for computing things like this.  The Matrix package 
(part of the base distribution) contains a function expm, whose help 
file says, The expm package contains newer (partly faster and more 
accurate) algorithms for expm() and includes logm and sqrtm.  This 
suggests to me that the most numerically stable way to get an arbitrary 
power p of a matrix M in R might be as follows:



expm(p*logm(M))


  If compute time becomes an issue, I would want to do numerical 
comparisons of the results from this with the results from the your 
other method.



  Hope this helps.
  Spencer


p.s.  I found the above in part by using findFn('expm') after 
library(sos).



On 3/11/2012 9:14 AM, Joshua Wiley wrote:

On Sun, Mar 11, 2012 at 8:56 AM, Peter Langfelder
peter.langfel...@gmail.com  wrote:

On Sun, Mar 11, 2012 at 1:46 AM, Ebrahim Jahanshiri
e.jahansh...@gmail.com  wrote:

Dear list,

I understand that to raise matrix A to power (-1/2) we should use something
like this:

eigen(A)$vectors%*%diag(1/sqrt(eigen(A)$values))%*%t(eigen(A)$vectors)

[from previous discussions:
http://r.789695.n4.nabble.com/matrix-power-td900335.html]

But this will only do it for negative sqrt of the matrix not for other
fraction powers like (-3/2).

Not sure why you think this won't work for -3/2 - simply use
eigen(A)$values^(-3/2) instead of the 1/sqrt(eigen(A)$values) and
you're good to go. Generalizations to other powers are left as
exercise for the reader :)

also please be kind to your poor computer and store and reuse
eigen(A), that is not trivial to compute!


Peter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




--
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Matrix negative fraction power

2012-03-11 Thread Berend Hasselman

On 11-03-2012, at 17:52, Spencer Graves wrote:

  If my memory is correct, the archives of this list contains several 
 discussions of round off error problems associated with different methods for 
 computing things like this.  The Matrix package (part of the base 
 distribution) contains a function expm, whose help file says, The expm 
 package contains newer (partly faster and more accurate) algorithms for 
 expm() and includes logm and sqrtm.  This suggests to me that the most 
 numerically stable way to get an arbitrary power p of a matrix M in R might 
 be as follows:
 
 
expm(p*logm(M))
 

I have just tested and it should be this

library(expm)

expm((-1/2)*logm(A))
expm((-3/2)*logm(A))


Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Matrix negative fraction power

2012-03-11 Thread Berend Hasselman

On 11-03-2012, at 18:18, Berend Hasselman wrote:

 
 On 11-03-2012, at 17:52, Spencer Graves wrote:
 
 If my memory is correct, the archives of this list contains several 
 discussions of round off error problems associated with different methods 
 for computing things like this.  The Matrix package (part of the base 
 distribution) contains a function expm, whose help file says, The expm 
 package contains newer (partly faster and more accurate) algorithms for 
 expm() and includes logm and sqrtm.  This suggests to me that the most 
 numerically stable way to get an arbitrary power p of a matrix M in R might 
 be as follows:
 
 
   expm(p*logm(M))
 
 
 I have just tested and it should be this
 
 library(expm)
 
 expm((-1/2)*logm(A))
 expm((-3/2)*logm(A))
 

Indeed. It's getting on and I made a muddle.

Berend
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] function input as variable name (deparse/quote/paste) ??

2012-03-11 Thread casperyc
Thank you everyone for your reply.

Like I said in my original post, this is just a demonstrative example of my
'big' self written script.

My 'big' function take several inputs, of which the first 1 is the dataset
and returns a LIST variable 'res-list()' to the workspace with many
information.

The names of my actual datasets are NOT in any pattern, like 'dat1', 'dat2',
'dat3'. That's why i wonder if I can modify
the line 'res-' in anyway to be 'res.dat-' where 'dat' in the first
input. So I can CALL via 'res.dat' (or res.newdata, res.olddata,
res.tmpdata,res.hisdata) in the workspace any time I want to have a look.

-
###
PhD candidate in Statistics
School of Mathematics, Statistics and Actuarial Science, University of Kent
###

--
View this message in context: 
http://r.789695.n4.nabble.com/function-input-as-variable-name-deparse-quote-paste-tp4462841p4464294.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Efficient access to elements of a list of lists

2012-03-11 Thread Henrik Bengtsson
On Sun, Mar 11, 2012 at 9:18 AM, Benilton Carvalho
beniltoncarva...@gmail.com wrote:
 Hi,

 I have a long list of lists from which I want to efficiently extract
 and rbind elements. So I'm using the approach below:


 f - function(i){
    out - replicate(5, list(matrix(rnorm(80), nc=20)))
    names(out) - letters[1:5]
    out
 }
 set.seed(1)
 lst - lapply(1:1.5e6, f)
 (t0 - system.time(tmp - do.call(rbind, lapply(lst, '[[', 'b'


 Is there anything better/faster than the do.call+rbind+lapply combo
 above?

The [[ function involves method dispatching.  You can avoid that by
using .subset2().  That may save you some (micro?)seconds.

Now, if all extracted elements are truly of the same dimensions;

 bList - lapply(lst, FUN='[[', 'b')
 str(head(bList))
List of 6
 $ : num [1:4, 1:20] 0.936 -0.844 -0.221 -0.581 -2.513 ...
 $ : num [1:4, 1:20] -0.2618 0.0259 -1.3131 -0.0547 -0.3296 ...
 $ : num [1:4, 1:20] -1.589 0.844 -1.121 0.21 -0.846 ...
 $ : num [1:4, 1:20] -1.192 -1.268 1.688 -0.295 0.466 ...
 $ : num [1:4, 1:20] 2.504 -0.833 -1.751 1.117 -0.775 ...
 $ : num [1:4, 1:20] 0.119 -0.313 1.741 0.403 -0.261 ...

then you can avoid the rbind(), by doing an unlist()/dim()/aperm(), e.g.

# Extract 'b' as an 4-by-20-by-1.5e6 array
dim - dim(bList[[1]]);
n - length(bList);
bArray - unlist(bList, use.names=FALSE);
dimA - c(dim, n);
dim(bArray) - dimA;

# If you really need a matrix, then...

# Turing into a (4*1.5e6)-by-20 array
dimM - dim;
dimM[1] - n*dimM[1];
bMatrix - aperm(bArray, perm=c(1,3,2));
dim(bMatrix) - dimM;

You owe me a beer ;)

/Henrik

 On this example, the combo takes roughly 20s on my machine...
 but on the data I'm working with, it takes more than 1 minute... And
 given that I need to repeat the task several times, the cumul. amount
 of time is significant for me.

 Thank you for any suggestion/comment,

 benilton

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Efficient access to elements of a list of lists

2012-03-11 Thread Benilton Carvalho
Thanks Henrik!!! Hope to pay your beer soon. :) b

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Warnings when plotting after x11() in R 2.14.2

2012-03-11 Thread Uwe Ligges



On 08.03.2012 21:03, Mark Seeto wrote:

Dear R-help,

I recently upgraded from R 2.13.1 to R 2.14.2 and now get warning
messages when plotting after using x11(). Example:


plot(rnorm(10))### no warnings



x11(); plot(rnorm(10))

Warning messages:
1: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
2: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
3: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
4: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
5: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
6: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
7: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
8: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
9: In title(...) : Font family not found in Windows font database
10: In title(...) : Font family not found in Windows font database


plot(rnorm(10))### After using x11(), I get warnings even when x11() is not 
used

There were 18 warnings (use warnings() to see them)

warnings()

Warning messages:
1: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
2: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
3: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
4: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
5: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
6: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
7: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
8: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
9: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
10: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
11: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
12: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
13: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
14: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
15: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
16: In axis(side = side, at = at, labels = labels, ...) :
   Font family not found in Windows font database
17: In title(...) : Font family not found in Windows font database
18: In title(...) : Font family not found in Windows font database

This happens in both the 32 and 64 bit versions of R 2.14.2, and it
also happens with ggplot2 plots. I'm using RGui on Windows 7. It did
not happen with R 2.13.1.

It's not a major problem, because the plots still appear to be
produced correctly, but if anyone can tell me how to fix it, I'd
appreciate it.


Use dev.new() rather than x11(). Under Windows, there is a windows() 
device but no x11() device. R tries hard to work around your user error 
(calling x11() under Windows).


Uwe Ligges




Thanks,
Mark Seeto

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] extracting data from unstructured (text?) file

2012-03-11 Thread frauke
Dear R community, 

I have the following problem I hoped you could help me with. 

My data is save in thousand of files with a weird extension containing for
numbers and a z. For example *.1405z. With list.files I managed to load this
data into R. It looks like this (the row numbers are not in the original
file):

35 :LATEST STAGE 3.60 FT AT 730 AM CST ON
0102
36  .ER ARCT20102 C
DC21020813/DH12/HGIFF/DIH6
37   :QPF FORECAST6AM   NOON6PM  
MDNT
38   .E1 :0102:  /   3.5/   3.4/  
3.5
39   .E2 :0103:   /   3.5/   3.0/   2.5/  
2.1
40   .E3 :0104:   /   1.8/   1.5/   1.3/  
1.2
41   .E4 :0105:   /   1.2/   1.8/   2.3/  
2.7
42   .E5 :0106:   /   3.0/   3.0/   3.1/  
3.3
43.E6 :0107:   /  
3.4

I need the table in rows 37 to 43 in a matrix, for example:
0201 NA3.53.43.5
0103 3.53.02.5 2.1
0104 1.81.51.31.2
01051.2 1.82.32.7
0106 3.03.03.13.3
0107 3.4NANA   NA

 Unfortunately the row numbers vary per file.  I can call up each line with
file[40,1] for line 40 for example. It returns:
[1] .E3 :0104:   /   1.8/   1.5/   1.3/   1.2
38 Levels: .E1 :0102:  /   3.5/   3.4/   3.5 ...

 So I have two problems really:
1. How do I detect the table in the file (resp. the line where the table
starts)?
2. How do I break up each line to write the values into a matrix?

Feel free to suggest an entirely different approach if you think that is
helpful. 

Thanks a lot! Frauke



--
View this message in context: 
http://r.789695.n4.nabble.com/extracting-data-from-unstructured-text-file-tp4464423p4464423.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extracting data from unstructured (text?) file

2012-03-11 Thread jim holtman
Can you at least provide a subset of 2 files so we can see how the
data is really stored in the file and what the separators are between
the 'columns' of data.  Also how do you determine where the data
actually starts for the rows that you want to pull off.  This will aid
in determining how to parse the data.

On Sun, Mar 11, 2012 at 3:07 PM, frauke fh...@andrew.cmu.edu wrote:
 Dear R community,

 I have the following problem I hoped you could help me with.

 My data is save in thousand of files with a weird extension containing for
 numbers and a z. For example *.1405z. With list.files I managed to load this
 data into R. It looks like this (the row numbers are not in the original
 file):

 35                             :LATEST STAGE     3.60 FT AT 730 AM CST ON
 0102
 36                          .ER ARCT2    0102 C
 DC21020813/DH12/HGIFF/DIH6
 37                   :QPF FORECAST        6AM       NOON        6PM
 MDNT
 38                   .E1 :0102:              /       3.5/       3.4/
 3.5
 39                   .E2 :0103:   /       3.5/       3.0/       2.5/
 2.1
 40                   .E3 :0104:   /       1.8/       1.5/       1.3/
 1.2
 41                   .E4 :0105:   /       1.2/       1.8/       2.3/
 2.7
 42                   .E5 :0106:   /       3.0/       3.0/       3.1/
 3.3
 43                                                    .E6 :0107:   /
 3.4

 I need the table in rows 37 to 43 in a matrix, for example:
 0201     NA    3.5    3.4    3.5
 0103     3.5    3.0    2.5     2.1
 0104     1.8    1.5    1.3    1.2
 0105    1.2     1.8    2.3    2.7
 0106     3.0    3.0    3.1    3.3
 0107     3.4    NA    NA   NA

  Unfortunately the row numbers vary per file.  I can call up each line with
 file[40,1] for line 40 for example. It returns:
 [1] .E3 :0104:   /       1.8/       1.5/       1.3/       1.2
 38 Levels: .E1 :0102:              /       3.5/       3.4/       3.5 ...

  So I have two problems really:
 1. How do I detect the table in the file (resp. the line where the table
 starts)?
 2. How do I break up each line to write the values into a matrix?

 Feel free to suggest an entirely different approach if you think that is
 helpful.

 Thanks a lot! Frauke



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/extracting-data-from-unstructured-text-file-tp4464423p4464423.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extracting data from unstructured (text?) file

2012-03-11 Thread Vijaya Parthiban
Hi Frauke,

Try unix commands with R's system() function.

Example:
Let's say you have a matrix like this in the file (note: the first element
is missing) called hello.txt
10 100
2 20 200
3 30 300
4 40 400
5 50 500

You can try something like:

hello = system(cut -f1 hello.txt, intern=T)

VP.

On 11 March 2012 19:07, frauke fh...@andrew.cmu.edu wrote:

 Dear R community,

 I have the following problem I hoped you could help me with.

 My data is save in thousand of files with a weird extension containing for
 numbers and a z. For example *.1405z. With list.files I managed to load
 this
 data into R. It looks like this (the row numbers are not in the original
 file):

 35 :LATEST STAGE 3.60 FT AT 730 AM CST ON
 0102
 36  .ER ARCT20102 C
 DC21020813/DH12/HGIFF/DIH6
 37   :QPF FORECAST6AM   NOON6PM
 MDNT
 38   .E1 :0102:  /   3.5/   3.4/
 3.5
 39   .E2 :0103:   /   3.5/   3.0/   2.5/
 2.1
 40   .E3 :0104:   /   1.8/   1.5/   1.3/
 1.2
 41   .E4 :0105:   /   1.2/   1.8/   2.3/
 2.7
 42   .E5 :0106:   /   3.0/   3.0/   3.1/
 3.3
 43.E6 :0107:   /
 3.4

 I need the table in rows 37 to 43 in a matrix, for example:
 0201 NA3.53.43.5
 0103 3.53.02.5 2.1
 0104 1.81.51.31.2
 01051.2 1.82.32.7
 0106 3.03.03.13.3
 0107 3.4NANA   NA

  Unfortunately the row numbers vary per file.  I can call up each line with
 file[40,1] for line 40 for example. It returns:
 [1] .E3 :0104:   /   1.8/   1.5/   1.3/   1.2
 38 Levels: .E1 :0102:  /   3.5/   3.4/   3.5 ...

  So I have two problems really:
 1. How do I detect the table in the file (resp. the line where the table
 starts)?
 2. How do I break up each line to write the values into a matrix?

 Feel free to suggest an entirely different approach if you think that is
 helpful.

 Thanks a lot! Frauke



 --
 View this message in context:
 http://r.789695.n4.nabble.com/extracting-data-from-unstructured-text-file-tp4464423p4464423.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Problems when building a package for Windows 64

2012-03-11 Thread Eduardo Mendes
Hello

I have recently installed R 2.14.2 on a brand new pc running Windows 64.
One of things I would like to do is to recompile my R package (with C and
fortran source codes) for this new environment (it works on a mac and on a
linux box).  To this end, I had rtools 2.14 downloaded and installed (I
have also added 2.14.2/bin/x64 to PATH so that Rcmd works on a terminal).

On a cmd terminal I issue the command Rcmd INSTALL build name_of_my_package
to get

(x86 works fine)

*** arch - x64
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-214~1.2/etc/x64/Makeconf
  Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-214~1.2/etc/x64/Makeco
nf
  CYGWIN environment variable option nodosfilewarning turns off this
warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gfortran -m64 -O2  -mtune=core2 -c correl.f -o correl.o
f951.exe: sorry, unimplemented: 64-bit mode not compiled in
make: *** [correl.o] Error 1
ERROR: compilation failed for package

What am I missing?

Many thanks

Ed

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems when building a package for Windows 64

2012-03-11 Thread Prof Brian Ripley

On 11/03/2012 19:43, Eduardo Mendes wrote:

Hello

I have recently installed R 2.14.2 on a brand new pc running Windows 64.
One of things I would like to do is to recompile my R package (with C and
fortran source codes) for this new environment (it works on a mac and on a
linux box).  To this end, I had rtools 2.14 downloaded and installed (I
have also added 2.14.2/bin/x64 to PATH so that Rcmd works on a terminal).


That's the error you made.  That toolchain is the default for R = 
2.14.1 but not for 2.14.2.  Please do the homework the posting guide 
asked of you, e.g. read http://cran.r-project.org/bin/windows/Rtools/ or 
if you want to use the earlier version of Rtools, read 
http://cran.r-project.org/doc/manuals/R-admin.html and set MkRules.local 
accordingly.



On a cmd terminal I issue the command Rcmd INSTALL build name_of_my_package
to get

(x86 works fine)

*** arch - x64
cygwin warning:
   MS-DOS style path detected: C:/PROGRA~1/R/R-214~1.2/etc/x64/Makeconf
   Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-214~1.2/etc/x64/Makeco
nf
   CYGWIN environment variable option nodosfilewarning turns off this
warning.


That's in the manual, too 


   Consult the user's guide for more details about POSIX paths:
 http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gfortran -m64 -O2  -mtune=core2 -c correl.f -o correl.o
f951.exe: sorry, unimplemented: 64-bit mode not compiled in
make: *** [correl.o] Error 1
ERROR: compilation failed for package

What am I missing?

Many thanks

Ed

[[alternative HTML version deleted]]


The posting guide asked you not to send HTML.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Did we mention the posting guide?

--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extracting data from unstructured (text?) file

2012-03-11 Thread frauke
Thank you for the quick reply! I have attached two files.

http://r.789695.n4.nabble.com/file/n4464511/sample1.1339z sample1.1339z 
http://r.789695.n4.nabble.com/file/n4464511/sample2.1949z sample2.1949z 

--
View this message in context: 
http://r.789695.n4.nabble.com/extracting-data-from-unstructured-text-file-tp4464423p4464511.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems when building a package for Windows 64

2012-03-11 Thread Eduardo Mendes
Dear Prof. Ripley

Many thanks. rtools 2.15 did the job.

One note if I may - In the rtools site one reads

rtools215.exe - r2.14.1 to R 2.15.x No
rtoosl214.exe - r 2.13.x or R.2.14.x yes

which can mislead the reader.  2.14.x could mean 2.14.2 and no could mean
that rtools-2.15 is not read for prime time.

Ed

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Siegel-Tukey test for equal variability (code)

2012-03-11 Thread Tal Galili
Update:
The siegel Tukey code is now fixed (both on the github page, and the blog's
post):
https://github.com/talgalili/R-code-snippets/blob/master/siegel.tukey.r
http://www.r-statistics.com/2010/02/siegel-tukey-a-non-parametric-test-for-equality-in-variability-r-code/


Best,
Tal




On Sat, Mar 10, 2012 at 12:05 AM, Tal Galili tal.gal...@gmail.com wrote:

 With coordination with the code's author (Daniel),
 The updated code has been uploaded to github here:
 https://github.com/talgalili/R-code-snippets/blob/master/siegel.tukey.r
 And also the following post was updated with the code:

 http://www.r-statistics.com/2010/02/siegel-tukey-a-non-parametric-test-for-equality-in-variability-r-code/

 I suspect that the code still needs some tweaks so it will be able to take
 care of two vectors of different lengths.


 Tal

 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)

 --




 On Fri, Mar 9, 2012 at 11:11 PM, Daniel Malter dan...@umd.edu wrote:

 #The code of rank 1 in the previous post should have read
 #rank1-apply(iterator1,1,function(x) x+base1)
 #corrected code below


 siegel.tukey=function(x,y,id.col=TRUE,adjust.median=F,rnd=-1,alternative=two.sided,mu=0,paired=FALSE,exact=FALSE,correct=TRUE,
 conf.int=FALSE,conf.level=0.95){
 if(id.col==FALSE){
   data=data.frame(c(x,y),rep(c(0,1),c(length(x),length(y
   } else {
data=data.frame(x,y)
   }
  names(data)=c(x,y)
  data=data[order(data$x),]
  if(rnd-1){data$x=round(data$x,rnd)}

  if(adjust.median==T){
cat(\n,Adjusting medians...,\n,sep=)
data$x[data$y==0]=data$x[data$y==0]-(median(data$x[data$y==0]))
data$x[data$y==1]=data$x[data$y==1]-(median(data$x[data$y==1]))
  }
  cat(\n,Median of group 1 = ,median(data$x[data$y==0]),\n,sep=)
  cat(Median of group 2 = ,median(data$x[data$y==1]),\n,\n,sep=)
  cat(Testing median differences...,\n)
  print(wilcox.test(data$x[data$y==0],data$x[data$y==1]))


  cat(Performing Siegel-Tukey rank transformation...,\n,\n)

 sort.x-sort(data$x)
 sort.id-data$y[order(data$x)]

 data.matrix-data.frame(sort.x,sort.id)

 base1-c(1,4)
 iterator1-matrix(seq(from=1,to=length(x),by=4))-1
 rank1-apply(iterator1,1,function(x) x+base1)

 iterator2-matrix(seq(from=2,to=length(x),by=4))
 base2-c(0,1)
 rank2-apply(iterator2,1,function(x) x+base2)

 #print(rank1)
 #print(rank2)

 if(length(rank1)==length(rank2)){

  rank-c(rank1[1:floor(length(x)/2)],rev(rank2[1:ceiling(length(x)/2)]))
} else{

  rank-c(rank1[1:ceiling(length(x)/2)],rev(rank2[1:floor(length(x)/2)]))
 }


 unique.ranks-tapply(rank,sort.x,mean)
 unique.x-as.numeric(as.character(names(unique.ranks)))

 rank.matrix-data.frame(unique.x,unique.ranks)

 ST.matrix-merge(data.matrix,rank.matrix,by.x=sort.x,by.y=unique.x)

 print(ST.matrix)

 cat(\n,Performing Siegel-Tukey test...,\n,sep=)

 ranks0-ST.matrix$unique.ranks[ST.matrix$sort.id==0]
 ranks1-ST.matrix$unique.ranks[ST.matrix$sort.id==1]

 cat(\n,Mean rank of group 0: ,mean(ranks0),\n,sep=)
 cat(Mean rank of group 1: ,mean(ranks1),\n,sep=)


 print(wilcox.test(ranks0,ranks1,alternative=alternative,mu=mu,paired=paired,exact=exact,correct=correct,
 conf.int=conf.int,conf.level=conf.level))
 }

 Examples:

 x - c(33, 62, 84, 85, 88, 93, 97, 4, 16, 48, 51, 66, 98)
 id - c(0,0,0,0,0,0,0,1,1,1,1,1,1)

 siegel.tukey(x,id,adjust.median=F,exact=T)

 x-c(0,0,1,4,4,5,5,6,6,9,10,10)
 id-c(0,0,0,1,1,1,1,1,1,0,0,0)

 siegel.tukey(x,id)

 x - c(85,106,96, 105, 104, 108, 86)
 id-c(0,0,1,1,1,1,1)

 siegel.tukey(x,id)


 x-c(177,200,227,230,232,268,272,297,47,105,126,142,158,172,197,220,225,230,262,270)
 id-c(rep(0,8),rep(1,12))

 siegel.tukey(x,id,adjust.median=T)


 --
 View this message in context:
 http://r.789695.n4.nabble.com/Siegel-Tukey-test-for-equal-variability-code-tp1565053p4460705.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extracting data from unstructured (text?) file

2012-03-11 Thread jim holtman
Here is one way assuming the data start after QPF FORECAST:

 setwd('/temp')  # where the data is
 files - c('sample1.htm', 'sample2.htm')  # files to read
 # assumes 4 columns of data
 fields - list(c(19, 24), c(30, 35), c(41, 46), c(52, 57))  #columns of data
 results - lapply(files, function(.file){
+ inData - FALSE  # switch to indicate in data
+ collection - NULL  # will hold the data
+ inputFile - file(.file, 'r')  # open the connection
+ repeat{
+ input - readLines(inputFile, n = 1)
+ if (inData){  # parse the line and collect data
+ key - sub(^.E[0-9]+[^:]*:([^:]+).*, \\1, input)
+ if (nchar(key) != 4){ # done with data; return result
+ colnames(collection) - colNames
+ close(inputFile)
+ return(collection)
+ }
+ # get the data assuming that 'fields' defines where data is
+ cols - numeric(length(fields))
+ for (i in seq_along(fields)){
+ cols[i] - as.numeric(substring(input
+ , fields[[i]][1]
+ , fields[[i]][2]
+ )
+  )
+ }
+ collection - rbind(collection, cols)
+ rownames(collection)[nrow(collection)] - key
+ } else {  # looking for the start of the data
+ if (grepl(^:QPF FORECAST, input)){
+ # extract the column names
+ colNames - NULL
+ for (i in seq_along(fields)){
+ colNames - c(colNames, substring(input
+ , fields[[i]][1]
+ , fields[[i]][2]
+ )
+  )
+ }
+ inData - TRUE  # now get the data
+ }
+ }
+ }
+ })
Warning message:
NAs introduced by coercion
 print(results)
[[1]]
7AM1PM7PM1AM
0830 NA5.64.43.8
08313.33.02.62.5
09012.32.22.22.1
09022.12.02.02.0
09032.01.91.91.9
09041.8 NA NA NA

[[2]]
7AM1PM7PM1AM
0604 NA NA7.08.4
06059.49.28.67.8
06066.85.64.23.5
06073.23.02.92.8
06082.82.82.72.7
06092.7 NA NA NA



On Sun, Mar 11, 2012 at 4:07 PM, frauke fh...@andrew.cmu.edu wrote:
 Thank you for the quick reply! I have attached two files.

 http://r.789695.n4.nabble.com/file/n4464511/sample1.1339z sample1.1339z
 http://r.789695.n4.nabble.com/file/n4464511/sample2.1949z sample2.1949z

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/extracting-data-from-unstructured-text-file-tp4464423p4464511.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] CRAN (and crantastic) updates this week

2012-03-11 Thread Crantastic
CRAN (and crantastic) updates this week

New packages


* EffectStars (1.0)
  Maintainer: Unknown
  Author(s): Gunther Schauberger
  License: GPL-2
  http://crantastic.org/packages/EffectStars

  The package provides functions to visualize regression models with
  categorical response. The effects of the covariates are plotted with
  star plots in order to allow for an optical impression of the fitted
  model.

* extraBinomial (2.0)
  Maintainer: Xin Yang
  Author(s): Xin Yang
  License: GPL-3
  http://crantastic.org/packages/extraBinomial

  This package tests for differences in minor allele frequency between
  groups and is based on an extra-binomial variation model for pooled
  sequencing data. A set of simulated pooled sequencing data can be
  generated using this package.

* Familias (1.0)
  Maintainer: Petter Mostad
  Author(s): Petter Mostad mos...@chalmers.se
  License: GPL-2
  http://crantastic.org/packages/Familias

  This package represents a bare-bones implementation of an interface to
  the core Familias functions (www.familias.name), which are
  programmed in C++.  The package itself functions as a kind of
  database, where information about persons, pedigrees, allele systems
  and observations for persons are entered stepwise. In the end,
  probability calculations are made.

* JPSurv (1.0.1)
  Maintainer: Yongwu Shao
  Author(s): Yongwu Shao yws...@gmail.com,
  License: GPL (= 2)
  http://crantastic.org/packages/JPSurv

  Functions, methods, and datasets for cancer survival analysis,
  including the proportional hazard relative survival model, the join
  point relative survival model.

* kappaSize (1.0)
  Maintainer: Michael A Rotondi
  Author(s): Michael A Rotondi mroto...@yorku.ca
  License: GPL (= 2)
  http://crantastic.org/packages/kappaSize

  This package contains basic tools for the purpose of sample size
  estimation in studies of interobserver/interrater agreement
  (reliability).  This package contains sample size estimation
  functions for both the power-based and confidence interval-based
  methods, with binary or multinomial outcomes and two through six
  raters.

* koRpus (0.04-27)
  Maintainer: m.eik michalke
  Author(s): m.eik michalke meik.micha...@hhu.de, with contributions from Earl
 Brown eabr...@csumb.edu, Alberto Mirisola, and Laura
 Hauser
  License: GPL (= 3)
  http://crantastic.org/packages/koRpus

  A set of tools to analyze texts. Includes, amongst others, functions
  for automatic language detection, hyphenation, several indices of
  lexical diversity (e.g., type token ratio, HD-D/vocd-D, MTLD) and
  readability (e.g., Flesch, SMOG, LIX, Dale-Chall). Basic import
  functions for language corpora are also provided, to enable
  frequency analyses (supports Celex and Leipzig Corpora Collection
  file formats).  #' Note: For full functionality a local installation
  of TreeTagger is recommended.  Be encouraged to send feedback to the
  author(s)!

* networkDynamic (0.2-2)
  Maintainer: Ayn Leslie-Cook
  Author(s): Ayn Leslie-Cook, Zack Almquist, Pavel N. Krivitsky, Skye
 Bender-deMoll, David R. Hunter, Martina Morris, Carter T.
 Butts
  License: GPL-3
  http://crantastic.org/packages/networkDynamic

  Simple interface routines to facilitate the handling of network
  objects with complex intertemporal data.

* qLearn (1.0)
  Maintainer: Bibhas Chakraborty
  Author(s): Jingyi Xin, Bibhas Chakraborty, and Eric B. Laber
  License: GPL-2
  http://crantastic.org/packages/qLearn

  Functions to implement Q-learning for estimating optimal dynamic
  treatment regimes from two stage sequentially randomized trials, and
  to perform inference via m-out-of-n bootstrap for parameters
  indexing the optimal regime.

* Rdistance (1.0)
  Maintainer: Trent McDonald
  Author(s): Trent McDonald
  License: GNU General Public License
  http://crantastic.org/packages/Rdistance

  Analysis of line transect surveys.  Estimates distance-based
  sightability functions and abundances.

* relSim (0.1-33)
  Maintainer: James M. Curran
  Author(s): James M. Curran
  License: GPL (= 2)
  http://crantastic.org/packages/relSim

  A set of tools to explore the behaviour statistics used for forensic
  DNA interpretation when close relatives are involved

* RForcecom (0.1)
  Maintainer: Takekatsu Hiramura
  Author(s): Takekatsu Hiramura
  License: BSD
  http://crantastic.org/packages/RForcecom

  RForcecom provides the connection to Force.com (Salesforce.com) from
  R.

* SAScii (0.1)
  Maintainer: Anthony Joseph Damico
  Author(s): Anthony Joseph Damico
  License: GPL (= 2)
  http://crantastic.org/packages/SAScii

  Using any importation code designed for SAS users to read ASCII files
  into sas7bdat files, the SAScii package parses through the INPUT
  block of a (.sas) syntax file to design the parameters needed for a
  read.fwf function call.  This allows the user to specify the
  location of the ASCII (often a .dat) file and the location 

Re: [R] Which non-parametric regression would allow fitting this type of data? (example given).

2012-03-11 Thread Emmanuel Levy
Hello Bert,

Thanks so much for these suggestions. They led me to the package
LPCM, which I found worked best with minimum tuning.

lpc1 = lpc(cbind(X,Y), scaled=TRUE, h=c(0.05,0.05))
plot(lpc1)

... et voila!

All the best,

Emmanuel



On 11 March 2012 00:37, Bert Gunter gunter.ber...@gene.com wrote:
 Thanks for the example.

 Have you tried fitting a principal curve via either the princurve or
 pcurve packages?  I think this might work for what you want, but no
 guarantees.

 Note that loess, splines, etc. are all fitting y|x, that is, a
 nonparametric regression of y on x. That is not what you say you want,
 so these approaches are unlikely to work.


 -- Bert

 On Sat, Mar 10, 2012 at 6:20 PM, Emmanuel Levy emmanuel.l...@gmail.com 
 wrote:
 Hi,

 I'm wondering which function would allow fitting this type of data:

tmp=rnorm(2000)
X.1 = 5+tmp
Y.1 = 5+ (5*tmp+rnorm(2000))
tmp=rnorm(100)
X.2 = 9+tmp
Y.2 = 40+ (1.5*tmp+rnorm(100))
X.3 = 7+ 0.5*runif(500)
Y.3 = 15+20*runif(500)
X = c(X.1,X.2,X.3)
Y = c(Y.1,Y.2,Y.3)
   plot(X,Y)

 The problem with loess is that distances for the goodness of fit are
 calculated on the Y-axis. However, distances would need to be
 calculated on the normals of the fitted curve. Is there a function
 that provide this option?

 A simple trick in that case consists in swapping X and Y, but I'm
 wondering if there is a more general solution?

 Thanks for your input,

 Emmanuel

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



 --

 Bert Gunter
 Genentech Nonclinical Biostatistics

 Internal Contact Info:
 Phone: 467-7374
 Website:
 http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How do I do a pretty scatter plot using ggplot2?

2012-03-11 Thread Michael
Could you please show me an example for my two cases?

Thanks a lot!

On Sun, Mar 11, 2012 at 3:55 AM, Jim Lemon j...@bitwrit.com.au wrote:

  On 03/10/2012 11:37 AM, Michael wrote:

 Hi all,

 I am trying hard to do the following and have already spent a few hours in
 vain:

 I wanted to do the scatter plot.

 But given the high dispersion on those dots, I would like to bin the
 x-axis
 and then for each bin of the x-axis, plot the quantiles of the y-values of
 the data points in each bin:

 1. Uniform bin size on the x-axis;
 2. Equal number of observations in each bin;

 How to do that in R? I guess for the sake of prettyness, I'd better do it
 in ggplot2?

 Hi Michael,
 While it is not in ggplot2, a variation on the count.overplot function
 might do what you want. This function displays counts of closely spaced
 points rather than the points, but it applies the same area of aggregation
 across the whole plot. Getting the equal x bins is easy, and I assume that
 you mean equal observations within each bin, not across all bins. If you
 are stuck, I can probably hack up something from count.overplot.

 Jim



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extracting data from unstructured (text?) file

2012-03-11 Thread frauke
Wow Jim, this is much more than I expected. Thank you!!

It took me a while to figure out what exactly you are doing in that code.
But I think I understand and it definitely runs. May I ask you two follow up
questions?

First, some of my files have data from two or more cities in them. So I have
trouble that it picks the right city. What makes it difficult is that not in
all files will a city be called the same. Sometimes it might be van Buren,
other times Arkansas River at van Buren. Sometimes the target city is the
first in the file, other times further down. Here is an example: 
http://r.789695.n4.nabble.com/file/n4465068/sample3.txt sample3.txt .
Additionally, some files miss the city that I am looking for. 

Second, I would like extract some more data from the files, printed in bold
below.  I thought of storing this data in an extra line appended to the main
table or so.  I do manage to extract one at a time, but of course it takes
ages to run the process over and over again to get all the data. 

:ARKANSAS RIVER AT VAN BUREN
:FLOOD STAGE * 22.0  *
:
:LATEST STAGE*19.25* FT AT *400 AM* CST ON *010100*
.ER VBUA40101 C DC21010823/DH12/HGIFF/DIH6
:QPF FORECAST6AM   NOON6PM   MDNT
.E1 :0101:  /  19.3/  19.4/  19.4
.E2 :0102:   /  19.4/  19.4/  19.4/  19.4
.E3 :0103:   /  19.4/  19.4/  19.4/  19.4
.E4 :0104:   /  19.4/  19.4/  19.4/  19.4
.E5 :0105:   /  19.4/  19.4/  19.4/  19.4
.E6 :0106:   /  19.4
.ER VBUA40101 C DC21010823/DH12/PPQFZ/DIH6/  0.00/0.00/0.00/0.00  
.ER VBUA40101 C DC21010823/DH12/QTIFF/DIH6
:QPF FORECAST6AM   NOON6PM   MDNT
.E1 :0101:  /  0.98/  2.78/  8.66
.E2 :0102:   /  9.88/  8.70/  7.36/  7.48
.E3 :0103:   /  8.25/  8.42/  8.53/  9.02

Please Jim, only answer these questions if you have time. I certainly
appreciate any help very much. 

Thank you, Frauke


--
View this message in context: 
http://r.789695.n4.nabble.com/extracting-data-from-unstructured-text-file-tp4464423p4465068.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] specify GARCH model, using garchFit()

2012-03-11 Thread Ashley Bonner
Hello,

I’ve fitted a Garch(2,1) model with function 'garchFit()' from the package
'fGarch':

 m1 - garchFit(formula = ~garch(2,1),data = X,trace = F)

* See 'summary(m1)' OUTPUT BELOW *

PROBLEM: My alpha1 term is not significant and I would like to make a NEW
model, say m2, that does not contain alpha1, but I am not sure how to
specify this with the garchFit() arguments. I assume it must be done by
changing the formula argument (replacing ~garch(2,1) with something), but
am unsure; not an expert in this statistical field. Has anyone worked with
these and know the fix?

Thanks,

Ash


### OUTPUT:

 summary(m1)

Title:

 GARCH Modelling

Call:

 garchFit(formula = ~garch(2, 1), data =X, trace = F)

Meanand Variance Equation:

 data ~ garch(2, 1)

environment: 0x03c0c84c

 [data =ex3.5$sp5]

ConditionalDistribution:

 norm



Coefficient(s):

  mu omegaalpha1alpha2 beta1

0.630047  0.716062  0.048446 0.096263  0.838793



Std.Errors:

 based on Hessian



ErrorAnalysis:

   Estimate  Std. Error  t value Pr(|t|)

mu   0.63005 0.140724.477 7.56e-06 ***

omega0.71606 0.262642.726   0.0064 **

alpha1  0.048450.03096   1.565   0.1176

alpha2  0.096260.04354   2.211   0.0271 *

beta10.83879 0.02477   33.858  2e-16 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] to Michael ... Re: How do I do a pretty scatter plot using ggplot2?

2012-03-11 Thread Michael
Hi Michael,

I am trying the solution you've suggested below:

DAT - data.frame(x = runif(1000, 0, 20), y = rnorm(1000))
DAT$xbin - with(DAT, cut(x, seq(0, 20, 2)))

p - ggplot(DAT, aes(x = x, y = y)) + geom_point(alpha = 0.2) +
stat_quantile(aes(colour = ..quantile..), quantiles = seq(0.05, 0.95,
by=0.05)) + facet_wrap(~ xbin, scales = free)
print(p)
---

But my big problem is: I don't know how to modify the code above to do it
for equal # of points in each bin along the x-axis?

i.e. the 2nd case in the original problem:

2. Equal number of observations in each bin;

?

Thanks a lot!

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] to Michael ... Re: How do I do a pretty scatter plot using ggplot2?

2012-03-11 Thread Michael
And also, no matter how I changed the quantiles = seq(0.05, 0.95,
by=0.05)) line,

the number of lines in each bin and the number of legends on the right side
of the each plot are different...

What's the catch? Am I missing something here?

I thought the number of quantile lines and the number of legends should be
exactly the same, no?

On Sun, Mar 11, 2012 at 8:54 PM, Michael comtech@gmail.com wrote:

 Hi Michael,

 I am trying the solution you've suggested below:

 DAT - data.frame(x = runif(1000, 0, 20), y = rnorm(1000))
 DAT$xbin - with(DAT, cut(x, seq(0, 20, 2)))

 p - ggplot(DAT, aes(x = x, y = y)) + geom_point(alpha = 0.2) +
 stat_quantile(aes(colour = ..quantile..), quantiles = seq(0.05, 0.95,
 by=0.05)) + facet_wrap(~ xbin, scales = free)
 print(p)
 ---

 But my big problem is: I don't know how to modify the code above to do it
 for equal # of points in each bin along the x-axis?

 i.e. the 2nd case in the original problem:

 2. Equal number of observations in each bin;

 ?

 Thanks a lot!

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://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
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] Idea/package to linearize a curve along the diagonal?

2012-03-11 Thread Emmanuel Levy
Hi,

I am trying to normalize some data. First I fitted a principal curve
(using the LCPM package), but now I would like to apply a
transformation so that the curve becomes a straight diagonal line on
the plot.  The data used to fit the curve would then be normalized by
applying the same transformation to it.

A simple solution could be to apply translations only (e.g., as done
after a fit using loess), but here rotations would have to be applied
as well. One could visualize this as the stretching of a curve,
i.e., during such an unfolding process, both translations and
rotations would need to be applied.

Before I embark on this (which would require me remembering long
forgotten geometry principles) I was wondering if you can think of
packages or tricks that could make my life simpler?

Thanks for any input,

Emmanuel


Below I provide an example - the black curve is to be brought along
the diagonal, and all data points normal to a small segment (of the
black curve) would undergo the same transformation as it - what
small is remains to be defined though.

tmp=rnorm(2000)
X.1 = 5+tmp
Y.1 = 5+ (5*tmp+rnorm(2000))
tmp=rnorm(1000)
X.2 = 9+tmp
Y.2 = 40+ (1.5*tmp+rnorm(1000))
X.3 = 7+ 0.5*runif(500)
Y.3 = 15+20*runif(500)
X = c(X.1,X.2,X.3)
Y = c(Y.1,Y.2,Y.3)

lpc1 = lpc(cbind(X,Y), scaled=FALSE, h=c(1,1) )
plot(lpc1)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] SEM eigen value error 0 X 0 matrix

2012-03-11 Thread jahughes81
Using R-studio, I am trying to run a structural equation model and I am
running into problems with testing my primary model. Once I specify
everything and try to run it I get this error:

Error in eigen(S, symmetric = TRUE, only.values = TRUE) : 0 x 0 matrix

And when I look at the object for my primary model in my workspace, which is
created after I specify it, it lists all my model components, but has a
whole bunch of 'NA' values listed after my components. I have no idea why
they are listed there because I omitted all of the 'NA' values from my data
and can verify this by a visual inspection.

Here is my specified model:

# Primary model

wellbeing.model - specifyModel()
belonging - optimism, path1
autonomy - optimism, path2
optimism - wellbeing, path3
belonging - belonging_hapmar, patha
belonging - belonging_attend, pathb
belonging - belonging_cowrkint, pathc
autonomy - autonomy_overwork, pathd
autonomy - autonomy_famwkoff, pathe
autonomy - autonomy_hrsrelax, pathf
optimism - optimism_confinan, pathg
optimism - optimism_goodlife, pathh
optimism - optimis_conlegis, pathi
wellbeing - wellbeing_happy, pathj
wellbeing - wellbeing_health, pathk
wellbeing - wellbeing_life, pathl
belonging - autonomy, covariance1
autonomy_overwork - autonomy_famwkoff, covariance2
autonomy_overwork - autonomy_hrsrelax, covariance3
autonomy_hrsrelax - autonomy_famwkoff, covariance4
belonging - belonging, variance1
autonomy - autonomy, variance2
optimism - optimism, disturbance1
optimism_confinan - optimism_goodlife, disturbance2
optimism_goodlife - optimism_conlegis, disturbance3
optimism_confinan - optimism_conlegis, disturbance4
wellbeing - wellbeing, disturbance5
wellbeing_happy - wellbeing_health, disturbance6
wellbeing_happy - wellbeing_life, disturbance7
wellbeing_health - wellbeing_life, disturbance8
wellbeing.analysis - sem( wellbeing.model, gss.data.cov, nrow(gss.data_C) )
summary( wellbeing.analysis )
stdCoef( wellbeing.analysis )
effects( wellbeing.analysis )
pathDiagram( wellbeing.analysis, WellbeingPathModel, standardize=TRUE,
edge.labels=values )

And here are my model components once specified:

structure(c(belonging - optimism, autonomy - optimism, 
optimism - wellbeing, belonging - belonging_hapmar, belonging -
belonging_attend, 
belonging - belonging_cowrkint, autonomy - autonomy_overwork, 
autonomy - autonomy_famwkoff, autonomy - autonomy_hrsrelax, 
optimism - optimism_confinan, optimism - optimism_goodlife, 
optimism - optimis_conlegis, wellbeing - wellbeing_happy, 
wellbeing - wellbeing_health, wellbeing - wellbeing_life, 
belonging - autonomy, autonomy_overwork - autonomy_famwkoff, 
autonomy_overwork - autonomy_hrsrelax, autonomy_hrsrelax -
autonomy_famwkoff, 
belonging - belonging, autonomy - autonomy, optimism - optimism, 
optimism_confinan - optimism_goodlife, optimism_goodlife -
optimism_conlegis, 
optimism_confinan - optimism_conlegis, wellbeing - wellbeing, 
wellbeing_happy - wellbeing_health, wellbeing_happy -
wellbeing_life, 
wellbeing_health - wellbeing_life, belonging_hapmar -
belonging_hapmar, 
belonging_attend - belonging_attend, belonging_cowrkint -
belonging_cowrkint, 
autonomy_overwork - autonomy_overwork, autonomy_famwkoff -
autonomy_famwkoff, 
autonomy_hrsrelax - autonomy_hrsrelax, optimism_confinan -
optimism_confinan, 
optimism_goodlife - optimism_goodlife, optimis_conlegis -
optimis_conlegis, 
wellbeing_happy - wellbeing_happy, wellbeing_health -
wellbeing_health, 
wellbeing_life - wellbeing_life, path1, path2, path3, 
patha, pathb, pathc, pathd, pathe, pathf, pathg, 
pathh, pathi, pathj, pathk, pathl, covariance1, covariance2, 
covariance3, covariance4, variance1, variance2, disturbance1, 
disturbance2, disturbance3, disturbance4, disturbance5, 
disturbance6, disturbance7, disturbance8, V[belonging_hapmar], 
V[belonging_attend], V[belonging_cowrkint], V[autonomy_overwork], 
V[autonomy_famwkoff], V[autonomy_hrsrelax], V[optimism_confinan], 
V[optimism_goodlife], V[optimis_conlegis], V[wellbeing_happy], 
V[wellbeing_health], V[wellbeing_life], NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA), .Dim = c(41L, 3L), class = semmod)

I have no idea where the 'NA' values are coming from.

Any help would be most appreciated!

-
Jessica

--
View this message in context: 
http://r.789695.n4.nabble.com/SEM-eigen-value-error-0-X-0-matrix-tp4465139p4465139.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Idea/package to linearize a curve along the diagonal?

2012-03-11 Thread Jeff Newmiller
Aren't you just reinventing the inverse of a function?
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Emmanuel Levy emmanuel.l...@gmail.com wrote:

Hi,

I am trying to normalize some data. First I fitted a principal curve
(using the LCPM package), but now I would like to apply a
transformation so that the curve becomes a straight diagonal line on
the plot.  The data used to fit the curve would then be normalized by
applying the same transformation to it.

A simple solution could be to apply translations only (e.g., as done
after a fit using loess), but here rotations would have to be applied
as well. One could visualize this as the stretching of a curve,
i.e., during such an unfolding process, both translations and
rotations would need to be applied.

Before I embark on this (which would require me remembering long
forgotten geometry principles) I was wondering if you can think of
packages or tricks that could make my life simpler?

Thanks for any input,

Emmanuel


Below I provide an example - the black curve is to be brought along
the diagonal, and all data points normal to a small segment (of the
black curve) would undergo the same transformation as it - what
small is remains to be defined though.

tmp=rnorm(2000)
X.1 = 5+tmp
Y.1 = 5+ (5*tmp+rnorm(2000))
tmp=rnorm(1000)
X.2 = 9+tmp
Y.2 = 40+ (1.5*tmp+rnorm(1000))
X.3 = 7+ 0.5*runif(500)
Y.3 = 15+20*runif(500)
X = c(X.1,X.2,X.3)
Y = c(Y.1,Y.2,Y.3)

lpc1 = lpc(cbind(X,Y), scaled=FALSE, h=c(1,1) )
plot(lpc1)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] ggplot2: coord_polar

2012-03-11 Thread Athula Herath
Hello HelpeRs,

The last print statement in the code segment below results in :

Error in data$x[data$x == -Inf] - range$x.range[1] :
  replacement has length zero


R version 2.14.1 Patched (2011-12-23 r57982)

ggplot2: version 0.90

OS : Linux (64bit)


Any thoughts?


Many Thanks,


A.


## code segment starts here


df - data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  se = c(0.1, 0.3, 0.3, 0.2)
  )
df2 - df[c(1,3),]

limits - aes(ymax = resp + se, ymin=resp - se)
dodge - position_dodge(width=0.9)

p - ggplot(df2, aes(fill=group, y=resp, x=trt))
p - p + geom_bar(position=dodge)


# This is OK
print(p)

# This is OK
print(p + coord_polar())
p - p + geom_errorbar(limits, position=dodge, width=0.25)

# This is OK
print(p)

# Error at the next statement
print(p +  coord_polar())

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to plot diagonal line at any coordinate range in R

2012-03-11 Thread Gundala Viswanath
Dear expert

How can we plot diagonal across (from bottom-left-hand corner to top
right-hand corner),
at any given coordinate range

For example

 plot(c(-2,3), c(-1,5), type = n, xlab=x, ylab=y, asp = 1)
or
 plot(c(0,1000), c(0,334), type = n, xlab=x, ylab=y, asp = 1)

I tried abline with the following but failed:

 abline(0,1,col=red)

- G.V.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to plot diagonal line at any coordinate range in R

2012-03-11 Thread Jeff Newmiller
Your requirement that the line go from bottom-left to top-right regardless of 
the coordinates is inconsistent with a slope of 1. Are you sure that is your 
requirement?
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Gundala Viswanath gunda...@gmail.com wrote:

Dear expert

How can we plot diagonal across (from bottom-left-hand corner to top
right-hand corner),
at any given coordinate range

For example

 plot(c(-2,3), c(-1,5), type = n, xlab=x, ylab=y, asp = 1)
or
 plot(c(0,1000), c(0,334), type = n, xlab=x, ylab=y, asp = 1)

I tried abline with the following but failed:

 abline(0,1,col=red)

- G.V.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Re : How to plot diagonal line at any coordinate range in R

2012-03-11 Thread Pascal Oettli
Hi  G.V.

Does it fit to your request?


plot(c(-2,3), c(-1,5), type = n, xlab=x, ylab=y, asp = 1)
dg - par(usr)
segments(dg[1],dg[3],dg[2],dg[4], col='red')

Regards,
Pascal

- Mail original -
De : Gundala Viswanath gunda...@gmail.com
À : r-h...@stat.math.ethz.ch
Cc : 
Envoyé le : Lundi 12 mars 2012 14h15
Objet : [R] How to plot diagonal line at any coordinate range in R

Dear expert

How can we plot diagonal across (from bottom-left-hand corner to top
right-hand corner),
at any given coordinate range

For example

 plot(c(-2,3), c(-1,5), type = n, xlab=x, ylab=y, asp = 1)
or
 plot(c(0,1000), c(0,334), type = n, xlab=x, ylab=y, asp = 1)

I tried abline with the following but failed:

 abline(0,1,col=red)

- G.V.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.