Re: [R] max length of a factor variable

2010-09-28 Thread Richard Mott

Thanks

I eventually tracked down the problem to something unrelated to this 
question (one out of the millions of character strings happened to be 
NA by chance, which of course was parsed as a missing value, breaking 
the code a long way downstream.)


Richard

On 28/09/2010 04:01, Michael Bedward wrote:

Hello Richard,

Since no one else has answered yet I'll venture a guess.

The following works on my little macbook...

x- as.factor(sapply(letters[1:26], function(x) paste(rep(x, 10),
collapse=)))

So each of the 26 factor levels in x has a string representation of
100,000 chars.  So I'm *guessing* the limit is only that imposed by
system memory.

Hopefully if that's wrong it will provoke someone to correct me :)

Michael

On 27 September 2010 19:15, Richard Mottrm...@well.ox.ac.uk  wrote:

Hi

Is there a maximum length for the character string representing a level of a
factor?  I have a set of several million variables, each a factor of length
19. Each factor level is a character string which in some cases can be many
thousands of characters long.  I am trying to find out why my analysis fails
- I just wanted to rule out the possibility that the internal factor
conversion has a problem parsing long strings.

Thanks

Richard
--

Richard Mott   | Wellcome Trust Centre
tel 01865 287588   | for Human Genetics
fax 01865 287697   | Roosevelt Drive, Oxford OX3 7BN

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



--

Richard Mott   | Wellcome Trust Centre
tel 01865 287588   | for Human Genetics
fax 01865 287697   | Roosevelt Drive, Oxford OX3 7BN

__
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 convert SEXP to double

2010-09-28 Thread Dmitrij Kudriavcev
Hello All,

A simple question.

I get some return from the R in my C++ program (via Rcpp package). The
result come, as SEXP and it should be a simple numeric variable.

How to convert it to double?

The code, what i use:

stringstream ss;
ss  p - predict(fit_ar11, n.ahead = 2, doplot=FALSE);
  p$pred[1];

SEXP ans;
int iRet = R.parseEval(ss.str().c_str());
if (iRet == 0  ans != NULL)
{

// ???
}

Cheers,
Dima

[[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] hcluster with linkage median

2010-09-28 Thread Kennedy

Thank you Peter for your help.

I had tried hclust before but I made the mistake of using the D matrix above
instead of a dist object. Hence

  library(flashClust)

  d - as.dist(D)
  # Clustering using hclust
  hc - hclust(d, method = median,members=NULL)
  # Clustering using flashClust 
  fc - flashClust(d,method=median,members=NULL)

solves the problem I posted. But another question arises. How is the median
linkage calculated? I want it to be like this:

Given clusters C1=(1,2,3) and C2=(4), the distance between C1 and C2 is: 
  d(C1,C2) = median(d(1,4),d(2,4),d(3,4)) = median(0.2, 1.0, 0.8) = 0.8,
where the values d(1,4), d(2,4) and d(3,4) are taken from the D matrix
above.

If this is not the case, is there any function that uses this linkage
metric?


Thanks

Henrik

-- 
View this message in context: 
http://r.789695.n4.nabble.com/hcluster-with-linkage-median-tp2715585p2716728.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] calculating mean and s.d. from a two-column table

2010-09-28 Thread Jim Lemon

On 09/28/2010 02:34 AM, Jonas Josefsson wrote:

I have a two-column table as follows where age is in the 1st column and
the number of individuals is in the 2nd.

age;no
1;21
2;31
3;9
4;12
5;6


Can I use mean() and sd() to calculate the mean and standard deviation
from this or do I have to manually multiplicate 21*1+31*2 etc. / N?


Hi Jonas,
You can also use weighted.mean:

weighted.mean(age,no)

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.


Re: [R] Regular expressions: offsets of groups

2010-09-28 Thread Michael Bedward
What Titus wants to do is akin to retrieving capturing groups from a
Matcher object in Java. I also thought there must be an existing,
elegant solution to this some time ago and searched for it, including
looking at the sources (albeit with not much expertise) but came up
blank.

I also looked at the stringr package (which is nice) but it doesn't
quite do it either.

Michael

On 28 September 2010 01:48, Titus von der Malsburg malsb...@gmail.com wrote:
 Dear list!

 gregexpr(a+(b+), abcdaabbc)
 [[1]]
 [1] 1 5
 attr(,match.length)
 [1] 2 4

 What I want is the offsets of the matches for the group (b+), i.e. 2
 and 7, not the offsets of the complete matches.  Is there a way in R
 to get that?

 I know about gsubgn and strapply, but they only give me the strings
 matched by groups not their offsets.

 I could write something myself that first takes the above matches
 (ab and aabb) and then searches again using only the group (b+).
 For this to work, I'd have to parse the regular expression and search
 several times ( 2, for nested groups) instead of just once.  But I'm
 sure there is a better way to do this.

 Thanks for any suggestion!

   Titus

 __
 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 to convert SEXP to double

2010-09-28 Thread Romain Francois

Le 28/09/10 08:43, Dmitrij Kudriavcev a écrit :


Hello All,

A simple question.

I get some return from the R in my C++ program (via Rcpp package). The
result come, as SEXP and it should be a simple numeric variable.

How to convert it to double?

The code, what i use:

stringstream ss;
ss  p- predict(fit_ar11, n.ahead = 2, doplot=FALSE);
p$pred[1];

SEXP ans;
int iRet = R.parseEval(ss.str().c_str());
if (iRet == 0  ans != NULL)
{

 // ???
}

Cheers,
Dima


Hello,

Questions about Rcpp should go to the Rcpp-devel mailing list (cc'ed).

You probably meant to use thsi version of parseEval:

int  parseEval(const std::string  line, SEXP ans); // parse line, 
return in ans; error code rc


In your example ans is never used or initialized, so you have less 
than zero chances of it to work.



With recent versions of RInside, you may just do :

double res = R.parseEval( ss.str().c_str() ) ;

conversion will work itself out.


why:

parseEval implements the proxy pattern:

RInside::Proxy RInside::parseEval(const std::string  line) {
SEXP ans;
int rc = parseEval(line, ans);
if (rc != 0) {
throw std::runtime_error(std::string(Error evaluating: ) + line);
}
return Proxy( ans );
}

and Proxy has a templated implicit conversion operator:

class Proxy {
public:
Proxy(SEXP xx): x(xx) { };

template typename T
operator T() {
return ::Rcpp::asT(x);
}
private:
Rcpp::RObject x;
};

Please register to the Rcpp-devel mailing list of you have follow up 
questions.


Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/cCmbgg : Rcpp 0.8.6
|- http://bit.ly/bzoWrs : Rcpp svn revision 2000
`- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th

__
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] One-sided CUSUM / MOSUM Tests?

2010-09-28 Thread Achim Zeileis

On Mon, 27 Sep 2010, bo...@hsu-hh.de wrote:


Dear R-help list members,

I have the following question concerning the strucchange()-package: is it 
possible to get the boundaries for one-sided (upper / lower) CUSUM and MOSUM 
tests?


Not out of the box, at least not exactly. You can do this:

library(strucchange)
ocus - efp(Nile ~ 1, type = OLS-CUSUM)
plot(ocus, boundary = FALSE)
lines(boundary(ocus, 0.1), col = 2)

i.e., approximate the one-sided 5% boundary by the 10% two-sided boundary. 
But, of course, this ignores the probability of multiple crossings (which 
is low at conventional levels).


Using the function efpFunctional() you can also simulate the distribution 
of arbitrary test statistics, including those corresponding to one-sided 
boundaries. The result is intended for use with the function gefp().


Finally, for some of the boundaries, closed-form solutions are available 
in strucchange, e.g., for the boundary used above. To compute this a 
series expansion is employed, only the first term of which is required for 
the one-sided boundary. So if you take the necessary pieces from the 
underlying code, you can also compute one-sided boundaries.


hth,
Z


Thank you in advance.

Julia

__
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] A problem with plotting a long expression in ylab ?

2010-09-28 Thread Tal Galili
Hello,

It seems that there is a problem when plotting an expression in the ylab of
a plot in case it is too long.

Example:

plot(1)
title(ylab = test
looong
) # work
plot(1)
title(ylab = expression(paste(test (% of 360 *degree,  # works
plot(1)
title(ylab = expression(paste(test looong (% of
360 *degree,  # doesn't work


(R version R 2.11.1, on win 7 )


Is it supposed to be this way?  (shouldn't there be at least a warning ?)

Best,
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)
--

[[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] A problem with plotting a long expression in ylab ?

2010-09-28 Thread Barry Rowlingson
On Tue, Sep 28, 2010 at 10:03 AM, Tal Galili tal.gal...@gmail.com wrote:
 Hello,

 It seems that there is a problem when plotting an expression in the ylab of
 a plot in case it is too long.

 Example:

 plot(1)
 title(ylab = test
 looong
 ) # work
 plot(1)
 title(ylab = expression(paste(test (% of 360 *degree,  # works
 plot(1)
 title(ylab = expression(paste(test looong (% of
 360 *degree,  # doesn't work

 what does 'work/doesn't work' mean?

 I see some problems with the appearance of the label, and they seem
related to the line breaks in the label. A single line label:

  plot(1)
  title(ylab=looong
cat is long)

 (where any line breaks you see are due to mail clients linebreaking)
works fine (except of course the label is truncated at the start and
end).

However if I do:

  plot(1)
  title(ylab=looong
cat is\n long)

 (with a newline char \n in there)

 I only see the last looo*oong because the first line is out of my
margin area. I can actually see the descender of the 'g', so I know
it's there.

 I think the 'doesn't work' you are having is because there's a
newline on the end of your continuation string:

  plot(1)
  title(ylab=foo
+ )  # has a newline at end
  title(ylab=foo)# doesn't

You can give more label space by using par(mar=, for example:

 par(mar=c(5,8,4,2))
 plot(1)
 title(ylab=long\ncat\nis\nlong)

 But of course you need to know how many lines your ylab will be
before you make the plot...

Barry

__
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] A problem with plotting a long expression in ylab ?

2010-09-28 Thread Tal Galili
Hi Barry,

Sorry for not being clear.

Not work == Doesn't add the text to the ylab

My initial example was intended with no line breaks.

Here it is again with variations:
plot(1)
title(ylab = expression(paste(test
lng
(% of 360 *degree,  # won't work
plot(1)
title(ylab = expression(paste(test looong (% of
360 *degree, ))), cex.lab = 1) # works
plot(1)
title(ylab = expression(paste(test looong (% of
360 *degree, ))), cex.lab = 3) # doesn't work


My point is that in regular text, ylab plots it where it then goes outside
the borders.
With the use of expressions - the text just doesn't show up.

Originally I thought it was because of my miss-use of expressions, until I
figured it was the level of cex.lab I was using.
The problem is that when you can't see the text, you don't have a sense of
how much to decrease the cex.lab so the text will fit.

I hope I was now clearer.

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 Tue, Sep 28, 2010 at 11:29 AM, Barry Rowlingson 
b.rowling...@lancaster.ac.uk wrote:

 On Tue, Sep 28, 2010 at 10:03 AM, Tal Galili tal.gal...@gmail.com wrote:
  Hello,
 
  It seems that there is a problem when plotting an expression in the ylab
 of
  a plot in case it is too long.
 
  Example:
 
  plot(1)
  title(ylab = test
 
 looong
  ) # work
  plot(1)
  title(ylab = expression(paste(test (% of 360 *degree,  # works
  plot(1)
  title(ylab = expression(paste(test looong (% of
  360 *degree,  # doesn't work

  what does 'work/doesn't work' mean?

  I see some problems with the appearance of the label, and they seem
 related to the line breaks in the label. A single line label:

   plot(1)
  
 title(ylab=looong
 cat is long)

  (where any line breaks you see are due to mail clients linebreaking)
 works fine (except of course the label is truncated at the start and
 end).

 However if I do:

   plot(1)
  
 title(ylab=looong
 cat is\n long)

  (with a newline char \n in there)

  I only see the last looo*oong because the first line is out of my
 margin area. I can actually see the descender of the 'g', so I know
 it's there.

  I think the 'doesn't work' you are having is because there's a
 newline on the end of your continuation string:

   plot(1)
   title(ylab=foo
 + )  # has a newline at end
   title(ylab=foo)# doesn't

 You can give more label space by using par(mar=, for example:

  par(mar=c(5,8,4,2))
  plot(1)
  title(ylab=long\ncat\nis\nlong)

  But of course you need to know how many lines your ylab will be
 before you make the plot...

 Barry


[[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] 95% confidence intercal with glm

2010-09-28 Thread zozio32

Hi

I had to use a glm instead of my basic lm on some data due to unconstant
variance.

now, when I plot the model over the data, how can I easily get the 95%
confidence interval that sormally coming from:
  
   yv - predict(modelVar,list(aveLength=xv),int=c)
   matlines(xv,yv,lty=c(1,2,2))

There is no interval argument to pass to the predict function when using a
glm, so I was wondering if I had to use an other function

thanks 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/95-confidence-intercal-with-glm-tp2716906p2716906.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] Combining two variables in text

2010-09-28 Thread trb1

Hi all,

how can I manually create a data.frame or similar object to display in a
textplot, that omits column and row numbers/headings? 

Also, how can I combine several variables in text
i.e. suppose I have 
a - one
b - two
then what expression can I place in 
title(main=...)
in terms of a and b to give an output title of 
one, two 
i.e. a then b separated by a comma.

Thanks 


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Combining-two-variables-in-text-tp2716916p2716916.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] Combining two variables in text

2010-09-28 Thread trb1

In the date.frame/ text plot, would it be possible to change the font size of
one of the lines?
Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Combining-two-variables-in-text-tp2716916p2716931.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] Combining two variables in text

2010-09-28 Thread Dimitris Rizopoulos

try this:

a - one
b - two

paste(a, b, sep = , )


I hope it helps.

Best,
Dimitris


On 9/28/2010 12:12 PM, trb1 wrote:


Hi all,

how can I manually create a data.frame or similar object to display in a
textplot, that omits column and row numbers/headings?

Also, how can I combine several variables in text
i.e. suppose I have
a- one
b- two
then what expression can I place in
title(main=...)
in terms of a and b to give an output title of
one, two
i.e. a then b separated by a comma.

Thanks




--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

__
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] bwplot superpose panel.points from another dataframe

2010-09-28 Thread Christophe Bouffioux
Thanks for your help Peter
but the red marks on boxplot do not correspond to ex2 dataframe
actually, it reproduce on each panel the same marks
that is to say the 3 first lines of ex2
So this is not correct


Christophe

On Mon, Sep 27, 2010 at 6:18 PM, Peter Ehlers ehl...@ucalgary.ca wrote:

 On 2010-09-27 4:54, Christophe Bouffioux wrote:

 bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2),
pch = |,
par.settings = list(
plot.symbol = list(alpha = 1, col = transparent,cex = 1,pch =
 20)),
panel = function(x, y){
 panel.bwplot(x, y)
 X- tapply(ex3$v1b, ex3[,c(1,2)], max)
 Y- seq(length(unique(ex3[,c(1,2)])))
 panel.points(X, Y, pch = 17, col = red)
 })


 Perhaps this is what you're trying to achieve:


  bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2),
   panel = function(x, y){
panel.bwplot(x, y, pch=|)
X - tapply(ex3$v1b, ex3[, 1:2], max)
Y - seq(nrow(unique(ex3[, 1:2])))

panel.points(X, Y, pch = 17, col = red)
})

 (I didn't see any need for your par.settings.)

 I'm not crazy about the way you define X,Y. I think
 I would augment the data frame appropriately instead.

  -Peter Ehlers


[[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] break function execution

2010-09-28 Thread raje...@cse.iitm.ac.in

Hi,

I have an R function that executes for a little over a minute. When the 
function starts running, the R interface freezes and doesnt change until the 
function exits cleanly. Is there someway I can force the function to exit 
without messing up the interface?(An equivalent of Ctrl-C)

Additionally, can I run the function in background and get a notification when 
it completes?
[[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] subtraction based on two groups in a dataframe

2010-09-28 Thread Dennis Murphy
Hi:

Perhaps this might be useful:

tst - read.table(textConnection(
+plate.id well.id  Group  HYB  rlt1
+ 1 P1  A1 Control SKOV3hyb 0.190
+ 2 P1  A2 Control SKOV3hyb 0.210
+ 3 P1  A3 Control SKOV3hyb 0.205
+ 4 P1  A4 Control SKOV3hyb 0.206
+ 5 P1  A5 Control SKOV3hyb 0.184
+ 385   P1  A1ovca SKOV3hyb 0.184
+ 386   P1  A2ovca SKOV3hyb 0.229
+ 387   P1  A3ovca SKOV3hyb 0.214
+ 388   P1  A4ovca SKOV3hyb 0.226
+ 389   P1  A5ovca SKOV3hyb 0.217), header = TRUE)

tst2 - reshape(tst, idvar = c('plate.id', 'well.id'), timevar = 'Group',
 direction = 'wide')
tst2
  plate.id well.id HYB.Control rlt1.Control HYB.ovca rlt1.ovca
1   P1  A1SKOV3hyb0.190 SKOV3hyb 0.184
2   P1  A2SKOV3hyb0.210 SKOV3hyb 0.229
3   P1  A3SKOV3hyb0.205 SKOV3hyb 0.214
4   P1  A4SKOV3hyb0.206 SKOV3hyb 0.226
5   P1  A5SKOV3hyb0.184 SKOV3hyb 0.217

tst2$rlt1.diff - rlt1.ovca - rlt1.Control

reshape() is reshaping the data based on plate.id * well.id combinations, so
the observations in Control and ovca should match on those two keys..

HTH,
Dennis


On Mon, Sep 27, 2010 at 12:47 PM, 1Rnwb sbpuro...@gmail.com wrote:


 Hello

 I have a data set like below:
plate.id well.id   Group  HYB  rlt1
 1 P1  A1 Control SKOV3hyb 0.190
 2 P1  A2 Control SKOV3hyb 0.210
 3 P1  A3 Control SKOV3hyb 0.205
 4 P1  A4 Control SKOV3hyb 0.206
 5 P1  A5 Control SKOV3hyb 0.184
 385   P1  A1ovca SKOV3hyb 0.184
 386   P1  A2ovca SKOV3hyb 0.229
 387   P1  A3ovca SKOV3hyb 0.214
 388   P1  A4ovca SKOV3hyb 0.226
 389   P1  A5ovca SKOV3hyb 0.217
 390   P1  A6ovca SKOV3hyb 0.207


 each plate.id contains 384 readings for Group==Control and the same
 plate.id will contain 384 readings for Group=='ovca' to give a total of
 768
 values for P1 and so on for other plate ID's. I have to take the subtract
 the values of rlt1 colum between the two groups based on Plate ID.

 currently I am using
  newdat2$diff-(newdat2[1:5,5]-newdat2[6:10,5])/newdat2[1:5,5]*100
  newdat2
plate.id well.id   Group  HYB  rlt1   diff
 1 P1  A1 Control SKOV3hyb 0.190   3.157895
 2 P1  A2 Control SKOV3hyb 0.210  -9.047619
 3 P1  A3 Control SKOV3hyb 0.205  -4.390244
 4 P1  A4 Control SKOV3hyb 0.206  -9.708738
 5 P1  A5 Control SKOV3hyb 0.184 -17.934783
 385   P1  A1ovca SKOV3hyb 0.184   3.157895
 386   P1  A2ovca SKOV3hyb 0.229  -9.047619
 387   P1  A3ovca SKOV3hyb 0.214  -4.390244
 388   P1  A4ovca SKOV3hyb 0.226  -9.708738
 389   P1  A5ovca SKOV3hyb 0.217 -17.934783

 I have tried
 apply(newdat2, 1, function(x) tapply(x, plate.id,
 newdat2$Control-newdat2$ovca)))

 I am looking for a more simple way to calculate the percent difference
 between the each value (based on well.id) for the two groups for 100's of
 plate.ids.

 I would appreciate help in getting this solved.
 Thanks

 --
 View this message in context:
 http://r.789695.n4.nabble.com/subtraction-based-on-two-groups-in-a-dataframe-tp2716104p2716104.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] A problem with plotting a long expression in ylab ?

2010-09-28 Thread Barry Rowlingson
On Tue, Sep 28, 2010 at 10:35 AM, Tal Galili tal.gal...@gmail.com wrote:

 My point is that in regular text, ylab plots it where it then goes outside
 the borders.
 With the use of expressions - the text just doesn't show up.
 Originally I thought it was because of my miss-use of expressions, until I
 figured it was the level of cex.lab I was using.
 The problem is that when you can't see the text, you don't have a sense of
 how much to decrease the cex.lab so the text will fit.
 I hope I was now clearer.

Gotcha. Seems to only affect ylab though. Do this:

  t =  expression(paste(test
loo(% of 360 *degree,
)))
  plot(1,xlab=t,ylab=t,main=t)

then if I shrink my graphics window I can make the ylab disappear but
not the xlab or title.

 Seems to affect any rotated expressions:

 plot(1)
 text(1,1,t,srt=90)
 text(1,1,t,srt=0)
 text(1,1,t,srt=45)

 Now shrink window and watch the rotated expressions vanish! They
disappear when they start (or finish) out of the entire graphics
device, not the plot region...

 I cant find anything relating to clipping in the help, and I am on
Linux, so see if there's any news about it, try it with R-patched or
R-devel and then report a bug after having read all the other stuff
about R bug reporting!

Barry

__
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] cochran Q test

2010-09-28 Thread Dennis Murphy
Hi:

Try here:

https://stat.ethz.ch/pipermail/r-help/2006-September/113156.html

HTH,
Dennis

On Mon, Sep 27, 2010 at 7:27 PM, Kohleth Chia kohl...@gmail.com wrote:

 Dear all,

 I am trying to look for a built in function that performs the cochran Q
 test.
 that is, cochranq.test(X)
 where X is a contingency table (maybe a matrix or data.frame).
 The output will naturally be the test statisitcs, p-value, etc.

 A quick search on Google gives me the cochran.test in the 'outlier'
 package,
 but I had a look at the description of the test and it doesn't look
 anything
 close to the cochran Q test.

 MY questions is:
 1. Is that cochran.test the cochran Q test I am looking for?
 2. If not, where can I find such function? I DON'T want to write my own
 function.

 Thanks

 --
 KC
 ^_^

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


[[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] Best package for time series analysis with wavelets???

2010-09-28 Thread gaussllego

Hi!!

I'm looking for a package in R for time series analysis using wavelets( I'm
interested on extractingt information from electrocardiograms with the aim
of study the heart rate variability) so i want to know which package is the
best for me. I've thinking about using some of those(you can recommend me
others,xD):

*wavelets: A package of funtions for computing wavelet filters, wavelet
transforms and multiresolution analyses.

*waveslim: Basic wavelet routines for one-, two- and three-dimensional
signal processing.

*wavethresh: Wavelets statistics and transforms.

*mtsa: Insightful Wavelet Methods for Time Series Analysis(Software to book
Wavelet Methods for Time Series Analysis, so i don't know if it's reliable).

What do you think??

thanks for your help!!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Best-package-for-time-series-analysis-with-wavelets-tp2717043p2717043.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] Use R in Visual Basic Environment

2010-09-28 Thread Soumen Pal
I need your kind help regarding the following:

I wish to know is there any way to use R in Visual Basic environment. I want
to develop a VB application where R can be embedded (R will work as a back
end statistical engine). If available, please provide me some source of
study materials/articles available on the internet related to this.

-- 
Thanks  Regards,

Soumen Pal

[[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] Regular expressions: offsets of groups

2010-09-28 Thread Titus von der Malsburg
On Tue, Sep 28, 2010 at 9:46 AM, Michael Bedward
michael.bedw...@gmail.com wrote:
 What Titus wants to do is akin to retrieving capturing groups from a
 Matcher object in Java.

Precisely.  Here's the description:

  
http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Matcher.html#start(int)

Gabor's lookbehind trick solves some special cases but it's not the
kind of general solution I'm looking for.  Let me explain what I'm
trying to achieve here.  I'm working on a package that provides tools
for processing and analyzing eye movements (we're doing reading
research).  In most situations, eye movements consist of fixations
where the eyes are relatively stationary and saccades, quick movements
between fixations.  A common way to represent eye movements is as
strings of symbols, where each symbol corresponds to a fixation on a
particular region.  AABC means two fixations followed by a fixation on
B and then C.  When people analyze eye movements it's often necessary
to find specific events in the eye movement record like: fixations on
the word C preceded by fixations on words D-F and followed by
fixations on words A-C.  This event can be specified using this
regexpr: [D-F]+(C)[A-C]+  The group (in parenthesis) indicates the
substring for which I'd like to know the position in the overall
string.  Another application is the extraction of subsequences from a
sequence of fixations.  Note that in some situations people might have
to use more groups in their regexprs and that groups can be nested.
In this case the user would have to indicate for which group he/she
wants to know the offset.  I'm not an expert for regexpr engines but
I'm pretty sure the necessary information is available in the engine.

Gabor, I see you're the author of gsubfn (fantastic package!).  Do you
see a relatively simple way to expose information about group offsets
and their corresponding match lengths?  I think this could be useful
for other applications as well.  At least it seems Michael could use
it, too.  We can cook up something for ourselves but a general
solution would benefit the larger community.

   Titus

__
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] Combining two variables in text

2010-09-28 Thread Johannes Huesing
trb1 thomasrbol...@yahoo.co.uk [Tue, Sep 28, 2010 at 12:12:01PM CEST]:
[...]
 Also, how can I combine several variables in text
 i.e. suppose I have 
 a - one
 b - two
 then what expression can I place in 
 title(main=...)
 in terms of a and b to give an output title of 
 one, two 
 i.e. a then b separated by a comma.
 

Type ?paste at the prompt.

-- 
Johannes Hüsing   There is something fascinating about science. 
  One gets such wholesale returns of conjecture 
mailto:johan...@huesing.name  from such a trifling investment of fact.  
  
http://derwisch.wikidot.com (Mark Twain, Life on the Mississippi)

__
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] Using mlogit package to generate a binary mixed logit model

2010-09-28 Thread Michael Morton
Hi,

 

I am trying to generate a binary mixed logit model which contains only
individual specific data (no alternative specific data). Each observation is
contained within one line (data shape = wide). For example:

 

Individual ID   Dependent variableIndependent variable 1
..Independent variable x

1 1
0.2  ..4.9

2 0
0.75..4.2

3 0
0.8  ..5.68

4 1
0.1  ..1.57

5 0
0.14..1.8

 

I have had no such luck in generating a model as yet, I am working through
error messages in the modelling command (after generating a formula
(mFormula) and setting the data (mlogit.data)). Is it possible to generate a
binary mixed logit model using the mlogit package, specifically the rpar
command? If so, does anyone have any tips on the best way to write in the
model (both mFormula, mlogit.data and mlogit commands)?

 

Thanks,

 

Michael


[[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] Regular expressions: offsets of groups

2010-09-28 Thread Gabor Grothendieck
On Tue, Sep 28, 2010 at 6:52 AM, Titus von der Malsburg
malsb...@gmail.com wrote:
 On Tue, Sep 28, 2010 at 9:46 AM, Michael Bedward
 michael.bedw...@gmail.com wrote:
 What Titus wants to do is akin to retrieving capturing groups from a
 Matcher object in Java.

 Precisely.  Here's the description:

  http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Matcher.html#start(int)

 Gabor's lookbehind trick solves some special cases but it's not the

The only limitation is that in the regular expressions supported by R
you cannot have repitition in the (=...) portion but none of your
examples -- neither the one you gave nor the one below require that
since if the prior expression ends in X+ you can just use X.Are
you sure it does not cover all your actual situations?

If you truly do have situations where that require repetition a
gregexpr plus gsubfn will do it in one line.   Parenthesize the
portion of the regular expression you want to capture and replace
every character in it with X (or some other character that does not
otherwise occur).  Then find the positions and lengths of strings of
X.

 gregexpr(X+, gsubfn(a(b+), ~ gsub(., X, x), abcdaabbcbbb))
[[1]]
[1] 1 5
attr(,match.length)
[1] 1 2

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] bwplot superpose panel.points from another dataframe

2010-09-28 Thread Dennis Murphy
Hi:

I did this in ggplot2, which seemed easier than the approach you tried in
lattice's bwplot() - as far as I can tell, you want to plot the unique value
of v1b as a red dot in each boxplot. To that end,

ex - data.frame(v1 = log(abs(rt(180, 3)) + 1),
v2 = rep(c(2007, 2006, 2005), 60),
z  = rep(c(a, b, c, d, e, f), e = 30))
# the individual to be marked
ex2 - data.frame(v1b = log(abs(rt(18, 3)) + 1),
v2 = rep(c(2007, 2006, 2005), 6),
z  = rep(c(a, b, c, d, e, f), e = 3))
ex3 - merge(ex, ex2, by=c(v2,z))

library(ggplot2)
h - ggplot(ex3)
h + geom_boxplot(aes(x = v2, y = v1)) +
geom_point(aes(x = v2, y = v1b), shape = 17, colour = 'red', size = 3) +
coord_flip() + facet_wrap( ~ z) +
opts(panel.minor.grid = theme_blank()) + theme_bw()

It has a different look from bwplot(), but it appears to me that the points
are correctly located.

HTH,
Dennis

On Tue, Sep 28, 2010 at 12:29 AM, Christophe Bouffioux 
christophe@gmail.com wrote:

 Thanks for your help Peter
 but the red marks on boxplot do not correspond to ex2 dataframe
 actually, it reproduce on each panel the same marks
 that is to say the 3 first lines of ex2
 So this is not correct


 Christophe

 On Mon, Sep 27, 2010 at 6:18 PM, Peter Ehlers ehl...@ucalgary.ca wrote:

  On 2010-09-27 4:54, Christophe Bouffioux wrote:
 
  bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2),
 pch = |,
 par.settings = list(
 plot.symbol = list(alpha = 1, col = transparent,cex = 1,pch =
  20)),
 panel = function(x, y){
  panel.bwplot(x, y)
  X- tapply(ex3$v1b, ex3[,c(1,2)], max)
  Y- seq(length(unique(ex3[,c(1,2)])))
  panel.points(X, Y, pch = 17, col = red)
  })
 
 
  Perhaps this is what you're trying to achieve:
 
 
   bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2),
panel = function(x, y){
 panel.bwplot(x, y, pch=|)
 X - tapply(ex3$v1b, ex3[, 1:2], max)
 Y - seq(nrow(unique(ex3[, 1:2])))
 
 panel.points(X, Y, pch = 17, col = red)
 })
 
  (I didn't see any need for your par.settings.)
 
  I'm not crazy about the way you define X,Y. I think
  I would augment the data frame appropriately instead.
 
   -Peter Ehlers
 

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


[[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] Odp: Object Browser

2010-09-28 Thread Douglas Bates
On Mon, Sep 27, 2010 at 3:04 AM, Petr PIKAL petr.pi...@precheza.cz wrote:
 Hi
 I noticed that nobody answered your question yet so here is my try.

 If you want to see what objects are in your environment you can use ls()
 but its output is only names of objects. Here is a function I use a long
 time for checking what objects are there, their type, size and possibly
 rows columns. You can modify it to give you some more info but usually it
 is not needed.

 Regards
 Petr

 ls.objects - function (pos = 1, pattern, order.by)
 {
    napply - function(names, fn) sapply(names, function(x) fn(get(x,
        pos = pos)))
    names - ls(pos = pos, pattern = pattern)
    obj.class - napply(names, function(x) as.character(class(x))[1])
    obj.mode - napply(names, mode)
    obj.type - ifelse(is.na(obj.class), obj.mode, obj.class)
    obj.size - napply(names, object.size)
    obj.dim - t(napply(names, function(x) as.numeric(dim(x))[1:2]))
    vec - is.na(obj.dim)[, 1]  (obj.type != function)
    obj.dim[vec, 1] - napply(names, length)[vec]
    out - data.frame(obj.type, obj.size, obj.dim)
    names(out) - c(Type, Size, Rows, Columns)
    if (!missing(order.by))
        out - out[order(out[[order.by]]), ]
    out
 }

An alternative for the command line interface is

ls.str()

which combines ls() and a very brief version of str() as applied to
each of the objects.

__
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] bwplot superpose panel.points from another dataframe

2010-09-28 Thread Deepayan Sarkar
On Tue, Sep 28, 2010 at 12:59 PM, Christophe Bouffioux
christophe@gmail.com wrote:
 Thanks for your help Peter
 but the red marks on boxplot do not correspond to ex2 dataframe
 actually, it reproduce on each panel the same marks
 that is to say the 3 first lines of ex2
 So this is not correct

You are probably looking for something like these:

bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2), X = ex3$v1b,
   pch = |,
   panel = function(x, y, ..., X, subscripts){
   panel.bwplot(x, y, ..., subscripts = subscripts)
   X - X[subscripts]
   X - tapply(X, y, unique)
   Y - tapply(y, y, unique)
   panel.points(X, Y, pch = 17, col = red)
   })


bwplot(v2 ~ v1 | z, data = ex, layout=c(3,2), ext.data = ex2,
   pch = |,
   panel = function(x, y, ..., ext.data){
   panel.bwplot(x, y, ...)
   i - which.packet()
   sub - subset(ext.data, as.numeric(z) == i)
   with(sub, panel.points(v1b, v2, pch = 17, col = red))
   })

-Deepayan



 Christophe

 On Mon, Sep 27, 2010 at 6:18 PM, Peter Ehlers ehl...@ucalgary.ca wrote:

 On 2010-09-27 4:54, Christophe Bouffioux wrote:

 bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2),
        pch = |,
        par.settings = list(
        plot.symbol = list(alpha = 1, col = transparent,cex = 1,pch =
 20)),
        panel = function(x, y){
             panel.bwplot(x, y)
             X- tapply(ex3$v1b, ex3[,c(1,2)], max)
             Y- seq(length(unique(ex3[,c(1,2)])))
             panel.points(X, Y, pch = 17, col = red)
             })


 Perhaps this is what you're trying to achieve:


  bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2),
       panel = function(x, y){
            panel.bwplot(x, y, pch=|)
            X - tapply(ex3$v1b, ex3[, 1:2], max)
            Y - seq(nrow(unique(ex3[, 1:2])))

            panel.points(X, Y, pch = 17, col = red)
            })

 (I didn't see any need for your par.settings.)

 I'm not crazy about the way you define X,Y. I think
 I would augment the data frame appropriately instead.

  -Peter Ehlers


        [[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-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] Compare two 3d plots

2010-09-28 Thread Ab Hu

I'll check that book out and/or get help from the authors. But i was still
hoping there is some basic way to compare these 3d plots using R. 
By the way, I figured out i can draw these plots using command image and
get a gradient heat map or topography map with gradients. Is there a
function in R to process the colors in these images and give me the
difference between two images?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Compare-two-3d-plots-tp2716325p2717123.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] Best package for time series analysis with wavelets???

2010-09-28 Thread Dennis Murphy
Hi:

You might find this useful:
http://finzi.psych.upenn.edu/R/library/wavelets/html/ecg.html

You could also try package wmtsa, the Insightful Wavelet Methods for Time
Series Analysis package. But there's more :)

The results of this search also appear to dig up some useful packages and
functions:

library(sos)# install it first if you don't have it
findFn('wavelet time series')

The results will appear in your browser. I got 175 hits over several
packages. sos is a *very* useful package.

HTH,
Dennis

On Tue, Sep 28, 2010 at 4:34 AM, gaussllego gluonesconle...@gmail.comwrote:


 Hi!!

 I'm looking for a package in R for time series analysis using wavelets( I'm
 interested on extractingt information from electrocardiograms with the aim
 of study the heart rate variability) so i want to know which package is the
 best for me. I've thinking about using some of those(you can recommend me
 others,xD):

 *wavelets: A package of funtions for computing wavelet filters, wavelet
 transforms and multiresolution analyses.

 *waveslim: Basic wavelet routines for one-, two- and three-dimensional
 signal processing.

 *wavethresh: Wavelets statistics and transforms.

 *mtsa: Insightful Wavelet Methods for Time Series Analysis(Software to book
 Wavelet Methods for Time Series Analysis, so i don't know if it's
 reliable).

 What do you think??

 thanks for your help!!
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Best-package-for-time-series-analysis-with-wavelets-tp2717043p2717043.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] cochran Q test

2010-09-28 Thread Kohleth Chia
Thanks for all the suggestions. It seems that I still have to write my own code 
after all.
But I am really surprised that no one has done it in a proper package yet.


KC
^_^

On 28/09/2010, at 9:18 PM, Dennis Murphy wrote:

 Hi:
 
 Try here:
 
 https://stat.ethz.ch/pipermail/r-help/2006-September/113156.html
 
 HTH,
 Dennis
 
 On Mon, Sep 27, 2010 at 7:27 PM, Kohleth Chia kohl...@gmail.com wrote:
 Dear all,
 
 I am trying to look for a built in function that performs the cochran Q
 test.
 that is, cochranq.test(X)
 where X is a contingency table (maybe a matrix or data.frame).
 The output will naturally be the test statisitcs, p-value, etc.
 
 A quick search on Google gives me the cochran.test in the 'outlier' package,
 but I had a look at the description of the test and it doesn't look anything
 close to the cochran Q test.
 
 MY questions is:
 1. Is that cochran.test the cochran Q test I am looking for?
 2. If not, where can I find such function? I DON'T want to write my own
 function.
 
 Thanks
 
 --
 KC
 ^_^
 
[[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.
 


[[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] 95% confidence intercal with glm

2010-09-28 Thread Ben Bolker
zozio32 remy.pascal at gmail.com writes:

 
 
 Hi
 
 I had to use a glm instead of my basic lm on some data due to unconstant
 variance.
 
 now, when I plot the model over the data, how can I easily get the 95%
 confidence interval that sormally coming from:
 
yv - predict(modelVar,list(aveLength=xv),int=c)
matlines(xv,yv,lty=c(1,2,2))
 
 There is no interval argument to pass to the predict function when using a
 glm, so I was wondering if I had to use an other function
 

  You need to use predict with se=TRUE; construct the confidence
intervals by computing predicted values +- 1.96 times the standard
error returned; and apply the inverse link function for your model.

  If heteroscedasticity is your main problem, and not a specific
(known) non-normal distribution, you might consider using the gls
function from the nlme package with an appropriate 'weights' argument.

__
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] stacked area chart

2010-09-28 Thread Ista Zahn
Hi Dimitri,
I'm not proficient with base graphics, but here is a ggplot solution:

my.data.m - melt(my.data, id=date)
my.data.m$pn - +
my.data.m[my.data.m$variable %in% c(y, z), pn] - -
my.data.m$variable - factor(my.data.m$variable, levels=c(a, x, y, z))
my.data.m$Date - as.numeric(my.data.m$date)

ggplot(my.data.m, aes(x=Date, y=value, fill=variable)) +
  geom_area(data=subset(my.data.m, pn==+)) +
  geom_area(data=subset(my.data.m, pn==-)) +
  scale_x_continuous(breaks=unique(my.data.m$Date),
labels=unique(my.data.m$date)) +
  scale_fill_manual(values=c(yellow, blue, green, orange)) +
  theme_bw() +
  ylab(Title of Y) +
  opts(title=Chart title, axis.text.x=theme_text(angle=70, vjust=1, hjust=1))


HTH,
Ista

On Mon, Sep 27, 2010 at 6:05 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 I found a solution to my original question (see code below).
 But I have a question about cosmetics, which I always find very challenging.
 1. How can I make all dates appear on the X axis (rotated at 90
 degrees vs. horizontal)?
 2. How can I create vertical grid lines so that at each date there is
 a gridline?
 3. How can I create a legend for colors, but not on top of the graph
 but on the right side, outside of the graph (because in my real data
 set I have a lot of variables - so that there'll never be enough space
 for the legend in the graph itself)

 Thanks a lot!
 Dimitri


 ### Creating a data set with both positives and negatives
 my.data-data.frame(date=c(20080301,20080402,20080503,20090301,20090402,20090503,20100301,20100402,20100503),
 x=c(1.1,1.0,1.6,1,2,1.5,2.1,1.3,1.9),y=c(-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9),
 z=c(-0.2,-0.3,-0.4,-0.1,-0.2,-0.05,-0.2,-0.15,-0.06),a=c(10,13,15,15,16,17,15,16,14))
 my.data$date-as.character(my.data$date)
 my.data$date-as.Date(my.data$date,%Y%m%d)
 (my.data)

 positives-which(colSums(my.data[2:ncol(my.data)])0) # which vars
 have positive column sums?
 negatives-which(colSums(my.data[2:ncol(my.data)])0) # which vars
 have negative column sums?

 y.max-1.1*max(rowSums(my.data[names(positives)])) # the max on the y
 axis of the chart
 y.min-1.1*min(rowSums(my.data[names(negatives)])) # the min on the y
 axis of the chart
 ylim - c(y.min, y.max)
 order.positives-rev(rank(positives))
 order.of.pos.vars-names(order.positives)
 order.negatives-rev(rank(negatives))
 order.of.neg.vars-names(order.negatives)
 order-c(order.negatives,order.positives)
 order.of.vars-names(order)   # the order of variables on the chart -
 from the bottom up
 ### so, the bottom-most area should be for z, the second from the
 bottom area- for y (above z)

 all.colors-c('red','blue','green','orange','yellow','purple')
 xx - c(my.data$date, rev(my.data$date))
 bottom.y.coordinates-rowSums(my.data[names(negatives)])

 plot(x=my.data$date, y=bottom.y.coordinates, ylim=ylim, col='white',
 type='l', xaxt='n',
    ylab='Title for Y', xlab='Date', main='Chart Title')

 for(var in order.of.neg.vars){
        top.line.coords-bottom.y.coordinates-my.data[[var]]
        bottom.coords-c(bottom.y.coordinates,rev(top.line.coords))
        polygon(xx,bottom.coords,col=all.colors[which(names(my.data) %in% 
 var)])
        bottom.y.coordinates-top.line.coords
 }

 for(var in order.of.pos.vars){
        top.line.coords-bottom.y.coordinates+my.data[[var]]
        bottom.coords-c(bottom.y.coordinates,rev(top.line.coords))
        polygon(xx,bottom.coords,col=all.colors[which(names(my.data) %in% 
 var)])
        bottom.y.coordinates-top.line.coords
 }



 On Mon, Sep 27, 2010 at 11:47 AM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 Dear R-ers!

 Asking for your help with building the stacked area chart for the
 following simple data (several variables - with date on the X axis):

 ### Creating a data set
 my.data-data.frame(date=c(20080301,20080402,20080503,20090301,20090402,20090503,20100301,20100402,20100503),
 x=c(1.1,1.0,1.6,1,2,1.5,2.1,1.3,1.9),y=c(-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9),
 z=c(-0.2,-0.3,-0.4,-0.1,-0.2,-0.05,-0.2,-0.15,-0.06),a=c(4,3,5,5,6,7,5,6,4))
 my.data$date-as.character(my.data$date)
 my.data$date-as.Date(my.data$date,%Y%m%d)
 (my.data)

 I'd like the variables whose column values sum up to a negative number
 to be below zero on that chart and those that add up to a positive
 number to be above zero in the chart. I am calculating values for ylim
 and for the order of the variable entry (bottom up) like this:

 positives-which(colSums(my.data[2:ncol(my.data)])0) # which vars
 have positive column sums?
 negatives-which(colSums(my.data[2:ncol(my.data)])0) # which vars
 have negative column sums?

 y.max-1.1*max(rowSums(my.data[names(positives)])) # the max on the y
 axis of the chart
 y.min-1.1*min(rowSums(my.data[names(negatives)])) # the min on the y
 axis of the chart
 ylim - c(y.min, y.max)  # ylim for the stacked area chart

 order.positives-rev(rank(positives))
 order.negatives-rev(rank(negatives))
 order-c(order.negatives,order.positives)
 order.of.vars-names(order)   # the 

Re: [R] time series

2010-09-28 Thread Giovanni Petris

Unless you tell us what model or what forecasting technique you want to
use, it seems to me that this is more a question about Statistics than
about using R.

Best,
Giovanni Petris 


On Mon, 2010-09-27 at 23:02 +0100, Dr. Alireza Zolfaghari wrote:
 Hi list,
 I have a set of data which I want to use time series analysis in R in order
 to forecast the value for future. I know there are some R functions, but not
 sure how to use them. Would you please help me if you are familiar with time
 series in R? I want to get value for Nov 2012 using the following data.
 
 thanks
 Alireza
 
 time value Mar-80 72 Jun-80 77.4 Sep-80 81.9 Dec-80 81 Mar-81 80.1 Jun-81
 77.4 Sep-81 67.5 Dec-81 68.4 Mar-82 55.8 Jun-82 42.3 Sep-82 32.4 Dec-82 22.5
 Mar-83 25.2 Jun-83 32.4 Sep-83 27 Dec-83 36 Mar-84 33.3 Jun-84 41.4 Sep-84
 20.7 Dec-84 18.9 Mar-85 11.7 Jun-85 15.3 Sep-85 9 Dec-85 13.5 Mar-86 17.1
 Jun-86 16.2 Sep-86 24.3 Dec-86 28.8 Mar-87 33.3 Jun-87 41.4 Sep-87 46.8
 Dec-87 61.2 Mar-88 68.4 Jun-88 74.7 Sep-88 58.5 Dec-88 57.6 Mar-89 63.9
 Jun-89 52.2 Sep-89 50.4 Dec-89 50.4 Mar-90 42.3 Jun-90 38.7 Sep-90 26.1
 Dec-90 25.2 Mar-91 27 Jun-91 18.9 Sep-91 15.3 Dec-91 15.3 Mar-92 16.2 Jun-92
 17.1 Sep-92 13.5 Dec-92 15.3 Mar-93 18.9 Jun-93 15.3 Sep-93 19.8 Dec-93 27.9
 Mar-94 33.3 Jun-94 51.3 Sep-94 40.5 Dec-94 60.3 Mar-95 59.4 Jun-95 58.5
 Sep-95 47.7 Dec-95 57.6 Mar-96 45.9 Jun-96 37.8 Sep-96 30.6 Dec-96 37.8
 Mar-97 40.5 Jun-97 34.2 Sep-97 28.8 Dec-97 26.1 Mar-98 26.1 Jun-98 15.3
 Sep-98 11.7 Dec-98 10.8 Mar-99 10.8 Jun-99 13.5 Sep-99 22.5 Dec-99 32.4
 Mar-00 39.6 Jun-00 32.4 Sep-00 35.1 Dec-00 27 Mar-01 29.7 Jun-01 35.1 Sep-01
 34.2 Dec-01 42.3 Mar-02 51.3 Jun-02 61.2 Sep-02 61.2 Dec-02 57.6 Mar-03 53.1
 Jun-03 45 Sep-03 48.6 Dec-03 54.9 Mar-04 61.2 Jun-04 63 Sep-04 71.1 Dec-04
 78.3 Mar-05 70.2 Jun-05 73.8 Sep-05 77.4 Dec-05 75.6 Mar-06 76.5 Jun-06 72.9
 Sep-06 76.5 Dec-06 74.7 Mar-07 72 Jun-07 72 Sep-07 64.8 Dec-07 60.3 Mar-08
 43.2 Jun-08 40.5 Sep-08 30.6 Dec-08 29.7 Mar-09 24.3 Jun-09 23.4 Sep-09 20.7
 Dec-09 25.2 Mar-10 38.7 Jun-10 32.4 Sep-10 42.3
 
   [[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-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] Standard error of forecast

2010-09-28 Thread Brima

Hi all,

This is very basic but for a starter nothing is. I have a simple linear
regression I am using to predict some values and I need the standard error
of the prediction (forecast). Whats the easiest/bestway of getting this
error?

Best regards
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Standard-error-of-forecast-tp2717125p2717125.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] bwplot superpose panel.points from another dataframe

2010-09-28 Thread Christophe Bouffioux
BINGO
we have the solution

thanks a lot both, Deepayan and Dennis, for your help

Christophe

On Tue, Sep 28, 2010 at 2:10 PM, Deepayan Sarkar
deepayan.sar...@gmail.comwrote:

 On Tue, Sep 28, 2010 at 12:59 PM, Christophe Bouffioux
 christophe@gmail.com wrote:
  Thanks for your help Peter
  but the red marks on boxplot do not correspond to ex2 dataframe
  actually, it reproduce on each panel the same marks
  that is to say the 3 first lines of ex2
  So this is not correct

 You are probably looking for something like these:

 bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2), X = ex3$v1b,
   pch = |,
   panel = function(x, y, ..., X, subscripts){
   panel.bwplot(x, y, ..., subscripts = subscripts)
   X - X[subscripts]
   X - tapply(X, y, unique)
   Y - tapply(y, y, unique)
   panel.points(X, Y, pch = 17, col = red)
   })


 bwplot(v2 ~ v1 | z, data = ex, layout=c(3,2), ext.data = ex2,
   pch = |,
   panel = function(x, y, ..., ext.data){
   panel.bwplot(x, y, ...)
   i - which.packet()
   sub - subset(ext.data, as.numeric(z) == i)
   with(sub, panel.points(v1b, v2, pch = 17, col = red))
   })

 -Deepayan

 
 
  Christophe
 
  On Mon, Sep 27, 2010 at 6:18 PM, Peter Ehlers ehl...@ucalgary.ca
 wrote:
 
  On 2010-09-27 4:54, Christophe Bouffioux wrote:
 
  bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2),
 pch = |,
 par.settings = list(
 plot.symbol = list(alpha = 1, col = transparent,cex = 1,pch =
  20)),
 panel = function(x, y){
  panel.bwplot(x, y)
  X- tapply(ex3$v1b, ex3[,c(1,2)], max)
  Y- seq(length(unique(ex3[,c(1,2)])))
  panel.points(X, Y, pch = 17, col = red)
  })
 
 
  Perhaps this is what you're trying to achieve:
 
 
   bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2),
panel = function(x, y){
 panel.bwplot(x, y, pch=|)
 X - tapply(ex3$v1b, ex3[, 1:2], max)
 Y - seq(nrow(unique(ex3[, 1:2])))
 
 panel.points(X, Y, pch = 17, col = red)
 })
 
  (I didn't see any need for your par.settings.)
 
  I'm not crazy about the way you define X,Y. I think
  I would augment the data frame appropriately instead.
 
   -Peter Ehlers
 
 
  [[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] Table with different digit number

2010-09-28 Thread Nicola Sturaro Sommacal (Quantide srl)
Hi!

I have a table representing both absolute and relative frequency, for
example (code to get example data under the signature):

   ItalyGermany
absolute100 105
relative 40.51 41.18

How can I print a different number of decimal digits? I try to transform to
as.character, but cells result aligned to left and I don't like this
solution. At the end of my work I need to export the table to HTML, so this
can be do also with xtable package.

Thanks in advance for your help.

Nicola Sturaro Sommacal

-- 
Quantide srl
http://www.quantide.com



This is the code to get the data.frame with the data above:

df = data.frame(italy = c(100,40.51), germany = c(105, 41.18))
row.names(df) = c(absolute, relative)

[[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] plotting multiple animal tracks against Date/Time

2010-09-28 Thread Struve, Juliane

Hi,

in this self-contained example the file the same error message appears as when 
I read in my original results files.

library (zoo)
library(chron)
#generate example data
Fish_ID=1646
 Date - 01/01/2004 00:01:00
 Date - as.POSIXct(strptime(Date,format=%m/%d/%Y %H:%M:%S))
 R2sqrt -100
#put into dataframe
Test - data.frame(Fish_ID=Fish_ID,Date=Date,R2sqrt=R2sqrt)
# write .csv file
write.csv(Test,file=Test)
#generate list of files
filenames=Test
#read file(s) into zoo object
read.zoo(file=filenames, header = TRUE, FUN = as.chron, sep = ,, colClasses = 
c(NULL, NULL, character, numeric)) #works fine
#read list of files into zoo.object
lapply(filenames, read.zoo, header = TRUE, FUN = as.chron, sep = ,, 
colClasses = c(NULL, NULL, character, numeric))# error
Error in strptime(x, format, tz = tz) : invalid 'x' argument

Am I missing something ?

Thank you for your time and patience.


Juliane

Sorry for posting twice, libraries were missing earlier.

From: Gabor Grothendieck [ggrothendi...@gmail.com]
Sent: 27 September 2010 23:32
To: Struve, Juliane
Cc: r-help@r-project.org
Subject: Re: [R] plotting multiple animal tracks against Date/Time

On Mon, Sep 27, 2010 at 5:38 PM, Struve, Juliane
j.str...@imperial.ac.uk wrote:
 Hello,

 thank you very much for replying. The code yields an error message

 Error in strptime(x, format, tz = tz) : invalid 'x' argument

 But I can't see what's wrong with it, the Date/Time info  is in the third 
 column, format is
 %Y-%m-%d %H:%M:%S. There is no time zone info in the data, could this be a 
 problem ?


See the last line on every message to r-help.  You need to put
together a minimal self contained example that illustrates the
problem.
The best I can do with the information provided is to point out that this works:

 Lines - ',Fish_ID,Date,R2sqrt
+ 1,1646,2006-08-18 08:48:59,0
+ 2,1646,2006-08-18 09:53:20,100'

 library(zoo)
 library(chron)
 read.zoo(textConnection(Lines), header = TRUE, FUN = as.chron,
+  sep = ,, colClasses = c(NULL, NULL, character, numeric))
(08/18/06 08:48:59) (08/18/06 09:53:20)
  0 100






--
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Table with different digit number

2010-09-28 Thread Gabriela Cendoya
Try
round(df,2)
for two decimal digits

Gabriela

2010/9/28, Nicola Sturaro Sommacal (Quantide srl) mailingl...@sturaro.net:
 Hi!

 I have a table representing both absolute and relative frequency, for
 example (code to get example data under the signature):

ItalyGermany
 absolute100 105
 relative 40.51 41.18

 How can I print a different number of decimal digits? I try to transform to
 as.character, but cells result aligned to left and I don't like this
 solution. At the end of my work I need to export the table to HTML, so this
 can be do also with xtable package.

 Thanks in advance for your help.

 Nicola Sturaro Sommacal

 --
 Quantide srl
 http://www.quantide.com

 

 This is the code to get the data.frame with the data above:

 df = data.frame(italy = c(100,40.51), germany = c(105, 41.18))
 row.names(df) = c(absolute, relative)

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



-- 
_
Lic. María Gabriela Cendoya
Magíster en Biometría
Profesor Adjunto
Facultad de Ciencias Agrarias
UNMdP - Argentina

__
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] Table with different digit number

2010-09-28 Thread Henrique Dallazuanna
Try this:

 df[1,] - as.character(df[1,])

On Tue, Sep 28, 2010 at 8:48 AM, Nicola Sturaro Sommacal (Quantide srl) 
mailingl...@sturaro.net wrote:

 Hi!

 I have a table representing both absolute and relative frequency, for
 example (code to get example data under the signature):

   ItalyGermany
 absolute100 105
 relative 40.51 41.18

 How can I print a different number of decimal digits? I try to transform to
 as.character, but cells result aligned to left and I don't like this
 solution. At the end of my work I need to export the table to HTML, so this
 can be do also with xtable package.

 Thanks in advance for your help.

 Nicola Sturaro Sommacal

 --
 Quantide srl
 http://www.quantide.com

 

 This is the code to get the data.frame with the data above:

 df = data.frame(italy = c(100,40.51), germany = c(105, 41.18))
 row.names(df) = c(absolute, relative)

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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[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] Standard error of forecast

2010-09-28 Thread Ista Zahn
Hi,

predict(model_fit, se.fit=TRUE)

see ?predict.lm for details.

-Ista

On Tue, Sep 28, 2010 at 12:16 PM, Brima adamsteve2...@yahoo.com wrote:

 Hi all,

 This is very basic but for a starter nothing is. I have a simple linear
 regression I am using to predict some values and I need the standard error
 of the prediction (forecast). Whats the easiest/bestway of getting this
 error?

 Best regards
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Standard-error-of-forecast-tp2717125p2717125.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.




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.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.


[R] the arima()-function and AICc

2010-09-28 Thread Benedikt Gehr

 Hi

I'm trying to fit arima models with the arima() function and I have two 
questions.


##
##1. ##
##
I have n observations for my time series. Now, no matter what 
arima(p,d,q)- model I fit, I always get n residuals. How is that possible?
For example: If I try this out myself on an AR(1) and calculate the 
fitted values from the estimated coefficients I can calculate n-1 
residuals. What is the first residual - residuals[1] in the model?

Does it have something to do with the mean?

Here is what I did: - X is the time series I'm analysing

X-c(6.770705, 6.842524, 6.881832, 6.896694, 7.004967, 7.065750, 
7.139447, 7.227818, 7.274945, 7.333097, 7.350763, 7.404271, 7.426247, 
7.394454, 7.303650, 7.176984, 7.170972, 7.113736, 7.154326, 7.136678, 
7.103826, 7.146775, 7.084247, 7.016302, 6.784539, 6.705846, 6.709989, 
6.851557, 6.973064, 7.232223)


## The AR(1) Model

model10-arima(X,order=c(1,0,0),include.mean=T)

mu-model10[[1]][[2]]
a-model10[[1]][[1]]

## Get the fitted values and residuals of the arima(1,0,0)-model

fitted-vector(mode=numeric)
E-vector(mode=numeric)
for (i in 2:30){
fitted[i]-a*(X[i-1]-mu)+mu
E[i]-X[i]-fitted[i]
}
fitted
E# Innovations
residuals(model10)# Compare with the residuals from the arima() 
model


##
##2. ##
##
I want to calculate the AICc Value for model selection. Is there a way 
to calculate the AICc from the model output without doing it manually. I 
guess I could write a function myself somehow but it's always nice to 
have an inbuilt function with which to compare what one does. I know 
that there has been some discussion on this on the platform but I didn't 
find anything that helped me. I tried AICctab from the bbmle package but 
I couldn't figure out how to get my output from arima into the function. 
I tried with making a list of the logLik(mdoel) output and several other 
things but it never worked.


Any help with this is most appreciated

many thanks in advance

cheers

Beni

__
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] Offre illimitée Iphone 4 : Accesoires Off erts

2010-09-28 Thread ACTA SOLUTIONS COMMERCIALES

  Si ce message ne s'affiche pas correctement, [1]visualisez la version en
   ligne

[2]Remplissez ce formulaire pour ne plus recevoir notre newsletter.
 A réception, celui-ci sera pris en compte.

References

   Visible links
   1. http://ase.emv3.com/HM?a=DNX7CkLCed-q8SA9MOOiVdHnGHxKQNOlSQ-T
   2. http://ase.emv3.com/HP?a=DNX7CkLCed-q8SA9MOOiVdHnGHxKQNOlTQ9v

   Hidden links:
   3. http://ase.emv3.com/HS?a=DNX7CkLCed-q8SA9MOOiVdHnGHxKQNOlTg-S
   4. http://ase.emv3.com/HS?a=DNX7CkLCed-q8SA9MOOiVdHnGHxKQNOlTw9t
   5. http://ase.emv3.com/HS?a=DNX7CkLCed-q8SA9MOOiVdHnGHxKQNOlTA9s
__
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] Regular expressions: offsets of groups

2010-09-28 Thread William Dunlap

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Bedward
 Sent: Tuesday, September 28, 2010 12:46 AM
 To: Titus von der Malsburg
 Cc: r-help@r-project.org
 Subject: Re: [R] Regular expressions: offsets of groups
 
 What Titus wants to do is akin to retrieving capturing groups from a
 Matcher object in Java. I also thought there must be an existing,
 elegant solution to this some time ago and searched for it, including
 looking at the sources (albeit with not much expertise) but came up
 blank.
 
 I also looked at the stringr package (which is nice) but it doesn't
 quite do it either.

S+ has a subpattern=number argument to regexpr and
related functions.  It means that the text matched
by the subpattern'th parenthesized expression in the
pattern will be considered the matched text.  E.g.,
to find runs of b's that come immediately after a's:

   gregexpr(a+(b+), abcdaabbc, subpattern=1)
  [[1]]:
  [1] 2 7
  attr(, match.length):
  [1] 1 2

or to find bc's that come after 2 or more ab's
   gregexpr((ab){2,}bc, abbcabababbcabcababbc, subpattern=1)

regexpr() and strsplit() have this argument in S+ 8.1 but
gregexpr() is not yet in a released version of S+.

subpattern=0, the default, means to use the entire
pattern.  regexpr allows subpattern=-1, which means
to return a list with one element for each subpattern.
I don't know if the extra complexity is worth it.
(gregexpr does not allow subpattern=-1.)

The usual C regexec() returns this information.
Perhaps it would be handy to have it in R.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 
 Michael
 
 On 28 September 2010 01:48, Titus von der Malsburg 
 malsb...@gmail.com wrote:
  Dear list!
 
  gregexpr(a+(b+), abcdaabbc)
  [[1]]
  [1] 1 5
  attr(,match.length)
  [1] 2 4
 
  What I want is the offsets of the matches for the group (b+), i.e. 2
  and 7, not the offsets of the complete matches.  Is there a way in R
  to get that?
 
  I know about gsubgn and strapply, but they only give me the strings
  matched by groups not their offsets.
 
  I could write something myself that first takes the above matches
  (ab and aabb) and then searches again using only the group (b+).
  For this to work, I'd have to parse the regular expression 
 and search
  several times ( 2, for nested groups) instead of just 
 once.  But I'm
  sure there is a better way to do this.
 
  Thanks for any suggestion!
 
    Titus
 
  __
  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-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] Splitting data in to multiple boxplots

2010-09-28 Thread deadlyspider

Hi,

I have a data set in the following format:


id  cat  value
1   a12
2   a23
3   a14
4   b2
5   b3
6   c9
7   c8
8   c10
9   d30


I would like to set up boxplots for each category. The actual category names
are long and many so I would like this to be split automatically. Is this
possible? Can anybody point me in the right direction for this?

Thanks.


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Splitting-data-in-to-multiple-boxplots-tp2717491p2717491.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] Splitting data in to multiple boxplots

2010-09-28 Thread Joshua Wiley
Hi,

There is a very handy feature of boxplot() that will handle this
easily.  You can write formulae of the form:
scores ~ groups

For your sample data:
# read in data
dat - read.table(textConnection(
id  cat  value
1   a12
2   a23
3   a14
4   b2
5   b3
6   c9
7   c8
8   c10
9   d30
), header = TRUE)
closeAllConnections()

# this should give you boxplots by cat, also note the data argument
# which tells it where to look for the variable names
boxplot(value ~ cat, data = dat)

HTH,

Josh

On Tue, Sep 28, 2010 at 9:24 AM, deadlyspider wrcst...@gmail.com wrote:

 Hi,

 I have a data set in the following format:


 id  cat  value
 1   a    12
 2   a    23
 3   a    14
 4   b    2
 5   b    3
 6   c    9
 7   c    8
 8   c    10
 9   d    30


 I would like to set up boxplots for each category. The actual category names
 are long and many so I would like this to be split automatically. Is this
 possible? Can anybody point me in the right direction for this?

 Thanks.


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Splitting-data-in-to-multiple-boxplots-tp2717491p2717491.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.



--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.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] Opening a .R file with R (Windows)

2010-09-28 Thread Kye Gilder
I am new to using R.  I installed R on my computer (Windows) and everything
things appears to be just fine.  However, I have a simple script RTest.R
that does a few simple calculations.  When I double-click the RTest.R icon,
I get an Information dialong box which says, ARGUMENT 'C:\Documents and
Settings\kgilder\Desktop\RTest.R' __ignored__ .  When I choose OK, R then
opens, but it does not open or display the script.  Any help or suggestions?

When I open R and use File  Open New Script and path to the file, it opens
just fine.
Regards,

Kye

[[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] Opening a .R file with R (Windows)

2010-09-28 Thread Joshua Wiley
Hi Kye,

I have never gotten .R files to work quite like other types (e.g.,
double-clicking a .PDF) in Windows.  AFAIK there is no simple way to
do it, because you do not edit scripts directly in R (I am happy to be
corrected if someone knows better).  For general use, I would just
open R first and then open the file, or if you just want to run the
file, you can use R's batch mode from the Windows command prompt.

Best regards,

Josh

On Tue, Sep 28, 2010 at 10:11 AM, Kye Gilder kye.gil...@gmail.com wrote:

 I am new to using R.  I installed R on my computer (Windows) and everything
 things appears to be just fine.  However, I have a simple script RTest.R
 that does a few simple calculations.  When I double-click the RTest.R icon,
 I get an Information dialong box which says, ARGUMENT 'C:\Documents and
 Settings\kgilder\Desktop\RTest.R' __ignored__ .  When I choose OK, R then
 opens, but it does not open or display the script.  Any help or suggestions?

 When I open R and use File  Open New Script and path to the file, it opens
 just fine.
 Regards,

 Kye

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



--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.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.


Re: [R] Opening a .R file with R (Windows)

2010-09-28 Thread Bert Gunter
Well, try following the correct conventions ...

1. Double click on an .Rdata file, which is produced by saving from R,
and it will open.

2. Drag and drop a .R or any text file into an open R window and it
will source the contents.

This is probably documented somewhere .. maybe in the RW FAQ.

-- Bert

On Tue, Sep 28, 2010 at 10:22 AM, Joshua Wiley jwiley.ps...@gmail.com wrote:
 Hi Kye,

 I have never gotten .R files to work quite like other types (e.g.,
 double-clicking a .PDF) in Windows.  AFAIK there is no simple way to
 do it, because you do not edit scripts directly in R (I am happy to be
 corrected if someone knows better).  For general use, I would just
 open R first and then open the file, or if you just want to run the
 file, you can use R's batch mode from the Windows command prompt.

 Best regards,

 Josh

 On Tue, Sep 28, 2010 at 10:11 AM, Kye Gilder kye.gil...@gmail.com wrote:

 I am new to using R.  I installed R on my computer (Windows) and everything
 things appears to be just fine.  However, I have a simple script RTest.R
 that does a few simple calculations.  When I double-click the RTest.R icon,
 I get an Information dialong box which says, ARGUMENT 'C:\Documents and
 Settings\kgilder\Desktop\RTest.R' __ignored__ .  When I choose OK, R then
 opens, but it does not open or display the script.  Any help or suggestions?

 When I open R and use File  Open New Script and path to the file, it opens
 just fine.
 Regards,

 Kye

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



 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.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.




-- 
Bert Gunter
Genentech Nonclinical Biostatistics

__
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] Best package for time series analysis with wavelets???

2010-09-28 Thread gaussllego

Hi djmuseR!
Hi everybody!

Thanks for your answer djmuseR (I've just discovered the sos library and
it's really useful,xD)...

I would also like to know if there's a trully reliable,recommended wavelet's
library in R(In the sense that if,for example, there's some library that's
often used in scientific projects or mentioned in articles).

I need your opinion to help me choose the library! I expect your answers...

Thank you!!

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Best-package-for-time-series-analysis-with-wavelets-tp2717043p2717659.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 equivalent to read.csv / write.csv

2010-09-28 Thread statquant2

Hi, after testing 
R) system.time(read.csv(myfile.csv))
   user  system elapsed
  1.126   0.038   1.177

R) system.time(read.csv.sql(myfile.csv))
   user  system elapsed
  1.405   0.025   1.439
Warning messages:
1: closing unused connection 4 ()
2: closing unused connection 3 ()

It seems that the function is less efficient that the base one ... so ...
-- 
View this message in context: 
http://r.789695.n4.nabble.com/efficient-equivalent-to-read-csv-write-csv-tp2714325p2717585.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] constrained optimization -which package?

2010-09-28 Thread Leonardo Monasterio
Dear R users,

I want to find the maximum value of v,  subject to the constrain that
the sum of x is equal to 1.
So, I want to maximize:
v-t(x)%*%distance%*%x

Subject to:
sum(x)=1

Where:
x is a vector n X 1
distance is a matrix n*n and it is given.
(In practive, the number of n can go up to hundreds.)

I have a bit of experience using R but not much on optimization
techniques or on R optimization packages.  I have taken a look at
optim and nlminb, but I am confused.
 Do you have any suggestion on how to do it?
Thank you very much,
Leo  Monasterio.

__
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] Best package for time series analysis with wavelets???

2010-09-28 Thread Ben Bolker
gaussllego gluonesconleche at gmail.com writes:

 I would also like to know if there's a trully reliable,recommended wavelet's
 library in R(In the sense that if,for example, there's some library that's
 often used in scientific projects or mentioned in articles).

   I don't know, but I would suggest that you take the names of
the packages that you find via the sos package [despite the fact
that you use the 'library' function to load them, they're called
packages] and do a Google scholar search, possibly with some additional
search terms that are specific to your field, and see what scholarly/
peer-reviewed articles you can turn up.  That's what I would do.

  Ben Bolker

__
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] constrained optimization -which package?

2010-09-28 Thread Peng, C

?constrOptim


-- 
View this message in context: 
http://r.789695.n4.nabble.com/constrained-optimization-which-package-tp2717677p2717719.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 equivalent to read.csv / write.csv

2010-09-28 Thread Henrik Bengtsson
To speed things up, you certainly want to give R more clues about your
data files by being more explicit by many of the arguments (cf.
help(read.table), especially specifying argument 'colClasses' makes a
big difference.

/Henrik

On Tue, Sep 28, 2010 at 10:24 AM, statquant2 statqu...@gmail.com wrote:

 Hi, after testing
 R) system.time(read.csv(myfile.csv))
   user  system elapsed
  1.126   0.038   1.177

 R) system.time(read.csv.sql(myfile.csv))
   user  system elapsed
  1.405   0.025   1.439
 Warning messages:
 1: closing unused connection 4 ()
 2: closing unused connection 3 ()

 It seems that the function is less efficient that the base one ... so ...
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/efficient-equivalent-to-read-csv-write-csv-tp2714325p2717585.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] Howto view function's source code of an installed package

2010-09-28 Thread Mark Miller


I justed wanted to provide a description of how I was able to view source
code of a function.

First download the Program R package containing the function.  Specifically,
download the file that ends in tar.gz.  This is a compressed file.  Expand
the compressed file using, for example, WinZip.  Next open the
uncompressed file that ends in .tar.  I was able to open that file with
the free software 7-Zip available on the internet.  After installing that
software I clicked on the file 7zFM.exe and navigated to the directory
containing the .tar file.  You can extract the contents of that .tar
file into a new folder.  The contents consist of R files showing the source
code for the functions in the R package.  These R files can be opened with a
text editor.

Hopefully, it is okay to mention other software here by name.  I have used
the above method twice in the last few months to view source code for
functions.  In both instances I needed a substantial amount of time to
figure out how to do it.  This post might help others and perhaps will help
myself in the future.

Mark W. Miller

Gainesville, Florida


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Howto-view-function-s-source-code-of-an-installed-package-tp831711p2717744.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] break function execution

2010-09-28 Thread Greg Snow
Ctrl-C works on some platforms, it would help us to help you if we knew which 
OS you are using, which version of R you are using, and in some cases whether 
you are using the GUI or Terminal version of R.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of raje...@cse.iitm.ac.in
 Sent: Tuesday, September 28, 2010 2:13 AM
 To: r-help
 Subject: [R] break function execution
 
 
 Hi,
 
 I have an R function that executes for a little over a minute. When the
 function starts running, the R interface freezes and doesnt change
 until the function exits cleanly. Is there someway I can force the
 function to exit without messing up the interface?(An equivalent of
 Ctrl-C)
 
 Additionally, can I run the function in background and get a
 notification when it completes?
   [[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-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] Combining two variables in text

2010-09-28 Thread Greg Snow
Also ?sprintf for another approach.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Johannes Huesing
 Sent: Tuesday, September 28, 2010 5:25 AM
 To: r-help@r-project.org
 Subject: Re: [R] Combining two variables in text
 
 trb1 thomasrbol...@yahoo.co.uk [Tue, Sep 28, 2010 at 12:12:01PM
 CEST]:
 [...]
  Also, how can I combine several variables in text
  i.e. suppose I have
  a - one
  b - two
  then what expression can I place in
  title(main=...)
  in terms of a and b to give an output title of
  one, two
  i.e. a then b separated by a comma.
 
 
 Type ?paste at the prompt.
 
 --
 Johannes Hüsing   There is something fascinating about
 science.
   One gets such wholesale returns of
 conjecture
 mailto:johan...@huesing.name  from such a trifling investment of fact.
 http://derwisch.wikidot.com (Mark Twain, Life on the
 Mississippi)
 
 __
 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] Howto view function's source code of an installed package

2010-09-28 Thread Sicotte, Hugues
The instructions below are for examining files from a source code file. 
For package binaries, the R code may be in a binary file (.rdb).. Then
the following will help.

The first thing to try is to
Download and install the package and type library(packagename)

Type the function name (without the ()). All exported functions will be
visible (export commands in the NAMESPACE file of each package). In a
compiled packages, some internal functions may not be exported and be
visible.



Hugues
 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Mark Miller
Sent: Tuesday, September 28, 2010 2:10 PM
To: r-help@r-project.org
Subject: Re: [R] Howto view function's source code of an installed
package



I justed wanted to provide a description of how I was able to view
source
code of a function.

First download the Program R package containing the function.
Specifically,
download the file that ends in tar.gz.  This is a compressed file.
Expand
the compressed file using, for example, WinZip.  Next open the
uncompressed file that ends in .tar.  I was able to open that file
with
the free software 7-Zip available on the internet.  After installing
that
software I clicked on the file 7zFM.exe and navigated to the directory
containing the .tar file.  You can extract the contents of that .tar
file into a new folder.  The contents consist of R files showing the
source
code for the functions in the R package.  These R files can be opened
with a
text editor.

Hopefully, it is okay to mention other software here by name.  I have
used
the above method twice in the last few months to view source code for
functions.  In both instances I needed a substantial amount of time to
figure out how to do it.  This post might help others and perhaps will
help
myself in the future.

Mark W. Miller

Gainesville, Florida


-- 
View this message in context:
http://r.789695.n4.nabble.com/Howto-view-function-s-source-code-of-an-in
stalled-package-tp831711p2717744.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] break function execution

2010-09-28 Thread Peter Langfelder
On Tue, Sep 28, 2010 at 12:18 PM, Greg Snow greg.s...@imail.org wrote:
 Ctrl-C works on some platforms, it would help us to help you if we knew which 
 OS you are using, which version of R you are using, and in some cases whether 
 you are using the GUI or Terminal version of R.

 Hi,

 I have an R function that executes for a little over a minute. When the
 function starts running, the R interface freezes and doesnt change
 until the function exits cleanly. Is there someway I can force the
 function to exit without messing up the interface?(An equivalent of
 Ctrl-C)

 Additionally, can I run the function in background and get a
 notification when it completes?

On Windows you need to press the Escape (Esc) key. However, some
compiled functions are not programmed to be interruptible and neither
Ctrl-C nor Esc will stop them.

As far as I know, there's no way to run something in the background
from the interactive R prompt (there may be a way to hack it together
using threads, but not on all platforms), but you can always write a
full script and use R CMD BATCH to run it in batch mode, possibly in
the background.

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.


[R] ask for a question with cch function

2010-09-28 Thread Qian Xiyuan
Dear all,
I am reading the cch function source code. But I can not understand the
following codes. Please help me.
What's the fitter here?

 fitter - get(method)
 out - fitter(tenter = tenter, texit = texit, cc = cc, id = id, X = X, ntot
= nn, robust = robust)

[[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] confirming behavior of by

2010-09-28 Thread Daryl Morris

 Hi,

I'm using by to summarize by multiple groups, and want to extract the 
returned into a pretty dataframe.  I'm trying to find a simple way to 
name the rows of the data frame.  I'd like it to be something like 
index1.val1.index2.val2 where the index1 and index2 are the names of the 
indices and the val1  val2 are names of possible values of the index.  
(the calling function will do a bit more processing)


I had thought to use attr(byOut,dimnames) for this, but the author of 
by chose to output that as a string rather than as a vector... and I'm 
too lazy to figure out parsing that at this point.  I'm thinking it's 
probably easier to determine the order external to by.


Finally ... my question ... the help for by says: A data frame is 
split by row into data frames subsetted by the values of one or more 
factors.   Should I infer from this that the elements are factorized?  
And that the order of the rows would be the same as if we did factor, 
with the default options (ie alphabetical)?  Further, is that applied 
iteratively, with each subgroup broken into the factors for the 
remaining indices (which would have the order as if they were 
factorized)?  And that the order of the data has no bearing on the order 
of the results?


hopefully that makes sense.

or if someone else has a better way of getting the job done?

thanks, Daryl Morris
FHCRC, UW

__
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 equivalent to read.csv / write.csv

2010-09-28 Thread David Scott

On 29/09/2010 6:24 a.m., statquant2 wrote:


Hi, after testing
R) system.time(read.csv(myfile.csv))
user  system elapsed
   1.126   0.038   1.177

R) system.time(read.csv.sql(myfile.csv))
user  system elapsed
   1.405   0.025   1.439
Warning messages:
1: closing unused connection 4 ()
2: closing unused connection 3 ()

It seems that the function is less efficient that the base one ... so ...


I presume you have had a good look at the R Data Import/Export manual?

It does there warn of inefficiency with read.table (hence also read.csv) 
and suggest more direct use of scan which in your case might be via 
connections and readLines and writeLines.


If that doesn't work, why not go to a database. Use RODBC or some such 
to read and write tables in the database. There are many options for 
databases to use (MySQL works for me). You can easily read data in and 
out of the database in .csv format. If the .csv files are similar there 
shouldn't be too much overhead in defining table formats for the database.



David Scott

--
_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

__
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] Howto view function's source code of an installed package

2010-09-28 Thread Prof Brian Ripley

On Tue, 28 Sep 2010, Mark Miller wrote:




I justed wanted to provide a description of how I was able to view source
code of a function.

First download the Program R package containing the function.  Specifically,
download the file that ends in tar.gz.  This is a compressed file.  Expand
the compressed file using, for example, WinZip.  Next open the
uncompressed file that ends in .tar.  I was able to open that file with
the free software 7-Zip available on the internet.  After installing that
software I clicked on the file 7zFM.exe and navigated to the directory
containing the .tar file.  You can extract the contents of that .tar
file into a new folder.  The contents consist of R files showing the source
code for the functions in the R package.  These R files can be opened with a
text editor.

Hopefully, it is okay to mention other software here by name.  I have used
the above method twice in the last few months to view source code for
functions.  In both instances I needed a substantial amount of time to
figure out how to do it.  This post might help others and perhaps will help
myself in the future.


Why not just use the untar() function in package utils?  Since you 
appear to be on Windows (do study and follow the posting guide), using 
R is much the easiest.




Mark W. Miller

Gainesville, Florida


--
View this message in context: 
http://r.789695.n4.nabble.com/Howto-view-function-s-source-code-of-an-installed-package-tp831711p2717744.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.



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


[R] constrained optimization -which package?

2010-09-28 Thread Leonardo Monasterio
Dear R users,

In the function bellow I  want to find the maximum value of v,
subject to the constrain that the sum of x is equal to 1.
 I want to maximize:
v-t(x)%*%distance%*%x

Subject to:
sum(x)=1

Where:
x is a vector n X 1
distance is a matrix n*n and it is given.
(In practice, the number of n can go up to hundreds.)

I have a bit of experience using R but not much on optimization
techniques or on R optimization packages.  I have taken a look at
optim and nlminb, but I am quite confused.
 Do you have any suggestion on how to do it?
Thank you very much,
Leo  Monasterio.

__
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] Problem with unlist

2010-09-28 Thread Susan Gruber
I suspect the problem is that table() is not displaying the correct
length.  Try
  table(n, useNA=ifany)

--Susan


Message: 75
Date: Mon, 27 Sep 2010 11:41:24 -0700
From: Henrik Bengtsson h...@stat.berkeley.edu
To: Ben Bolker bbol...@gmail.com
Cc: r-help r-h...@stat.math.ethz.ch
Subject: Re: [R] Problem with unlist
Message-ID:
aanlkti=hym1y25uc_fkdxh5qde14v3k_a5ub6azgj...@mail.gmail.com
Content-Type: text/plain; charset=ISO-8859-1

On Mon, Sep 27, 2010 at 5:27 AM, Ben Bolker bbol...@gmail.com wrote:
 Luis Felipe Parra felipe.parra at quantil.com.co writes:


 ?Hello, I am trying to unlist a list, which is attached, and I am
having the
 problem that when I unlist it the number of elements changes from 5065 to
 5084

 ? x - lapply(SumaPluvi, FUN=[, 1);
  n - sapply(x, FUN=length);
  print(table(n));
 n
 ? ?1
 5065
  print(which(n != 1));
 integer(0)
  length(unlist(lapply(SumaPluvi, FUN=[, 1)))
 [1] 5081
 

 I dont now why, but when I unlist it the number of elements changes from
 5065 to 5084 even if there is no list element with length greater than
one.
 Do you know what can be happening?


 ?We probably won't be able to get farther without a reproducible
 example. ?One brute-force way of finding the problem is by bisection:
 i.e., try the first and last halves of your list separately, and see
 if either one individually shows a similar problem. ?Proceed recursively
 until you localize the problem ...

...and as alternative, my most recent post did contain an updated code
snippet that is likely to find list elements generating more than one
value.

/Henrik

__
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] A problem with plotting a long expression in ylab ?

2010-09-28 Thread Ben Bolker
Barry Rowlingson b.rowlingson at lancaster.ac.uk writes:

  My point is that in regular text, ylab plots it where it then goes outside
  the borders.
  With the use of expressions - the text just doesn't show up.
  Originally I thought it was because of my miss-use of expressions, until I
  figured it was the level of cex.lab I was using.
  The problem is that when you can't see the text, you don't have a sense of
  how much to decrease the cex.lab so the text will fit.
  I hope I was now clearer.
 
 Gotcha. Seems to only affect ylab though. Do this:
 
   t =  expression(paste(test
 loo(% of 360 *degree,
 )))
   plot(1,xlab=t,ylab=t,main=t)
 
 then if I shrink my graphics window I can make the ylab disappear but
 not the xlab or title.
 
  Seems to affect any rotated expressions:
 
  plot(1)
  text(1,1,t,srt=90)
  text(1,1,t,srt=0)
  text(1,1,t,srt=45)
 
  Now shrink window and watch the rotated expressions vanish! They
 disappear when they start (or finish) out of the entire graphics
 device, not the plot region...
 
  I cant find anything relating to clipping in the help, and I am on
 Linux, so see if there's any news about it, try it with R-patched or
 R-devel and then report a bug after having read all the other stuff
 about R bug reporting!
 
 Barry


   I don't claim to understand it, but there is something quite
fundamental about the properties of the X11() graphics device in R
that makes labels that would otherwise overlap, disappear -- if
you do 'extreme resizing' with the graphics above, you can see that
otherwise-overlapping x- and y-axis tick labels disappear as the
graph gets scrunched.  This is (apparently) true of X11 graphics
on MacOS as well -- Quartz window has a different behavior.
Trying with pdf() as well -- for height=2, width=2, only 1 y-axis
and 2 x-axis tick labels survive, *but* the x and y labels and the
title are all still present (but clipped, of course).
   [Hmmm. Take my reports above with a grain of salt, I wasn't
always using expression()s.]

  So I would guess that if you reported this as a bug you would
be told that it was a poorly documented property of R's X11
graphics model, rather than a bug ...

  I have no idea where to start looking for more information
about what defines this behavior -- if I were desperate to know
I would probably try asking Paul Murrell ...

  I would be very interested to see this discussed on r-devel,
if anyone bit ...

   Ben Bolker

__
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] Time invariant coefficients in a time varying coefficients model using dlm package

2010-09-28 Thread Christian Schoder
Dear R-users,

I am trying to estimate a state space model of the form

(1) b_t = G * b_t-1 + w_tw_t ~ N(0,W)

(2) y_t= A' * x_t + H' * b_t + v_t v_t ~ N(0,V)

(Hamilton 1984: 372)

In particular my estimation in state space form looks like

(3) a3_t = 1 * a3_t-1 + w_t  w_t ~ N(0,W)

(4) g_t = (a1, a2) * (1, P_t)' + u_t * a3_t + v_tv_t ~ N(0,V)

where g_t is the investment rate, P_t are profits and u_t is the
utilization rate. As you can see, I would like to estimate the
coefficient of the utilization rate in time-varying terms and all the
other coefficients of the investment function in constant terms. 

The issue I have now is that the package dlm only allows for
specifications of the form

(5) b_t = 1 * b_t-1 + w_tw_t ~ N(0,W)

(6) y_t = F_t * b_t + v_t v_t ~ N(0,V)

where b_t is the vector of parameters. Hence, it does not allow me to
take parameters as time-invariant. In terms of my investment
specification this reads

(7) (a1_t, a2_t, a3_t)' = diag(3) * (a1_t-1, a2_t-1, a3_t-1)' + w_t
w_t ~ N(0,W)

(8) g_t = (1, P_t, u_t) * (a1_t, a2_t, a3_t)' + v_tv_t ~ N(0,V)

As far as I understand state space modeling the following restrictions
on the Variance-covariance matrix W should imply a1_t=a1 and a2_t=a2
which is time invariant:

(9) W=[(0,0,0),(0,0,0),(0,0,w_33)]

However, if I apply the filter (dlmFilter) (not smoother) on this
specification with estimated values for the unknown paramters (w_33 and
matrix V) in order to get the series of the state vector (a1_t, a2_t,
a3_t)' then for some reason a1_t and a2_t are not constant!!! a3_t isn't
either but this is how it is supposed to be. How is that possible when I
told the model that the variance of the first two elements of the state
vector are zero? Is the problem the fact that I use the filter instead
of the smoother?

Could someone please point out to me, how I would have to specify the
state space model for the dlm package so that the coefficients of my
first two regressors are actually time invariant?

Thank you very much for your support on this!!

Christian

__
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] drawing samples based on a matching variable

2010-09-28 Thread L Brown
Hi, everyone. I have what I hope will be a simple coding question. It seems
this is a common job, but so far I've had trouble finding the answer in
searches.

I have two matrices (x and y) with a different number of observations in
each. I need to draw a random sample without replacement of observations
from x, and then, using a matching variable, draw a sample of equal size
from y. It is the matching variable that is hanging me up.

For example--

 # example matrices. lets assume seed always equals 1. (lets also assume I
have assigned variable names A and B to my columns..)
 set.seed(1)
 x-cbind(1:10,sample(1:5,10,rep=T))
 x
  [A] [B]
 [1,]12
 [2,]22
 [3,]33
 [4,]45
 [5,]52
 [6,]65
 [7,]75
 [8,]84
 [9,]94
[10,]   101

 y-cbind(1:14,sample(1:5,14,rep=T))
 y
  [A] [B]
 [1,]12
 [2,]22
 [3,]33
 [4,]45
 [5,]52
 [6,]65
 [7,]75
 [8,]84
 [9,]94
[10,]   101
[11,]   112
[12,]   121
[13,]   134
[14,]   142

 #draw random sample of n=4 without replacement from matrix x.
 x.samp-x[sample(10,4,replace=F),]
 x.samp
 [A] [B]
[1,]33
[2,]45
[3,]52
[4,]75

Next, I would need to draw four observations from matrix y (without
replacement) so that the distribution of y$B is identical to x.samp$B.

I'd appreciate any help, and sorry to post such a basic question!

LB

[[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] ask for a question with cch function

2010-09-28 Thread Bill.Venables
It would help if you were to tell up which package you are talking about.  I 
take it this is the survival package and this is the proportioanl hazards 
fitting function for case-cohort data.  

You would have seen earlier in the code that

method - match.arg(method)

so at that stage 'method' is a character string.  The default is Prentice.

so

fitter - get(method)

will search for an object whose name matches that character string and return 
it.  Presumably this is a fitting function requested on the call to fit the 
model.

So the answer to your question is The fitter here is whatever method the user 
specified on the call.  If none were specified it defaults to Prentice().

Next you will probably want to know where Prentice() can be found.  The answer 
is inside the survival NAMESPACE, and it is not exported.  So to see that 
function you will need to use

survival:::Prentice

This will most likely become very tedious and ultimately frustrating.  You can 
always look at code - that's the facility that open source software is famous 
for providing - but it really is a last resort.  You are much better reading 
the documentation very carefully and checking the examples provided.  Trust me, 
I'm a statistician.

Bill Venables.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Qian Xiyuan
Sent: Wednesday, 29 September 2010 6:00 AM
To: r-help@r-project.org
Subject: [R] ask for a question with cch function

Dear all,
I am reading the cch function source code. But I can not understand the
following codes. Please help me.
What's the fitter here?

 fitter - get(method)
 out - fitter(tenter = tenter, texit = texit, cc = cc, id = id, X = X, ntot
= nn, robust = robust)

[[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-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] constrained optimization -which package?

2010-09-28 Thread Ravi Varadhan
No.  That would not work for equality constraints.  

This is quadratic programming problem.  Check out `quadprog' or any other
quad programming packages in R.

If you have more general, nonlinearly constrained optimization you can use
any one of the 3 following packages:

1. `spg' function in BB package
2.  `constrOptim.nl' or `auglag' functions in alabama package
3. `solnp' in Rsolnp package.

Hope this helps,
Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Peng, C
Sent: Tuesday, September 28, 2010 2:54 PM
To: r-help@r-project.org
Subject: Re: [R] constrained optimization -which package?


?constrOptim


-- 
View this message in context:
http://r.789695.n4.nabble.com/constrained-optimization-which-package-tp27176
77p2717719.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.


[R] fixing the dispersion parameter in glm

2010-09-28 Thread Huso, Manuela
I would like to fit a glm with Poisson distribution and log link with a known 
dispersion parameter.  I do not want to estimate the dispersion parameter.  I 
know what it is, so I simply want to fix it at a constant for this and other 
models to follow.  My simple, no covariate model is:

Tall.glm-glm(Seedling~1, 
family=poisson, 
offset(log(area)),
data=tallPSME.df)

I want to fix the dispersion parameter at 2.5.  How can I do this, please?

Thanks in advance,

Manuela
 
::
Manuela Huso
Consulting Statistician
201H Richardson Hall
Department of Forest Ecosystems and Society
Oregon State University
Corvallis, OR   97331
ph: 541-737-6232
fx: 541-737-1393

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of L Brown
Sent: Tuesday, September 28, 2010 2:47 PM
To: r-help@r-project.org
Subject: [R] drawing samples based on a matching variable

Hi, everyone. I have what I hope will be a simple coding question. It seems
this is a common job, but so far I've had trouble finding the answer in
searches.

I have two matrices (x and y) with a different number of observations in
each. I need to draw a random sample without replacement of observations
from x, and then, using a matching variable, draw a sample of equal size
from y. It is the matching variable that is hanging me up.

For example--

 # example matrices. lets assume seed always equals 1. (lets also assume I
have assigned variable names A and B to my columns..)
 set.seed(1)
 x-cbind(1:10,sample(1:5,10,rep=T))
 x
  [A] [B]
 [1,]12
 [2,]22
 [3,]33
 [4,]45
 [5,]52
 [6,]65
 [7,]75
 [8,]84
 [9,]94
[10,]   101

 y-cbind(1:14,sample(1:5,14,rep=T))
 y
  [A] [B]
 [1,]12
 [2,]22
 [3,]33
 [4,]45
 [5,]52
 [6,]65
 [7,]75
 [8,]84
 [9,]94
[10,]   101
[11,]   112
[12,]   121
[13,]   134
[14,]   142

 #draw random sample of n=4 without replacement from matrix x.
 x.samp-x[sample(10,4,replace=F),]
 x.samp
 [A] [B]
[1,]33
[2,]45
[3,]52
[4,]75

Next, I would need to draw four observations from matrix y (without
replacement) so that the distribution of y$B is identical to x.samp$B.

I'd appreciate any help, and sorry to post such a basic question!

LB

[[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-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] plotting multiple animal tracks against Date/Time

2010-09-28 Thread Gabor Grothendieck
On Tue, Sep 28, 2010 at 9:30 AM, Struve, Juliane
j.str...@imperial.ac.uk wrote:

 Hi,

 in this self-contained example the file the same error message appears as 
 when I read in my original results files.

 library (zoo)
 library(chron)
 #generate example data
 Fish_ID=1646
  Date - 01/01/2004 00:01:00
  Date - as.POSIXct(strptime(Date,format=%m/%d/%Y %H:%M:%S))
  R2sqrt -100
 #put into dataframe
 Test - data.frame(Fish_ID=Fish_ID,Date=Date,R2sqrt=R2sqrt)
 # write .csv file
 write.csv(Test,file=Test)
 #generate list of files
 filenames=Test
 #read file(s) into zoo object
 read.zoo(file=filenames, header = TRUE, FUN = as.chron, sep = ,, colClasses 
 = c(NULL, NULL, character, numeric)) #works fine
 #read list of files into zoo.object
 lapply(filenames, read.zoo, header = TRUE, FUN = as.chron, sep = ,, 
 colClasses = c(NULL, NULL, character, numeric))# error
 Error in strptime(x, format, tz = tz) : invalid 'x' argument

 Am I missing something ?

 Thank you for your time and patience.

Self contained means anyone else can just copy your code and paste it
into their session and see the error message you see.

Its likely that your file does not contain what you think it does.



-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] A problem with plotting a long expression in ylab ?

2010-09-28 Thread Paul Murrell

Hi

It is a bug.  A fix has been committed.

Thanks for the report!

Paul

On 29/09/2010 10:15 a.m., Ben Bolker wrote:

Barry Rowlingsonb.rowlingsonat  lancaster.ac.uk  writes:


My point is that in regular text, ylab plots it where it then goes outside
the borders.
With the use of expressions - the text just doesn't show up.
Originally I thought it was because of my miss-use of expressions, until I
figured it was the level of cex.lab I was using.
The problem is that when you can't see the text, you don't have a sense of
how much to decrease the cex.lab so the text will fit.
I hope I was now clearer.


Gotcha. Seems to only affect ylab though. Do this:

t =  expression(paste(test
loo(% of 360 *degree,
)))
plot(1,xlab=t,ylab=t,main=t)

then if I shrink my graphics window I can make the ylab disappear but
not the xlab or title.

  Seems to affect any rotated expressions:


plot(1)
text(1,1,t,srt=90)
text(1,1,t,srt=0)
text(1,1,t,srt=45)


  Now shrink window and watch the rotated expressions vanish! They
disappear when they start (or finish) out of the entire graphics
device, not the plot region...

  I cant find anything relating to clipping in the help, and I am on
Linux, so see if there's any news about it, try it with R-patched or
R-devel and then report a bug after having read all the other stuff
about R bug reporting!

Barry



I don't claim to understand it, but there is something quite
fundamental about the properties of the X11() graphics device in R
that makes labels that would otherwise overlap, disappear -- if
you do 'extreme resizing' with the graphics above, you can see that
otherwise-overlapping x- and y-axis tick labels disappear as the
graph gets scrunched.  This is (apparently) true of X11 graphics
on MacOS as well -- Quartz window has a different behavior.
Trying with pdf() as well -- for height=2, width=2, only 1 y-axis
and 2 x-axis tick labels survive, *but* the x and y labels and the
title are all still present (but clipped, of course).
[Hmmm. Take my reports above with a grain of salt, I wasn't
always using expression()s.]

   So I would guess that if you reported this as a bug you would
be told that it was a poorly documented property of R's X11
graphics model, rather than a bug ...

   I have no idea where to start looking for more information
about what defines this behavior -- if I were desperate to know
I would probably try asking Paul Murrell ...

   I would be very interested to see this discussed on r-devel,
if anyone bit ...

Ben Bolker

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


--
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
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] fixing the dispersion parameter in glm

2010-09-28 Thread Remko Duursma


How about:

y[y[,2] %in% x.samp[,2],]

gives you the subset of y where values in the second column are restricted
to your sample from x.

You can then sample from this matrix, if you need to...


greetings,
Remko
-- 
View this message in context: 
http://r.789695.n4.nabble.com/drawing-samples-based-on-a-matching-variable-tp2718009p2718128.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] constrained optimization -which package?

2010-09-28 Thread Peng, C

constrOptim()  can do linear and quadratic programming problems!  See the
following example from the help document.   
 
## Solves linear and quadratic programming problems
 ## but needs a feasible starting value
 #
 # from example(solve.QP) in 'quadprog'
 # no derivative
 fQP - function(b) {-sum(c(0,5,0)*b)+0.5*sum(b*b)}
 Amat   - matrix(c(-4,-3,0,2,1,0,0,-2,1),3,3)
 bvec   - c(-8,2,0)
 constrOptim(c(2,-1,-1), fQP, NULL, ui=t(Amat),ci=bvec)
 # derivative
 gQP - function(b) {-c(0,5,0)+b}
 constrOptim(c(2,-1,-1), fQP, gQP, ui=t(Amat), ci=bvec)
 
 ## Now with maximisation instead of minimisation
 hQP - function(b) {sum(c(0,5,0)*b)-0.5*sum(b*b)}
 constrOptim(c(2,-1,-1), hQP, NULL, ui=t(Amat), ci=bvec,
 control=list(fnscale=-1))

-- 
View this message in context: 
http://r.789695.n4.nabble.com/constrained-optimization-which-package-tp2717677p2718136.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] Problems creating an xts object

2010-09-28 Thread Luis Felipe Parra
Hello I am trying to create an xts object from a data frame that has numeric
and string variables. when I create the object all my variables are
converted to string, this is my original data frame:

 head(DatosF)
  FECHA CIERRE HORA DE CIERRE SESION/RUEDA PLAZO (De regreso para SIML,
Repos e INTB)  INSTRUMENTO TASA/ PRECIO TASA/ PRECIO EQUIV# VR# NOMINAL
CONTRAVALOR
1 20090803 080943
CONH  0 TFIT06140514
103.558   8.301   5e+09  5280535000
2 20090803 080944
CONH  0 TFIT06140514
103.562   8.300   2e+09  2112294000
3 20090803 081108
CONH  0 TUVT06200313
103.948   4.050   2e+07  3957262935
4 20090803 082116
CONH  0 TFIT05241110
103.488   4.663   5e+09  5433305000
5 20090803 082116
CONH  0 TFIT05241110
103.488   4.663   5e+09  5433305000
6 20090803 082116
CONH  0 TFIT05241110
103.489   4.662   5e+09  5433355000

 and this is what I am getting:

 head(XX)
FECHA CIERRE HORA DE CIERRE SESION/RUEDA PLAZO (De
regreso para SIML, Repos e INTB) INSTRUMENTO
2009-08-03 08:09:43 20090803   080943   CONH   
0   TFIT06140514 103.558
8.301
2009-08-03 08:09:44 20090803   080944   CONH   
0   TFIT06140514 103.562
8.300
2009-08-03 08:11:08 20090803   081108   CONH   
0   TUVT06200313 103.948
4.050
2009-08-03 08:21:16 20090803   082116   CONH   
0   TFIT05241110 103.488
4.663
2009-08-03 08:21:16 20090803   082116   CONH   
0   TFIT05241110 103.488
4.663
2009-08-03 08:21:16 20090803   082116   CONH   
0   TFIT05241110 103.489
4.662

Does anybody know what can be happening?

thank you

Felipe Parra

[[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] efficient equivalent to read.csv / write.csv

2010-09-28 Thread Gabor Grothendieck
On Tue, Sep 28, 2010 at 1:24 PM, statquant2 statqu...@gmail.com wrote:

 Hi, after testing
 R) system.time(read.csv(myfile.csv))
   user  system elapsed
  1.126   0.038   1.177

 R) system.time(read.csv.sql(myfile.csv))
   user  system elapsed
  1.405   0.025   1.439
 Warning messages:
 1: closing unused connection 4 ()
 2: closing unused connection 3 ()

 It seems that the function is less efficient that the base one ... so ...

The benefit comes with larger files.  With small files there is not
much point in speeding it up since the absolute time is already small.

Suggest you look at the benchmarks on the sqldf home page where a
couple of users benchmarked larger files.   Since sqldf was intended
for convenience and not really performance I was surprised as anyone
when several users independently noticed that sqldf ran several times
faster than unoptimized R code.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] move colorkey

2010-09-28 Thread Marlin Keith Cox
When using a wireframe, I need to move the colorkey from the right
position (default0 towards the plot.  I have also needed to adjust the
height and used the code

colorkey=list(T,space='right',height=.5)

I have looked at documents (within levelplot) but cannot find a way to
move the colorkey other than right, left, bottom and top.  I do not
understand corner interacts with x, y; unimplemented.  Is this a way
to place a colorkey.

keith

-- 
M. Keith Cox, Ph.D.
Alaska NOAA Fisheries, National Marine Fisheries Service
Auke Bay Laboratories
17109 Pt. Lena Loop Rd.
Juneau, AK 99801
keith@noaa.gov
marlink...@gmail.com
U.S. (907) 789-6603

__
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] Regular expressions: offsets of groups

2010-09-28 Thread Michael Bedward
Ah, that's interesting - thanks Bill. That's certainly on the right
track for me (Titus, you too ?) especially if the subpattern argument
accepted a vector of multiple group indices.

As you say, this is straightforward in C. I'd be happy to (try to)
make a patch for the R sources if there was some consensus on the best
way to implement it, ie. as a new R function or by extending existing
function(s).

Michael

On 29 September 2010 01:46, William Dunlap wrote:

 S+ has a subpattern=number argument to regexpr and
 related functions.  It means that the text matched
 by the subpattern'th parenthesized expression in the
 pattern will be considered the matched text.  E.g.,
 to find runs of b's that come immediately after a's:

   gregexpr(a+(b+), abcdaabbc, subpattern=1)
  [[1]]:
  [1] 2 7
  attr(, match.length):
  [1] 1 2

 or to find bc's that come after 2 or more ab's
   gregexpr((ab){2,}bc, abbcabababbcabcababbc, subpattern=1)

 regexpr() and strsplit() have this argument in S+ 8.1 but
 gregexpr() is not yet in a released version of S+.

 subpattern=0, the default, means to use the entire
 pattern.  regexpr allows subpattern=-1, which means
 to return a list with one element for each subpattern.
 I don't know if the extra complexity is worth it.
 (gregexpr does not allow subpattern=-1.)

 The usual C regexec() returns this information.
 Perhaps it would be handy to have it in R.

 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.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] quantile() and factors not allowed

2010-09-28 Thread Steve
A list (t) that I'm trying to pass to quantile() is causing this error:

Error in  quantile.default(t, probs = c(0.9, 9.95, 0.99))
  factors are not allowed

I've successfully use lists before, and am having difficulty finding my
mistake.  Any suggestions appreciated!

-Steve

__
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] stacked area chart

2010-09-28 Thread Dimitri Liakhovitski
Thanks a lot, Ista!

On Tue, Sep 28, 2010 at 10:00 AM, Ista Zahn iz...@psych.rochester.edu wrote:
 Hi Dimitri,
 I'm not proficient with base graphics, but here is a ggplot solution:

 my.data.m - melt(my.data, id=date)
 my.data.m$pn - +
 my.data.m[my.data.m$variable %in% c(y, z), pn] - -
 my.data.m$variable - factor(my.data.m$variable, levels=c(a, x, y, z))
 my.data.m$Date - as.numeric(my.data.m$date)

 ggplot(my.data.m, aes(x=Date, y=value, fill=variable)) +
  geom_area(data=subset(my.data.m, pn==+)) +
  geom_area(data=subset(my.data.m, pn==-)) +
  scale_x_continuous(breaks=unique(my.data.m$Date),
 labels=unique(my.data.m$date)) +
  scale_fill_manual(values=c(yellow, blue, green, orange)) +
  theme_bw() +
  ylab(Title of Y) +
  opts(title=Chart title, axis.text.x=theme_text(angle=70, vjust=1, hjust=1))


 HTH,
 Ista

 On Mon, Sep 27, 2010 at 6:05 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 I found a solution to my original question (see code below).
 But I have a question about cosmetics, which I always find very challenging.
 1. How can I make all dates appear on the X axis (rotated at 90
 degrees vs. horizontal)?
 2. How can I create vertical grid lines so that at each date there is
 a gridline?
 3. How can I create a legend for colors, but not on top of the graph
 but on the right side, outside of the graph (because in my real data
 set I have a lot of variables - so that there'll never be enough space
 for the legend in the graph itself)

 Thanks a lot!
 Dimitri


 ### Creating a data set with both positives and negatives
 my.data-data.frame(date=c(20080301,20080402,20080503,20090301,20090402,20090503,20100301,20100402,20100503),
 x=c(1.1,1.0,1.6,1,2,1.5,2.1,1.3,1.9),y=c(-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9),
 z=c(-0.2,-0.3,-0.4,-0.1,-0.2,-0.05,-0.2,-0.15,-0.06),a=c(10,13,15,15,16,17,15,16,14))
 my.data$date-as.character(my.data$date)
 my.data$date-as.Date(my.data$date,%Y%m%d)
 (my.data)

 positives-which(colSums(my.data[2:ncol(my.data)])0) # which vars
 have positive column sums?
 negatives-which(colSums(my.data[2:ncol(my.data)])0) # which vars
 have negative column sums?

 y.max-1.1*max(rowSums(my.data[names(positives)])) # the max on the y
 axis of the chart
 y.min-1.1*min(rowSums(my.data[names(negatives)])) # the min on the y
 axis of the chart
 ylim - c(y.min, y.max)
 order.positives-rev(rank(positives))
 order.of.pos.vars-names(order.positives)
 order.negatives-rev(rank(negatives))
 order.of.neg.vars-names(order.negatives)
 order-c(order.negatives,order.positives)
 order.of.vars-names(order)   # the order of variables on the chart -
 from the bottom up
 ### so, the bottom-most area should be for z, the second from the
 bottom area- for y (above z)

 all.colors-c('red','blue','green','orange','yellow','purple')
 xx - c(my.data$date, rev(my.data$date))
 bottom.y.coordinates-rowSums(my.data[names(negatives)])

 plot(x=my.data$date, y=bottom.y.coordinates, ylim=ylim, col='white',
 type='l', xaxt='n',
    ylab='Title for Y', xlab='Date', main='Chart Title')

 for(var in order.of.neg.vars){
        top.line.coords-bottom.y.coordinates-my.data[[var]]
        bottom.coords-c(bottom.y.coordinates,rev(top.line.coords))
        polygon(xx,bottom.coords,col=all.colors[which(names(my.data) %in% 
 var)])
        bottom.y.coordinates-top.line.coords
 }

 for(var in order.of.pos.vars){
        top.line.coords-bottom.y.coordinates+my.data[[var]]
        bottom.coords-c(bottom.y.coordinates,rev(top.line.coords))
        polygon(xx,bottom.coords,col=all.colors[which(names(my.data) %in% 
 var)])
        bottom.y.coordinates-top.line.coords
 }



 On Mon, Sep 27, 2010 at 11:47 AM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 Dear R-ers!

 Asking for your help with building the stacked area chart for the
 following simple data (several variables - with date on the X axis):

 ### Creating a data set
 my.data-data.frame(date=c(20080301,20080402,20080503,20090301,20090402,20090503,20100301,20100402,20100503),
 x=c(1.1,1.0,1.6,1,2,1.5,2.1,1.3,1.9),y=c(-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9),
 z=c(-0.2,-0.3,-0.4,-0.1,-0.2,-0.05,-0.2,-0.15,-0.06),a=c(4,3,5,5,6,7,5,6,4))
 my.data$date-as.character(my.data$date)
 my.data$date-as.Date(my.data$date,%Y%m%d)
 (my.data)

 I'd like the variables whose column values sum up to a negative number
 to be below zero on that chart and those that add up to a positive
 number to be above zero in the chart. I am calculating values for ylim
 and for the order of the variable entry (bottom up) like this:

 positives-which(colSums(my.data[2:ncol(my.data)])0) # which vars
 have positive column sums?
 negatives-which(colSums(my.data[2:ncol(my.data)])0) # which vars
 have negative column sums?

 y.max-1.1*max(rowSums(my.data[names(positives)])) # the max on the y
 axis of the chart
 y.min-1.1*min(rowSums(my.data[names(negatives)])) # the min on the y
 axis of the chart
 ylim - c(y.min, y.max)  # ylim for the stacked area chart

 order.positives-rev(rank(positives))
 

Re: [R] quantile() and factors not allowed

2010-09-28 Thread Joshua Wiley
Hi Steve,

The basic problem (as the error suggests) is that data of class
factor is not allowed in quantile.default.  So one of the elements
of your list must be a factor.  What are the results of:   str(t)  ?
As a side note, since t() is a function, using t as a variable name
can be a bit confusing.

If your list is relative small, you could post the results of dput(t)
which would allow us to see what your data is actually like and
perhaps identify the exact problem and offer a solution.

Cheers,

Josh


On Tue, Sep 28, 2010 at 5:56 PM, Steve n...@ittibitti.org wrote:
 A list (t) that I'm trying to pass to quantile() is causing this error:

 Error in  quantile.default(t, probs = c(0.9, 9.95, 0.99))
  factors are not allowed

 I've successfully use lists before, and am having difficulty finding my
 mistake.  Any suggestions appreciated!

 -Steve

 __
 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
University of California, Los Angeles
http://www.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] need help with ramdomly sampling some data

2010-09-28 Thread Michael Larkin
I am trying to get R to randomly select values from my dataset (i.e.
bootstrapping) with replacement.  However, my attempts at this have been
unsuccessful.  Here is a basic example of what I am doing:  

I have a data vector of 8 values (i.e. data= 2,5,9,4,5,6,7,8).  I used the
sample function and it worked.  However, it only repeated my values in the
exact same order as the dataset.  It did not randomly sample them.  Here the
code for what I did:  

sample(data, replace=TRUE)

Any advice to randomly select data from my dataset would be greatly
appreciated.  

Mike  

 


[[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] need help with ramdomly sampling some data

2010-09-28 Thread Peter Langfelder
On Tue, Sep 28, 2010 at 6:22 PM, Michael Larkin mlar...@rsmas.miami.edu wrote:
 I am trying to get R to randomly select values from my dataset (i.e.
 bootstrapping) with replacement.  However, my attempts at this have been
 unsuccessful.  Here is a basic example of what I am doing:

 I have a data vector of 8 values (i.e. data= 2,5,9,4,5,6,7,8).  I used the
 sample function and it worked.  However, it only repeated my values in the
 exact same order as the dataset.  It did not randomly sample them.  Here the
 code for what I did:

 sample(data, replace=TRUE)

You're doing the right thing. Perhaps your random seed was set in a
particular way, or perhaps you made some mistake in the execution, but
I get the following:

 data= c(2,5,9,4,5,6,7,8)
 sample(data, replace=TRUE)
[1] 5 5 5 4 9 8 2 7

which is what you likely want.

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] need help with ramdomly sampling some data

2010-09-28 Thread Jonathan Christensen
Mike,

It works for me:

 data - 1:8
 sample(data,replace=TRUE)
[1] 6 4 5 2 5 8 7 2

Please provide a reproducible example, if possible, and the output of
sessionInfo().

Jonathan


On Tue, Sep 28, 2010 at 7:22 PM, Michael Larkin mlar...@rsmas.miami.eduwrote:

 I am trying to get R to randomly select values from my dataset (i.e.
 bootstrapping) with replacement.  However, my attempts at this have been
 unsuccessful.  Here is a basic example of what I am doing:

 I have a data vector of 8 values (i.e. data= 2,5,9,4,5,6,7,8).  I used the
 sample function and it worked.  However, it only repeated my values in the
 exact same order as the dataset.  It did not randomly sample them.  Here
 the
 code for what I did:

 sample(data, replace=TRUE)

 Any advice to randomly select data from my dataset would be greatly
 appreciated.

 Mike




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


[[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] R Extensions getDLLVersion

2010-09-28 Thread Kyle Covington
Hi,

I'm just learning to write R extensions in C and to embed R in C.

I was trying to get through the example in the help page on calling the .dll
directly (
http://cran.r-project.org/doc/manuals/R-exts.html#Calling-R_002edll-directly
).

When I compile I consistently get the error that getDLLVersion() as well as
get_R_HOME() and getRUser() are not defined (this might not be verbatim the
error that I get, I'm compiling on a computer at work and posting this at
home).

These are defined in Rembedded.h ln60 as:
extern char *getDLLVersion(void), *getRUser(void), *get_R_HOME(void);

I included Rembedded.h from the example.

I searched the entire R directory for the string getDLLVersion and only
found it in Rembedded.h and the help documentation (for the .dll directly
example).

Am I missing some key file or just not understanding how these functions
work?  I'm just learning C so this may be a very basic question.  If anyone
could point me to a good reference on this it would be very helpful.

Technical Notes:
OS: win7 32bit
Compiler: mingw32
R: 2.11.1

Thanks
Kyle

[[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] drawing samples based on a matching variable

2010-09-28 Thread Michael Bedward
Hello LB,

It's one of those problems that's basic but tricky :)  I don't have an
elegant one-liner for it but here's a function that would do it...

function(xs, y) {
# sample matrix y such that col 2 of the sample matches
# col 2 of matrix xs

  used - logical(nrow(y))
  yi - integer(nrow(xs))

  k - 1
  for (xsval in xs[,2]) {
i - which( !used  y[,2] == xsval )
if (length(i) = 1) {
  yi[k] - sample(i, 1)
  used[ yi[k] ] - TRUE
  k - k + 1
} else {
  stop(bummer: not possible to get a matching sample)
}
  }

  y[yi, ]
}

Note, I've assumed here that in your real data the first col won't
always contain the row index as it does in your example.

Michael

On 29 September 2010 07:46, L Brown missmissl...@gmail.com wrote:
 Hi, everyone. I have what I hope will be a simple coding question. It seems
 this is a common job, but so far I've had trouble finding the answer in
 searches.

 I have two matrices (x and y) with a different number of observations in
 each. I need to draw a random sample without replacement of observations
 from x, and then, using a matching variable, draw a sample of equal size
 from y. It is the matching variable that is hanging me up.

 For example--

 # example matrices. lets assume seed always equals 1. (lets also assume I
 have assigned variable names A and B to my columns..)
 set.seed(1)
 x-cbind(1:10,sample(1:5,10,rep=T))
 x
      [A] [B]
  [1,]    1    2
  [2,]    2    2
  [3,]    3    3
  [4,]    4    5
  [5,]    5    2
  [6,]    6    5
  [7,]    7    5
  [8,]    8    4
  [9,]    9    4
 [10,]   10    1

 y-cbind(1:14,sample(1:5,14,rep=T))
 y
      [A] [B]
  [1,]    1    2
  [2,]    2    2
  [3,]    3    3
  [4,]    4    5
  [5,]    5    2
  [6,]    6    5
  [7,]    7    5
  [8,]    8    4
  [9,]    9    4
 [10,]   10    1
 [11,]   11    2
 [12,]   12    1
 [13,]   13    4
 [14,]   14    2

 #draw random sample of n=4 without replacement from matrix x.
 x.samp-x[sample(10,4,replace=F),]
 x.samp
     [A] [B]
 [1,]    3    3
 [2,]    4    5
 [3,]    5    2
 [4,]    7    5

 Next, I would need to draw four observations from matrix y (without
 replacement) so that the distribution of y$B is identical to x.samp$B.

 I'd appreciate any help, and sorry to post such a basic question!

 LB

        [[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-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] drawing samples based on a matching variable

2010-09-28 Thread Michael Bedward
On 29 September 2010 09:47, Remko Duursma wrote:


 How about:

 y[y[,2] %in% x.samp[,2],]

 gives you the subset of y where values in the second column are restricted
 to your sample from x.

 You can then sample from this matrix, if you need to...

Just saw this reply tangled up in another topic (at least in my inbox).

Yes, that gives all the rows of matrix y that contain a col 2 value in
the matrix sampled from x but still leaves a bit of leg work to do and
doesn't check that the sampling is actually possible.

Michael

__
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] need help with ramdomly sampling some data

2010-09-28 Thread Michael Larkin
I got it to work.  I didn't have the data listed as a vector (c in front of
the data).  I copied Peter's code and it worked perfectly.  Thanks!   

 

Mike  

 

From: Jonathan Christensen [mailto:dzhona...@gmail.com] 
Sent: Tuesday, September 28, 2010 9:31 PM
To: Michael Larkin
Cc: r-help@r-project.org
Subject: Re: [R] need help with ramdomly sampling some data

 

Mike,

It works for me:

 data - 1:8
 sample(data,replace=TRUE)
[1] 6 4 5 2 5 8 7 2

Please provide a reproducible example, if possible, and the output of
sessionInfo().

Jonathan



On Tue, Sep 28, 2010 at 7:22 PM, Michael Larkin mlar...@rsmas.miami.edu
wrote:

I am trying to get R to randomly select values from my dataset (i.e.
bootstrapping) with replacement.  However, my attempts at this have been
unsuccessful.  Here is a basic example of what I am doing:

I have a data vector of 8 values (i.e. data= 2,5,9,4,5,6,7,8).  I used the
sample function and it worked.  However, it only repeated my values in the
exact same order as the dataset.  It did not randomly sample them.  Here the
code for what I did:

sample(data, replace=TRUE)

Any advice to randomly select data from my dataset would be greatly
appreciated.

Mike




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

 


[[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] quantile() and factors not allowed

2010-09-28 Thread Steve
The underlying data contained values that resulted in Factor instead of
number fields during the read.csv.  Problem fixed!

I also introduced a typo while copying the error into my message, and as
for the poor variable naming, I'll be more careful.

Thanks x3!  Corrected structure:

 str(CPU)
'data.frame':   56470 obs. of  8 variables:
 $ Value   : num  2.91 9.10e-01 1.08e+07 3.88e+06 3.03 ...
 $ Timestamp   : Factor w/ 4835 levels 9/17/2010 15:30,..: 1 1 1 1 2 2 2
2 3 3 ...
 $ MetricId: Factor w/ 5 levels cpu.usage.average,..: 1 1 4 4 1 1 4
4 1 1 ...
 $ Unit: Factor w/ 4 levels %,count,KB,..: 1 1 3 3 1 1 3 3 1
1 ...
 $ Entity  : Factor w/ 2 levels system1,..: 2 1 2 1 2
1 2 1 2 1 ...
 $ EntityId: Factor w/ 3 levels ,EI1,..: 2 3 2 3 2
3 2 3 2 3 ...
 $ IntervalSecs: int  1800 1800 1800 1800 1800 1800 1800 1800 1800 1800
...
 $ Instance: Factor w/ 1 level : 1 1 1 1 1 1 1 1 1 1 ...

 Hi Steve,

 The basic problem (as the error suggests) is that data of class
 factor is not allowed in quantile.default.  So one of the elements
 of your list must be a factor.  What are the results of:   str(t)  ?
 As a side note, since t() is a function, using t as a variable name
 can be a bit confusing.

 If your list is relative small, you could post the results of dput(t)
 which would allow us to see what your data is actually like and
 perhaps identify the exact problem and offer a solution.

 Cheers,

 Josh


 On Tue, Sep 28, 2010 at 5:56 PM, Steve n...@ittibitti.org wrote:
 A list (t) that I'm trying to pass to quantile() is causing this error:

 Error in  quantile.default(t, probs = c(0.9, 9.95, 0.99))
  factors are not allowed

 I've successfully use lists before, and am having difficulty finding my
 mistake.  Any suggestions appreciated!

 -Steve

 __
 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
 University of California, Los Angeles
 http://www.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] next step in randomly sampling

2010-09-28 Thread Michael Larkin
Thanks to the people on this list I was able to fix my code for randomly
sampling.  Thanks.  

 

Now, I am moving on to the next step and I ran into another snag.  I have a
large dataset but I am starting with a small made-up dataset until I figure
it out.  I have two columns of data (age and length).  I got R to read my
data called growth which is the age and length for 10 fish:  

 

 growth

  Age Length

1   2200

2   5450

3   6600

4   7702

5   8798

6   5453

7   4399

8   1120

9   2202

 

Then I believe I converted my data to a three vectors by: 

 

newgrowth-c(growth)

 

Now I want to randomly select the values from this dataset to create a new
dataset.  I want to do this many times, however, for now I am just trying to
get it to randomly select from the dataset only once.  The trick is that I
need to keep the columns together.  Each age corresponds to a length.  For
example, the 200 length fish has an age of 2 years.  

 

I tried to resample the data with this code:   

 

sample(newgrowth)

 

However, I ended up getting the data listed as a row in the same order, not
randomly selected.  I pasted the result below.  

 

 sample(newgrowth)

$Age

[1] 2 5 6 7 8 5 4 1 2

 

$Length

[1] 200 450 600 702 798 453 399 120 202

 

Any advice on how I can randomly select from these 9 rows of data would be
greatly appreciated.  

 

Mike


[[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] get response from a glm

2010-09-28 Thread xinxin xx

Hi everyone:

  ¡¡I am new to R and I have a really basic question.
 I have already got a generalized linear model from some dataset, say y=b0 
+ b1X1 + b2X2.  Then I want to get the value of y provided, say, X1=1, X2=2.  
And the confidence Intervals of this y.
 I know I can just calculate that since I know the model already. But is 
there some code that can calculate those automatically?


Thank you very much!
  
[[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] next step in randomly sampling

2010-09-28 Thread Jonathan Christensen
Mike,

Try

growth[sample(1:length(growth)),]

to permute the rows.

Jonathan


On Tue, Sep 28, 2010 at 8:38 PM, Michael Larkin mlar...@rsmas.miami.eduwrote:

 Thanks to the people on this list I was able to fix my code for randomly
 sampling.  Thanks.



 Now, I am moving on to the next step and I ran into another snag.  I have a
 large dataset but I am starting with a small made-up dataset until I figure
 it out.  I have two columns of data (age and length).  I got R to read my
 data called growth which is the age and length for 10 fish:



  growth

  Age Length

 1   2200

 2   5450

 3   6600

 4   7702

 5   8798

 6   5453

 7   4399

 8   1120

 9   2202



 Then I believe I converted my data to a three vectors by:



 newgrowth-c(growth)



 Now I want to randomly select the values from this dataset to create a new
 dataset.  I want to do this many times, however, for now I am just trying
 to
 get it to randomly select from the dataset only once.  The trick is that I
 need to keep the columns together.  Each age corresponds to a length.  For
 example, the 200 length fish has an age of 2 years.



 I tried to resample the data with this code:



 sample(newgrowth)



 However, I ended up getting the data listed as a row in the same order, not
 randomly selected.  I pasted the result below.



  sample(newgrowth)

 $Age

 [1] 2 5 6 7 8 5 4 1 2



 $Length

 [1] 200 450 600 702 798 453 399 120 202



 Any advice on how I can randomly select from these 9 rows of data would be
 greatly appreciated.



 Mike


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


[[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] constrained optimization -which package?

2010-09-28 Thread Ravi Varadhan
Please read the help page carefully, the very first line that describes the 
function says, Minimise a function subject to linear inequality constraints.  
OP has a problem with equality constraints:  sum(x) = 1.

Furthermore, if you want to solve a QP problem then it is better to use a 
dedicated QP algorithm than to use a general-purpose nonlinear optimization 
algorithm.

Ravi.


Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Peng, C cpeng@gmail.com
Date: Tuesday, September 28, 2010 7:58 pm
Subject: Re: [R] constrained optimization -which package?
To: r-help@r-project.org


  constrOptim()  can do linear and quadratic programming problems!  See 
 the
  following example from the help document.   
   
  ## Solves linear and quadratic programming problems
   ## but needs a feasible starting value
   #
   # from example(solve.QP) in 'quadprog'
   # no derivative
   fQP - function(b) {-sum(c(0,5,0)*b)+0.5*sum(b*b)}
   Amat   - matrix(c(-4,-3,0,2,1,0,0,-2,1),3,3)
   bvec   - c(-8,2,0)
   constrOptim(c(2,-1,-1), fQP, NULL, ui=t(Amat),ci=bvec)
   # derivative
   gQP - function(b) {-c(0,5,0)+b}
   constrOptim(c(2,-1,-1), fQP, gQP, ui=t(Amat), ci=bvec)
   
   ## Now with maximisation instead of minimisation
   hQP - function(b) {sum(c(0,5,0)*b)-0.5*sum(b*b)}
   constrOptim(c(2,-1,-1), hQP, NULL, ui=t(Amat), ci=bvec,
   control=list(fnscale=-1))
  
  -- 
  View this message in context: 
  Sent from the R help mailing list archive at Nabble.com.
  
  __
  R-help@r-project.org mailing list
  
  PLEASE do read the posting guide 
  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] Object Browser

2010-09-28 Thread Vitally S.
wxffxw wxf...@gmail.com writes:

 So, is there any thing like the combination of eclipse and Jgr?
 If not, I am interested to develope something to fulfill this simple but
 very important function. But right now I have no idea where to start. Any
 suggestions?

If you are interested in developing such a browser,  you might try to contact
Ian Fellows the developer of Deducer (www.deducer.org). I am not using it myself
but it looks like there is an API for extensions and in addition Deducer works 
in
many IDEs (if not all).

I have in plan to write a tree like visual object inspector for ESS,  but it
will take some time.

If you manage to start the project, try to keep in mind that object browser is
actually an environment inspector so it could be used to inspect environments
in an hierarchical fashion. Such approach would be useful during a
debug session for instance.

Also the same code might be potentially useful for inspection of S4/S3 class
hierarchy, multilevel lists, proto hierarchies,  Rjava,  cpp or whatever object 
or
collections with tree-likes structure. So generality is relay important here.

Cheers,
Vitally.


 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.


[R] ramdom sampling from a dataset

2010-09-28 Thread Michael Larkin
I am trying to get R to pick random integers from my dataset (i.e.
bootstrapping) with replacement.  However, my attempts at this have been
unsuccessful.  Here is a basic example of what I am doing:  

I have a data vector of 8 integers (data= 2,5,9,4,5,6,7,8).  I used the
sample function and it worked but it only repeated my values in the exact
same order.  It did not randomly sample them.  Here is my code:  

sample(data, replace=TRUE)

Any advice would be greatly appreciated.  

Mike  

 

 


[[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] efficient equivalent to read.csv / write.csv

2010-09-28 Thread statquant2

Hello all,
the test I provided was just to pinpoint that for loading once a big csv
file with read.csv was quicker than read.csv.sql... I have already
optimized my calls to read.csv for my particular problem, but is a simple
call to read.csv was quicker than read.csv.sql I doubt that specifying args
would invert the reult a lot...

May be I should outline my problem :

I am working on a powerful machine with 32Go or 64Go of RAM, so loading file
and keeping them in memory is not really an issue.
Those files (let's say 100) are shared by many and are flat csv files (this
to say that modify them is out of question).
Those files have lots of rows and between 10 and 20 colums, string and
numeric...

I basically need to be able to load these files to quicker possible and then
I will keep those data frame in memory... 
So :
Should I write my own C++ function and call it from R ?
Or is there a R way of improving drastically read.csv ?

Thanks a lot
-- 
View this message in context: 
http://r.789695.n4.nabble.com/efficient-equivalent-to-read-csv-write-csv-tp2714325p2717937.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] Transforming/appending data (words in IMDB)

2010-09-28 Thread aeneas24

Hi everyone,

 
I am doing an analysis of reviews in IMDB and am running into trouble getting 
my data into the right shape for analysis. 
 
Key question: I want to know for each word in the IMDB, whether it is over- or 
under-represented in a particular category (Rating x Genre). I was figuring on 
estimating this with a g-test, fwiw. But the basic question I'm asking here is 
about data transformation/appending. To go from these columns:

Film| Genre1| Genre2 | Genre3 | Reviewer | Rating  | Word | Word_ct

to these:

Word | Genre | Rating | Word_ct | Word_ct_in_genre | Word_ct_in_Rating | 
Expected_word_ct | G-test-score

The actual amount of data is enormous (I have 10 files of ~1.5 GB each) and I 
suspect I'm going to have to learn how to use the bigmemory package or 
something like it. But for now, I'd be happy if I could figure out how to do 
some basic calculations on a toy-sized subset of the data.
 
Broader goal: I am trying to do is see how words pattern in different reviews. 
For example, if someone uses gross in a describing a romance, they probably 
gave it a low rating. But someone else describing a horror movie with gross 
may think of it as a positive thing.  

Below I've put what I've tried so far, with annotations about my thinking. 
-

# Here is what a little portion of the data looks like:
mini-read.csv(miniimdb.csv, header=F)
head(mini)
  FilmGenre1Genre2 Genre3 Reviewer Rating  Word Word_ct
1   Up Animation Adventure ComedyKelly  9   the22
2   Up Animation Adventure ComedyKelly  9   dog 5
3   Up Animation Adventure ComedyKelly  9   can10
4   Up Animation Adventure ComedyKelly  9   wow 2
5 Fame Drama Music   NA Jenn  8   the15
6 Fame Drama Music   NA Jenn  8 dance12

# Each row indicates one word as used by one reviewer for one movie. In the 
first line, we see that Kelly used the 22 times in her review of Up. The 
line gives us information about her review: she gave Up 9 stars (out of 10), 
22/32 people found her review helpful. Up is listed as multiple genres, which 
will become more inconvenient later. It would be easier if each row of Up 
occurred as three rows--identical except for Genre. So that's one 
transformation I'm not sure how to do. 

# I also need to sum up, say, how many times any word appears in a given genre 
(and later how often it appears in a given rating category so I can do the 
conditional probabilities and get my observed vs. expected values). Here's one 
way I thought about doing it:
  
data.by.genre1-split(mini,mini$Genre1)
data.by.genre1$Animation
   FilmGenre1Genre2 Genre3 Reviewer Rating Word Word_ct
1Up Animation Adventure ComedyKelly  9  the22
2Up Animation Adventure ComedyKelly  9  dog 5
3Up Animation Adventure ComedyKelly  9  can10
4Up Animation Adventure ComedyKelly  9  wow 2
11   Up Animation Adventure ComedyEddie  4  the12
12   Up Animation Adventure ComedyEddie  4  dog 4
13   Up Animation Adventure ComedyEddie  4  can 2
14   Up Animation Adventure ComedyEddie  4  boy 2

data.ani=data.by.genre1$Animation
ani.wc-sum(data.ani$V10)
ani.wc
[1] 59
miniplus=cbind(mini,ani.wc)
head(miniplus)
  FilmGenre1Genre2 Genre3 Reviewer Rating  Word Word_ct ani.wc
1   Up Animation Adventure ComedyKelly  9   the22 59
2   Up Animation Adventure ComedyKelly  9   dog 5 59
3   Up Animation Adventure ComedyKelly  9   can10 59
4   Up Animation Adventure ComedyKelly  9   wow 2 59
5 Fame Drama Music   NA Jenn  8   the15 59
6 Fame Drama Music   NA Jenn  8 dance12 59

# That's one approach, but it seems REALLY inefficient since I would have to 
have add a new column specific to each genre, whether it was appropriate for 
the film or not. Also, sometimes a genre is listed as the first genre, 
sometimes as the second or third. I actually want to report the total of all 
the's in Animation, whether Animation is listed as the first, second, or 
third genre. I'm not sure how to do that. 

# I've also tried to use the reshape library. That gets me a little closer to 
the kind of data I want, but I'm not really sure how to append it smartly. 

library(reshape)

# To use melt, I seem to need to shave off the columns I'm not interested in 
(film title and reviewer).

mininew-cbind(mini[2:4],mini[6:8])
head(melt(mininew,id=c(Word, Genre1, Genre2, Genre3, Rating), 
measured=c(Word_Ct)))
WordGenre1Genre2   Genre3 Rating variable value
1the Animation Adventure   Comedy  9Word_ct 22
2dog Animation Adventure   Comedy  9Word_ct 5
3can Animation Adventure   Comedy  9Word_ct 10
4wow Animation Adventure   Comedy  9Word_ct 2
5the Drama Music NA 

[R] short captions for xtable?

2010-09-28 Thread cuz

Hi,

For my dissertation, I have used xtable profusely. I'm also a fan of
extended captions in the text. However, these captions are unwieldy in the
List of Tables, so I'd like to use the short caption option available with
regular \caption usage. Is this possible?

Thanks,
Cuz
-- 
View this message in context: 
http://r.789695.n4.nabble.com/short-captions-for-xtable-tp2718226p2718226.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.


  1   2   >