Re: [R] image.plot adding x-axis labels. Please Help

2012-04-04 Thread David Lyon
Sorry that didnt work for me, any ideas?


- Original Message -
From: ilai ke...@math.montana.edu
To: David Lyon david_ly...@yahoo.com
Cc: r-help@r-project.org r-help@r-project.org
Sent: Tuesday, April 3, 2012 10:43 PM
Subject: Re: [R] image.plot adding x-axis labels. Please Help

On Tue, Apr 3, 2012 at 7:25 PM, David Lyon david_ly...@yahoo.com wrote:
 if I had a data file like this:
 1.42 1.29 -0.13
 1.46 1.34 -0.12
 1.45 1.32 -0.13
 1.36 1.26 -0.10
 1.33 1.29 -0.04

 I want to create a image plot like this:
 data1-read.table(A)

 image.plot(t(data1), axes=FALSE, xlab=NA, ylab=NA)

 I cant get the labels for the x axis right can some kind person help me?

axis(1,at=seq(0,1,l=ncol(data1)),labels=LETTERS[1:ncol(data1)])


 axis(1.???.labels=c(A, B, C))


 Many thanks in advance!

 __
 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] Trying to merge new data set to bottom of old data set. Both are zoo objects.

2012-04-04 Thread knavero
Here is the data I'm working with:

http://r.789695.n4.nabble.com/file/n4530888/new.txt new.txt 

http://r.789695.n4.nabble.com/file/n4530888/old.txt old.txt 

My code is here:

http://pastebin.com/9jjs6Ahr

I'm looking for away to simply attach the new.txt to the bottom of old.txt
through R, else I'll just throw it in Excel to do some preprocessing. I've
looked into using merge, cbind, concatenate, and rbind. However, I'm running
into problems where the 2012 data keeps ending up on top before the 2010 and
2011 data or the function just adds more extra columns to the right side. Is
there a simple method of doing this? Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/Trying-to-merge-new-data-set-to-bottom-of-old-data-set-Both-are-zoo-objects-tp4530888p4530888.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] Trying to merge new data set to bottom of old data set. Both are zoo objects.

2012-04-04 Thread knavero
Here's a case where it doesn't work. Again, the problem is that when I use
the rbind or concatenate functions, the 2012 data set seems to go ahead of
the 2010 and 2011 portions of the data set. The problem seems dependent on
the text files I read in:

http://r.789695.n4.nabble.com/file/n4531011/old.txt old.txt 

http://r.789695.n4.nabble.com/file/n4531011/new.txt new.txt 

using this code:

http://pastebin.com/8W6KaaPQ

In a case where it works, and the data seemed to be in the right order, I
read in a different old.txt named old1.txt and somehow it seemed to work.
The contents and format were similar to that of new.txt where there was 18
columns with the same headers. Here are the files to use:

http://r.789695.n4.nabble.com/file/n4531011/old1.txt old1.txt 

http://r.789695.n4.nabble.com/file/n4531011/new.txt new.txt 

using this code:

http://pastebin.com/6iNF5bPd

That should clarify the issue I'm having. Let me know if a dput is necessary
here. However all the vectors and vector modes seem to check out okay.  



--
View this message in context: 
http://r.789695.n4.nabble.com/Trying-to-merge-new-data-set-to-bottom-of-old-data-set-Both-are-zoo-objects-tp4530888p4531011.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] Grouping and/or splitting

2012-04-04 Thread Berend Hasselman

On 04-04-2012, at 07:15, Ashish Agarwal wrote:

 Yes. I was missing the DROP argument.
 But now the problem is splitting is causing some weird ordering of groups.

Why weird?

 See below:
 
 DF - read.table(text=
 Houseid,Personid,Tripid,taz
 1,1,1,4
 1,1,2,7
 2,1,1,96
 2,1,2,4
 2,1,3,2
 2,2,1,58
 3,1,5,7
 , header=TRUE, sep=,)
 aa - split(DF, DF[, 1:2], drop=TRUE)
 
 Now the result is aa[3] should is (3,1) and not (2,2). Why? How can I
 preserve the ascending order?
 

Try this

aa[order(names(aa))]

Berend

 aa[3]
 $`3.1`
  Houseid Personid Tripid taz
 7   31  5   7
 aa[4]
 $`2.2`
  Houseid Personid Tripid taz
 6   22  1  58
 
 
 On Wed, Apr 4, 2012 at 6:29 AM, Rui Barradas rui1...@sapo.pt wrote:
 
 Hello,
 
 
 Ashish Agarwal wrote
 
 I have a dataframe imported from csv file below:
 
 Houseid,Personid,Tripid,taz
 1,1,1,4
 1,1,2,7
 2,1,1,96
 2,1,2,4
 2,1,3,2
 2,2,1,58
 
 There are three groups identified based on the combination of first and
 second columns. How do I split this data frame?
 
 I tried
 aa - split(inpfil, inpfil[,1:2])
 but it has problems.
 
 Output desired is
 
 aa[1]
 Houseid,Personid,Tripid,taz
 1,1,1,4
 1,1,2,7
 aa[2]
 Houseid,Personid,Tripid,taz
 2,1,1,96
 2,1,2,4
 2,1,3,2
 aa[3]
 Houseid,Personid,Tripid,taz
 2,2,1,58
 
  [[alternative HTML version deleted]]
 
 __
 R-help@ 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.
 
 
 
 Any of the following three works with me.
 
 
 DF - read.table(text=
 Houseid,Personid,Tripid,taz
 1,1,1,4
 1,1,2,7
 2,1,1,96
 2,1,2,4
 2,1,3,2
 2,2,1,58
 , header=TRUE, sep=,)
 
 DF
 
 split(DF, DF[, 1:2], drop=TRUE)
 split(DF, list(DF$Houseid, DF$Personid), drop=TRUE)
 with(DF, split(DF, list(Houseid, Personid), drop=TRUE))
 
 The argument 'drop' defaults to FALSE. Was that the problem?
 
 Hope this helps,
 
 Rui Barrada
 
   [[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] multivariate ordered probit regression---use standard bivariate normal distribution?

2012-04-04 Thread Trey Batey
Hello.

I have yet to receive a response to my previous post, so I may have
done a poor job asking the question. So, here is the general question:
how can I run a run a multivariate (more than one non-independent,
response variables) ordered probit regression model? I've had success
doing this in the univariate case using the vglm() function in the
VGAM package. For example:

unvar.prob-vglm(y~x,cumulative(link=probit,parallel=FALSE,r everse=TRUE))

This would fit a unrestricted cumulative probit model (or a
thresholds of change model) with the ordered response variable
treated as a latent trait modeled with a standard normal distribution.
What I'd like to do is include an additional, ordinal response
variable, so that the two (non-independent) response variables are
treated as latent traits and modeled with a standard bivariate normal
distribution.

The VGAM package includes the function binormal(), which seems like it
should be of some use here, but if so, I don't know where/how it fits
into the model. I've included the results of running the model with
the two response variables separately. Any suggestions are welcome.
Again, if it helps in your response, I've included a link to the data
below.  Thanks.

--Trey


Get the data (a *.csv file) here:
https://docs.google.com/open?id=0B5zZGW2utJN0TEctcW1oblFRcTJrNDVLOVBmRWRaQQ


unvar.prob1-vglm(pube3~age,data=refdata,cumulative(link=probit,parallel=FALSE,reverse=TRUE))
 unvar.prob1
Call:
vglm(formula = pube3 ~ age, family = cumulative(link = probit,
parallel = FALSE, reverse = TRUE), data = refdata)

Coefficients:
(Intercept):1 (Intercept):2 age:1 age:2
-1.65895567 -2.14755951 0.06688242 0.04055919

Degrees of Freedom: 1492 Total; 1488 Residual
Residual Deviance: 1188.909
Log-likelihood: -594.4543

##

unvar.prob2-vglm(auric4~age,data=refdata,cumulative(link=probit,parallel=FALSE,reverse=TRUE))
 unvar.prob2
Call:
vglm(formula = auric4 ~ age, family = cumulative(link = probit,
parallel = FALSE, reverse = TRUE), data = refdata)

Coefficients:
(Intercept):1 (Intercept):2 (Intercept):3 age:1 age:2
-2.07719235 -2.43422370 -2.99123098 0.07319632 0.05133132
age:3
0.03797696

Degrees of Freedom: 2238 Total; 2232 Residual
Residual Deviance: 1583.47
Log-likelihood: -791.7348


*
Trey Batey--Anthropology Instructor
Division of Social Sciences
Mt. Hood Community College
Gresham, OR 97030

__
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] Grouping and/or splitting

2012-04-04 Thread Ashish Agarwal
Thanks a ton!
It was weird because according to me ordering should have by default.
Anyways, your workaround along with Weidong's method are both good
solutions.
On Wed, Apr 4, 2012 at 12:10 PM, Berend Hasselman b...@xs4all.nl wrote:


 On 04-04-2012, at 07:15, Ashish Agarwal wrote:

  Yes. I was missing the DROP argument.
  But now the problem is splitting is causing some weird ordering of
 groups.

 Why weird?

  See below:
 
  DF - read.table(text=
  Houseid,Personid,Tripid,taz
  1,1,1,4
  1,1,2,7
  2,1,1,96
  2,1,2,4
  2,1,3,2
  2,2,1,58
  3,1,5,7
  , header=TRUE, sep=,)
  aa - split(DF, DF[, 1:2], drop=TRUE)
 
  Now the result is aa[3] should is (3,1) and not (2,2). Why? How can I
  preserve the ascending order?
 

 Try this

 aa[order(names(aa))]

 Berend

  aa[3]
  $`3.1`
   Houseid Personid Tripid taz
  7   31  5   7
  aa[4]
  $`2.2`
   Houseid Personid Tripid taz
  6   22  1  58


[[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] filling small gaps of N/A

2012-04-04 Thread Petr PIKAL
 
 Michael,
 
 First of all, thank you very much for your answer.
 I've read your 2 answers, but I'm not really sure that they corresponds 
to
 my problem of NAs.

You shall read answers more carefully

x-rnorm(20)
x[3:4]-NA
x[12:19]-NA
x
 [1] -0.30754528  0.07597988  NA  NA -0.50585319 
-1.60509616  0.31488672  2.16969731
 [9]  0.67755514 -1.83075111  0.72044482  NA  NA NA   NA   
NA
[17]  NA  NA  NA -0.96576934

library(zoo)

na.approx(x)
 [1] -0.30754528  0.07597988 -0.11796447 -0.31190883 -0.50585319 
-1.60509616  0.31488672  2.16969731
 [9]  0.67755514 -1.83075111  0.72044482  0.53308769  0.34573056 
0.15837343 -0.02898370 -0.21634083
[17] -0.40369795 -0.59105508 -0.77841221 -0.96576934
na.approx(x, maxgap=3)
 [1] -0.30754528  0.07597988 -0.11796447 -0.31190883 -0.50585319 
-1.60509616  0.31488672  2.16969731
 [9]  0.67755514 -1.83075111  0.72044482  NA  NA NA   NA   
NA
[17]  NA  NA  NA -0.96576934

Does exactly what you want as far as I understand what you described.

Regards
Petr


 I'll try to detail you a bit more.
 
 This problem concerns the second part of my program. In the first part, 
I've
 already created a timeseries object with the library (timeseries). I had 
to
 delete first all the wrong values in my data and replace it with NAs. 
 So my data contains already missing data (NAs), as I have cleaned it 
before.
 
 The thing is that sometimes I have small gaps of missing data (only 2 or 
3
 following) like in example 1 below:
 
 example 1:
 
 09/01/2008 12:00  1.93 
 09/01/2008 12:15  3.93 
 09/01/2008 12:30   NASo here you have a small gap with 
only
 2 NAs
 09/01/2008 12:45   NA 
 09/01/2008 13:00  4.93 
 09/01/2008 13:15  5.93
 
 But sometimes, always in the same file, I have big gaps, such as 10 or 
more
 NAs following each other like in example 2 below:
 
 example 2:
 
 09/01/2008 16:15  2.93
 09/01/2008 16:30  2.93
 09/01/2008 16:45  NA
 09/01/2008 17:00  NA
 09/01/2008 17:15  NA
 09/01/2008 17:30  NA
 09/01/2008 17:45  NA
 09/01/2008 18:00  NA  So here you have a big gap with more 
than 10
 NAs following each other
 09/01/2008 18:15  NA
 09/01/2008 18:30  NA
 09/01/2008 18:45  NA
 09/01/2008 19:00  NA
 09/01/2008 19:15  NA
 09/01/2008 19:30  NA
 09/01/2008 19:45  NA
 09/01/2008 20:00  NA
 09/01/2008 20:15  7.93
 09/01/2008 20:30  7.93
 
 So in the whole same file, I can have sometimes big gaps (2 or 3 NAs),
 sometimes big or very big gaps (10 or 100 NAs following).
 
 The aim of my problem is to apply the function: na.approx(x) of the 
library
 (zoo) to fill NAs ONLY for small gaps.
 
 If I just do: apply(na.approx(x)), it will fill all the NAs of my data 
(big
 gaps + small gaps). It's exactly what I DON'T WANT.
 
 My problem is to say to R:  you apply the function (na.approx) to fill 
NAs
 ONLY if you see 4 NAs maximum following each other (small gaps) (like
 example 1). If you see more than 4 NAs following each other (big gaps 
like
 in example 2), you keep these NAs and you DON'T fill this big gap.
 
 My question is: how can I say this to R? I don't know how to do it.
 Hope I've been understandable this time ^^
 Thanks a lot again for all your answers!
 
 
 
 --
 View this message in context: 
http://r.789695.n4.nabble.com/filling-small-
 gaps-of-N-A-tp4528184p4528907.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] Odp: identify time span in date vector

2012-04-04 Thread Petr PIKAL
Hi

Can you please be more specific? Based on this input, what do you want as 
a result?

 set.seed(111)
 dates = as.Date(sort(rnorm(10,3000,100)), origin = 2000-1-1)
 dates
 [1] 2007-08-01 2007-10-21 2007-12-08 2007-12-15 2008-01-29 
2008-02-14 2008-02-16 2008-03-01
 [9] 2008-04-02 2008-04-11


Regards
Petr

 
 Hello everyone,
 
 i try to identify the first element of a date vector, for which the 
 following condition holds: at least 3 more dates within the next 365 
days,
 but at least one of these must be between 3-12 month later.
 
 dates = as.Date(sort(rnorm(10,3000,100)), origin = 2000-1-1)
 
 Has anyone an idea how to do this economically? I'll need to apply this 
to
 a large dataset with date vectors of various lengths and I can think 
only 
 of quite difficult algorithms :(
 
 Any ideas would be appreciated,
 Felix
 
 
[[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] filling small gaps of N/A

2012-04-04 Thread jeff6868
Wow, thank you for all your answers.

You were completely right michael. Well, it's my fault. I didn't understood
your 2nd reply, when you were talking about arguments for larger gaps. I
thought it was for deleting big gaps too. I apologize.
It was too easy in fact. I also didn't noticed the argument maxgap of the
function. 
Finally, it works perfectly only with this:

require(zoo)

imputation - function(x){
met - na.approx(x, maxgap = 4)

return(met)
}

data - myts[,2:5]
myts[,2:5]-apply(data,2,imputation)

Sorry for my stupidity. I'll try to be more careful next time, for such
small problems (when I was thinking it would be a big one) ;).
Well, thank you very much michael and the other repliers, and thank you for
having spared a bit of your time for me!

--
View this message in context: 
http://r.789695.n4.nabble.com/filling-small-gaps-of-N-A-tp4528184p4531224.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] Trying to merge new data set to bottom of old data set. Both are zoo objects.

2012-04-04 Thread Ashish Agarwal
It is unclear what the problem is. Does following code solve your append
problem?

fmt = %m/%d/%Y %H:%M
fname - new.txt
#records = 2904
newfile - read.csv(fname, header = TRUE, sep = ,, skip=0,
colClasses = c(rep(character,2), rep(numeric, 16))
)
newfile.comb - cbind(newfile[2], newfile[3])
fname - old.txt
#records = 73768
oldfile - read.table(fname, header = FALSE, sep = \t, dec = .,
colClasses = c(character,numeric,NULL), skip = 0)
names(oldfile)[1] - names(newfile)[2]
names(oldfile)[2] - names(newfile)[3]
combo.file = rbind(oldfile,newfile.comb)
#records = 76672
edit(combo.file)
AA

On Wed, Apr 4, 2012 at 9:27 AM, knavero knav...@gmail.com wrote:

 Here is the data I'm working with:

 http://r.789695.n4.nabble.com/file/n4530888/new.txt new.txt

 http://r.789695.n4.nabble.com/file/n4530888/old.txt old.txt

 My code is here:

 http://pastebin.com/9jjs6Ahr

 I'm looking for away to simply attach the new.txt to the bottom of old.txt
 through R, else I'll just throw it in Excel to do some preprocessing. I've
 looked into using merge, cbind, concatenate, and rbind. However, I'm
 running
 into problems where the 2012 data keeps ending up on top before the 2010
 and
 2011 data or the function just adds more extra columns to the right side.
 Is
 there a simple method of doing this? Thanks.

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Trying-to-merge-new-data-set-to-bottom-of-old-data-set-Both-are-zoo-objects-tp4530888p4530888.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.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] [R-pkgs] New package IC2

2012-04-04 Thread PLAT didier
Dear all,

A new package 'IC2' is now available. IC2 computes some indices of inequality 
and concentration (SGini, Atkinson, GEI). For each index, it provides 
decomposition between subgroups. Plotting of Lorenz and concentration curves 
are also available. Sampling weights can be used.

Regards,

--
Didier Plat
Laboratoire d'Economie des Transports
(CNRS -ENTPE -Université Lumiere)
ENTPE-rue Maurice AUDIN-69518 VAULX-EN-VELIN CEDEX-FRANCE
didier.p...@entpe.fr
http://www.entpe.fr/
http://www.let.fr/


[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
__
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] identify time span in date vector

2012-04-04 Thread Fischer, Felix
Dear Petr,

thanks for taking your time. 

For this input, the first element should be selected since there are more than 
3 more dates within one year (basically, all other dates are within one year) 
and at least one of them is more than 3 month later.

In the meantime, I came up with some code (probably) doing what I want:

identify_first_date = function(dates)
{
within_one_year = as.matrix(dist(dates))  366  
### next dates in same year?
within_one_year[upper.tri(within_one_year, diag=TRUE)]=FALSE

within_one_month = as.matrix(dist(dates))  91  
### next dates within 90 days?
within_one_month[upper.tri(within_one_month, diag=TRUE)]=FALSE

dates[
which(
apply(within_one_year,2,sum)  apply(within_one_month,2,sum)   
### more dates in one year than in one month
apply(within_one_year,2,sum) =3
### more than 4 dates in one year
)[1]]
}

I guess, the code could be improved, though, it takes some time.

Best,
Felix


-Ursprüngliche Nachricht-
Von: Petr PIKAL [mailto:petr.pi...@precheza.cz] 
Gesendet: Mittwoch, 4. April 2012 09:47
An: Fischer, Felix
Cc: r-help@r-project.org
Betreff: Odp: [R] identify time span in date vector

Hi

Can you please be more specific? Based on this input, what do you want as a 
result?

 set.seed(111)
 dates = as.Date(sort(rnorm(10,3000,100)), origin = 2000-1-1) dates
 [1] 2007-08-01 2007-10-21 2007-12-08 2007-12-15 2008-01-29 
2008-02-14 2008-02-16 2008-03-01
 [9] 2008-04-02 2008-04-11


Regards
Petr

 
 Hello everyone,
 
 i try to identify the first element of a date vector, for which the 
 following condition holds: at least 3 more dates within the next 365
days,
 but at least one of these must be between 3-12 month later.
 
 dates = as.Date(sort(rnorm(10,3000,100)), origin = 2000-1-1)
 
 Has anyone an idea how to do this economically? I'll need to apply 
 this
to
 a large dataset with date vectors of various lengths and I can think
only 
 of quite difficult algorithms :(
 
 Any ideas would be appreciated,
 Felix
 
 
[[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] read.socket utils package : somthing is going wrong

2012-04-04 Thread msalese
Hi everyone,
I'd appreciate if someone could help me to understand what is happening.

I'm attempting to connect R to the broker platform using tcp on localhost
5333.
Just to learn how use make.socket, write.socket, ..functions  I wrote simple
code:

#prepare string command to subscribe ask and bid price on Italian stock
#this should be a push stream like:
#First stream: 
#outcome=OK|item=MI.EQCON.2552
#Update stream:
#MI.EQCON.1|21|10|22|11|23|12|24|5|20|19|7.5
#MI.EQCON.2552|||7.3
#..
#until the buffer is full.
msg2-'function=subscribe|item=MI.EQCON.1|schema=ask1;bid1'

#open socket connection
socketPointer-make.socket(host='localhost',port=5333,fail=TRUE,server=FALSE)

#send the command line
write.socket(socket=socketPointer,string=msg2)

#read data
read.socket(socket=socketPointer,maxlen=252,loop=FALSE)

#send command to unsuscribe
write.socket(socket=sockPointer,string=unsub)

#close socket
close.socket(sockPointer)

The code remain stick on read.socket function, so I decided to use debug
functionality:
This is the read.socket source:

debugging in: read.socket(socket = s.p, maxlen = 252, loop = FALSE)
debug: {
if (length(port - as.integer(socket$socket)) != 1L) 
stop(invalid 'socket' argument)
maxlen - as.integer(maxlen)
buffer - paste(rep.int(#, maxlen), collapse = )
repeat {
tmp - .C(Rsockread, port, buffer = buffer, len = maxlen, 
PACKAGE = base)
rval - substr(tmp$buffer, 1L, tmp$len)
if (nzchar(rval) || !loop) 
break
}
rval
}

everything works fine up to  .C(Rsockread, port, buffer = buffer, len =
maxlen, PACKAGE = base)
when execution arrive to the c function call R goes in a some kind a eternal
loop !

Thanks very much
Massimo Salese

--
View this message in context: 
http://r.789695.n4.nabble.com/read-socket-utils-package-somthing-is-going-wrong-tp4531374p4531374.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] identify time span in date vector

2012-04-04 Thread Fischer, Felix

Dear David, 

thanks for your suggestion. 

However, when applied to 

dates = as.Date(c(2001-1-1, 2001-1-3, 2001-1-12, 2001-1-13, 
2001-4-20))

it doesn't behave like i want... 

 which( dates[4:(length(dates))] -dates[1:(length(dates)-3)] 365 
   dates[3:(length(dates)-1)] -dates[1:(length(dates)-3)]  90)

integer(0)

The condition is true for the first element of the vector, there are 4 more 
dates within one year and one (2001-4-20) is more than 90 days away.

I came up with the following solution:


identify_first_date = function(dates)
{
within_one_year = as.matrix(dist(dates))  366  
### next dates in same year?
within_one_year[upper.tri(within_one_year, diag=TRUE)]=FALSE

within_one_month = as.matrix(dist(dates))  91  
### next dates within 90 days?
within_one_month[upper.tri(within_one_month, diag=TRUE)]=FALSE

dates[
which(
apply(within_one_year,2,sum)  apply(within_one_month,2,sum)   
### more dates in one year than in one month
apply(within_one_year,2,sum) =3
### more than 4 dates in one year
)[1]]
}

identify_first_date(dates)
[1] 2001-01-01

However, this takes some time (couple of minutes) with my dataset of 250 000 
date vectors.

Best, Felix

-Ursprüngliche Nachricht-
Von: David Winsemius [mailto:dwinsem...@comcast.net] 
Gesendet: Dienstag, 3. April 2012 19:08
An: Fischer, Felix
Cc: r-help@r-project.org
Betreff: Re: [R] identify time span in date vector


On Apr 3, 2012, at 9:35 AM, Fischer, Felix wrote:

 Hello everyone,

 i try to identify the first element of a date vector, for which the 
 following condition holds: at least 3 more dates within the next 365 
 days, but at least one of these must be between 3-12 month later.

 dates = as.Date(sort(rnorm(10,3000,100)), origin = 2000-1-1)

 Has anyone an idea how to do this economically? I'll need to apply 
 this to a large dataset with date vectors of various lengths and I can 
 think only of quite difficult algorithms :(


which( dates[4:(length(dates))] -dates[1:(length(dates)-3)] 365 
dates[3:(length(dates)-1)] -dates[1:(length(dates)-3)]  90)

[1] 2 3

 Any ideas would be appreciated,
 Felix


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

David Winsemius, MD
West Hartford, CT

__
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] Perspective Plot, and npreg

2012-04-04 Thread Duncan Murdoch

On 12-04-03 4:35 PM, dnewbold wrote:

Hi, Im doing a simple non parametric regression using two variables(ie
regressing one on the the other), how would I counstruct my persp plot for
it with there only be two variables in total, . Any help would be much
appreciated.



You can't.  persp() plots are 3 dimensional.

Duncan Murdoch

__
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 load functions from file

2012-04-04 Thread Rolf Turner

On 04/04/12 15:54, John Kohr wrote:

Hello,

I have several functions in an .R file. I try to load them with load() command 
but it seems is not working..

if .R is in /home/user/myfunctions.R

how can i load it? is there any other way?


Don't assume that you know what load means on the basis of
believing that you have an intuitive understanding of this term.
You haven't.

Read the help for load.  I.e. RTFM.  You will see that the function
load() could scarcely be *less* appropriate for what you are trying
to do.

As someone else had told, the function you need to use is source().

But how would you have found that out, without someone telling you?
Ah!  Now you're asking questions!

The simple answer is, damned if I know.  I just thrashed around for
a while with help.search() and RSiteSearch(), and looked through
 ``An Introduction to R'' on the r-project home page.  Nada.  If you
*know* the function is called source then you can find it.  If you
don't know  catch 22.

cheers,

Rolf Turner

__
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 load functions from file

2012-04-04 Thread Bert Gunter
Rolf:

Google on load functions into R.
A post referencing source() (from Henrik Bengtsson is the first hit.

-- Bert

On Wed, Apr 4, 2012 at 3:23 AM, Rolf Turner rolf.tur...@xtra.co.nz wrote:
 On 04/04/12 15:54, John Kohr wrote:

 Hello,

 I have several functions in an .R file. I try to load them with load()
 command but it seems is not working..

 if .R is in /home/user/myfunctions.R

 how can i load it? is there any other way?


 Don't assume that you know what load means on the basis of
 believing that you have an intuitive understanding of this term.
 You haven't.

 Read the help for load.  I.e. RTFM.  You will see that the function
 load() could scarcely be *less* appropriate for what you are trying
 to do.

 As someone else had told, the function you need to use is source().

 But how would you have found that out, without someone telling you?
 Ah!  Now you're asking questions!

 The simple answer is, damned if I know.  I just thrashed around for
 a while with help.search() and RSiteSearch(), and looked through
  ``An Introduction to R'' on the r-project home page.  Nada.  If you
 *know* the function is called source then you can find it.  If you
 don't know  catch 22.

    cheers,

        Rolf Turner

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] Constructing Distance matrix for hclust

2012-04-04 Thread Alekseiy Beloshitskiy
Hi, Vinod,

Hope this will help you:

library(RJDBC)
#specify your mysql driver
drv - JDBC(com.vertica.Driver, ../vertica_3.5_jdk_5.jar)
# specify your connection string
conn - dbConnect(drv, jdbc:postgres://IP:port/dbname, login, 
password)
#list tables
dbListTables(conn)
#get your distances
dist-dbGetQuery(conn, select * from ...);


Good luck,
-Alex

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of 
Vinod Hegde [vinod.hegd...@gmail.com]
Sent: 27 March 2012 16:30
To: r-help@r-project.org
Subject: [R] Constructing Distance matrix for hclust

Hi,

I have similarity value between string pairs in a mysql database.
I need to construct the distance matrix which hclust can take and cluster
the strings. Most of the examples I came across show how to construct the
distance matrix using dist function.

How can I code to construct distance matrix using the data in mysql db.

Thanks a lot for any help.

[[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] image.plot adding x-axis labels. Please Help

2012-04-04 Thread David Winsemius


On Apr 3, 2012, at 11:16 PM, David Lyon wrote:


Sorry that didnt work for me, any ideas?


You _could_ indicate which package the image.plot function comes from.  
You _could_ include dput on a sufficient segment of `data1` to offer a  
reproducible test case. You _could_ indicate in what fashion the  
axis() call didn't work. I used to look such matters up, add code  
and make guesses, but got tired of doing extra work that was really  
the responsibility of the questioner.


--
David



- Original Message -
From: ilai ke...@math.montana.edu
To: David Lyon david_ly...@yahoo.com
Cc: r-help@r-project.org r-help@r-project.org
Sent: Tuesday, April 3, 2012 10:43 PM
Subject: Re: [R] image.plot adding x-axis labels. Please Help

On Tue, Apr 3, 2012 at 7:25 PM, David Lyon david_ly...@yahoo.com  
wrote:

if I had a data file like this:
1.42 1.29 -0.13
1.46 1.34 -0.12
1.45 1.32 -0.13
1.36 1.26 -0.10
1.33 1.29 -0.04

I want to create a image plot like this:
data1-read.table(A)

image.plot(t(data1), axes=FALSE, xlab=NA, ylab=NA)

I cant get the labels for the x axis right can some kind person  
help me?


axis(1,at=seq(0,1,l=ncol(data1)),labels=LETTERS[1:ncol(data1)])



axis(1.???.labels=c(A, B, C))


Many thanks in advance!

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


David Winsemius, MD
West Hartford, CT

__
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] Package seems to be present but library don't find it

2012-04-04 Thread Duncan Murdoch

On 12-04-03 12:25 PM, Marc Girondot wrote:

Indeed I get this error message when I install the library using R CMD
INSTALL but not within the GUI (in MacOsX). Good to know that R CMD
INSTALL is more verbose and permits to track bug.


I followed up in R-sig-mac, and it turns out the reason you didn't get a 
message is that you didn't specify the package type, and the default is 
to assume you have a binary package.  A binary install just copies the 
files into place without looking at them.  If you had specified 
type=source in the install.packages() call, you would get the same 
error messages as I got.


Duncan Murdoch



Thanks a lot.

It works fine now.

Marc

Le 03/04/12 16:03, Duncan Murdoch a écrit :

On 03/04/2012 9:50 AM, Marc Girondot wrote:

In case someone has the competence to check, the file is here:

setwd(~)

download.file(http://www.ese.u-psud.fr/epc/conservation/r-scripts/HelloWorld_1.0.tar.gz;,

HelloWorld_1.0.tar.gz)

install.packages(HelloWorld_1.0.tar.gz, repos = NULL)



The problem is that you try to export the name HelloWorld in your
NAMESPACE file, but you don't have an object of that name.  You should
export showHello instead.

Not sure why you didn't see the error message I got:

$ R CMD INSTALL HelloWorld_1.0.tar.gz
* installing to library 'F:/cygwin/home/murdoch/R/win-library/2.15'
* installing *source* package 'HelloWorld' ...
** R
** preparing package for lazy loading
** help
Warning:
C:/temp/RtmpimSWuh/R.INSTALLe801c296e9/HelloWorld/man/HelloWorld-packag
e.Rd:32: All text must be in a section
Warning:
C:/temp/RtmpimSWuh/R.INSTALLe801c296e9/HelloWorld/man/HelloWorld-packag
e.Rd:33: All text must be in a section
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error in namespaceExport(ns, exports) : undefined exports: HelloWorld
Error: loading failed
Execution halted
ERROR: loading failed
* removing 'F:/cygwin/home/murdoch/R/win-library/2.15/HelloWorld'

Duncan Murdoch





__
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] identify time span in date vector

2012-04-04 Thread Petr PIKAL
Hi

 
 Dear Petr,
 
 thanks for taking your time. 
 
 For this input, the first element should be selected since there are 
more 
 than 3 more dates within one year (basically, all other dates are within 

 one year) and at least one of them is more than 3 month later.
 
 In the meantime, I came up with some code (probably) doing what I want:
 
 identify_first_date = function(dates)
 {
 within_one_year = as.matrix(dist(dates))  366  ### next 

 dates in same year?
 within_one_year[upper.tri(within_one_year, diag=TRUE)]=FALSE
 
 within_one_month = as.matrix(dist(dates))  91### next 
 dates within 90 days?
 within_one_month[upper.tri(within_one_month, diag=TRUE)]=FALSE
 
 dates[
which(
apply(within_one_year,2,sum)  apply(within_one_month,2,sum)  
 ### more dates in one year than in one month
apply(within_one_year,2,sum) =3   ### more than 4 
 dates in one year
)[1]]
 }
 
 I guess, the code could be improved, though, it takes some time.

Your first condition can be fulfilled by

c(as.numeric(diff(dates))365, F)  c(as.numeric(diff(dates))91,F))

so if you put in your function

identify_first_date2 = function(dates)
{
within_one_year = as.matrix(dist(dates))  366
within_one_year[upper.tri(within_one_year, diag=TRUE)]=FALSE

distance-as.numeric(diff(dates))

dates[ which( c(distance365, F)  c(distance91,F)  
apply(within_one_year,2,sum) =3)[1]]
}

You shall get some improvement, however I am still struggling to evaluate 
how many consecutive dates are within one year.




 
 Best,
 Felix
 
 
 -Ursprüngliche Nachricht-
 Von: Petr PIKAL [mailto:petr.pi...@precheza.cz] 
 Gesendet: Mittwoch, 4. April 2012 09:47
 An: Fischer, Felix
 Cc: r-help@r-project.org
 Betreff: Odp: [R] identify time span in date vector
 
 Hi
 
 Can you please be more specific? Based on this input, what do you want 
as a result?
 
  set.seed(111)
  dates = as.Date(sort(rnorm(10,3000,100)), origin = 2000-1-1) dates
  [1] 2007-08-01 2007-10-21 2007-12-08 2007-12-15 2008-01-29 
 2008-02-14 2008-02-16 2008-03-01
  [9] 2008-04-02 2008-04-11
 
 
 Regards
 Petr
 
  
  Hello everyone,
  
  i try to identify the first element of a date vector, for which the 
  following condition holds: at least 3 more dates within the next 365
 days,
  but at least one of these must be between 3-12 month later.
  
  dates = as.Date(sort(rnorm(10,3000,100)), origin = 2000-1-1)
  
  Has anyone an idea how to do this economically? I'll need to apply 
  this
 to
  a large dataset with date vectors of various lengths and I can think
 only 
  of quite difficult algorithms :(
  
  Any ideas would be appreciated,
  Felix
  
  
 [[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] logistic regression

2012-04-04 Thread David Winsemius


On Apr 3, 2012, at 9:25 PM, Melrose2012 wrote:

I am trying to plot the logistic regression of a dataset (# of  
living flies
vs days the flies are alive) and then fit a best-fit line to this  
data.


Here is my code:
plot(fflies$living~fflies$day,xlab=Number of Days,ylab=Number of  
Fruit

Flies,main=Number of Living Fruit Flies vs Day,pch=16)
alive - (fflies$living)
dead - (fflies$living[1]-alive)
glm.fit - glm(cbind(alive,dead)~fflies$day,family=binomial)
summary(glm.fit)
lines(sort(fflies$day),fitted(glm.fit) [order (fflies$day)],col =
red,lwd=2)
lines(glm.fit,col = red,lwd=2)

My problem is that, while I am pretty sure that I did the 'glm'  
command
correctly, when I try to plot this as a best-fit line on my data, it  
does

not fit (clearly on a different scale somehow).

Can anyone enlighten me about what I am doing wrong?  Should I be  
scaling
one of these somehow?  I've tried various types of scaling but  
nothing plots

the line on top of the plot (no matter which I scale).


The parameter estimate is on the log(odds) scale. Two problems: A)  
Your plot is not even on the odds scale, much less the log(odds)  
scale. B) Your model assumes that the log(odds) for an event will  
increase linearly with days. However your event == alive seems  
reversed from what I would have expected it to be. I would have  
expected dead within an interval to be the event that might increase  
in probability as time increased. I also speculated that the problem  
(which was not described at all) might better fit within the framework  
of survival analysis rather than logistic regression?


--
David.



Thanks so much for whatever help you can give me!

Cheers,
Melissa

--
View this message in context: 
http://r.789695.n4.nabble.com/logistic-regression-tp4530651p4530651.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.


David Winsemius, MD
West Hartford, CT

__
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] Calculating NOEL using R and logistic regression - Toxicology

2012-04-04 Thread Jarno Tuimala
Dear Danielle,

At least in industrial toxicology (my original background) the recent
tendency has been to use benchmark dose (BSD) approach instead of NOEL
or NOAEL approach due to various problems with the definition and
estimation of NO(A)EL. In R this can be achieved using the packages
drc and bmd as already mentioned by Drew Tyre.

Here's a short code example that gives you the BMD at 1% level:

library(drc)
library(bmd)
data(daphnids)
d24-daphnids[daphnids$time==24h,]
fit - drm(no/total~dose, weights = total, data = d24, fct = LL.2(),
type = binomial)
ED(fit, 1)
bmd(FIT, 0.01)

See the following documents for more information, if you're interested
in using BSD instead of NO(A)EL:

http://www.cdpr.ca.gov/docs/risk/bmdquant.pdf
http://www.efsa.europa.eu/en/efsajournal/doc/1150.pdf

Jarno

__
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] cluster analysis with pairwise data

2012-04-04 Thread paladini

Hello,
I want to do a cluster analysis with my data. The problem is, that the 
variables dont't consist of single value but the entries are pairs of 
values.

That lokks like this:


Variable 1:Variable2:  Variable3:  ...
(1,2)  (1,5)   (4,2)
(7,8)  (3,88)  (6,5)
(4,7)  (12,4)  (4,4)
.   .  .
.   .  .
.   .  .
Is it possible to perform a cluster-analysis with this kind of data in 
R ?
I dont even know how to get this data in a matrix or a dada-frame or 
anything like this.


It would be really nice if somebody could help me.

Best regards and happy Easter

Claudia

__
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] Calculating NOEL using R and logistic regression - Toxicology

2012-04-04 Thread Jarno Tuimala
Make that

bmd(fit, 0.01)

in my previous post.

Jarno

__
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] filling small gaps of N/A

2012-04-04 Thread R. Michael Weylandt
No problem -- best of luck with it: the zoo package is one of the best
documentation-wise and I'd advise you to look at the available
vignettes when you have time.

Vignettes are extended documentation included in some packages that
give a more systematic presentation than can be given in the help
pages. vignette() [no arguments] at the command line will bring up a
list of all the vignettes available on your computer: alternatively,
you can see them on CRAN here:
http://cran.r-project.org/web/packages/zoo/index.html

Best,
Michael

On Wed, Apr 4, 2012 at 4:20 AM, jeff6868
geoffrey_kl...@etu.u-bourgogne.fr wrote:
 Wow, thank you for all your answers.

 You were completely right michael. Well, it's my fault. I didn't understood
 your 2nd reply, when you were talking about arguments for larger gaps. I
 thought it was for deleting big gaps too. I apologize.
 It was too easy in fact. I also didn't noticed the argument maxgap of the
 function.
 Finally, it works perfectly only with this:

 require(zoo)

    imputation - function(x){
    met - na.approx(x, maxgap = 4)

    return(met)
    }

    data - myts[,2:5]
    myts[,2:5]-apply(data,2,imputation)

 Sorry for my stupidity. I'll try to be more careful next time, for such
 small problems (when I was thinking it would be a big one) ;).
 Well, thank you very much michael and the other repliers, and thank you for
 having spared a bit of your time for me!

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/filling-small-gaps-of-N-A-tp4528184p4531224.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] Trying to merge new data set to bottom of old data set. Both are zoo objects.

2012-04-04 Thread Gabor Grothendieck
On Wed, Apr 4, 2012 at 1:47 AM, knavero knav...@gmail.com wrote:
 Here's a case where it doesn't work. Again, the problem is that when I use
 the rbind or concatenate functions, the 2012 data set seems to go ahead of
 the 2010 and 2011 portions of the data set. The problem seems dependent on
 the text files I read in:

 http://r.789695.n4.nabble.com/file/n4531011/old.txt old.txt

 http://r.789695.n4.nabble.com/file/n4531011/new.txt new.txt

 using this code:

 http://pastebin.com/8W6KaaPQ

 In a case where it works, and the data seemed to be in the right order, I
 read in a different old.txt named old1.txt and somehow it seemed to work.
 The contents and format were similar to that of new.txt where there was 18
 columns with the same headers. Here are the files to use:

 http://r.789695.n4.nabble.com/file/n4531011/old1.txt old1.txt

 http://r.789695.n4.nabble.com/file/n4531011/new.txt new.txt

 using this code:

 http://pastebin.com/6iNF5bPd

 That should clarify the issue I'm having. Let me know if a dput is necessary
 here. However all the vectors and vector modes seem to check out okay.


The problem is that the dates in the new file are of the form 2/23/12
but they are being read in using %m/%d/%Y %H:%M .  The %Y should be
%y.  For the old file the format is correct.

A few other points:

- it would be better to use library() than require() here.  If there
is some problem and it can't load the package then library will fail
with an error right at that point -- this is what we want in order to
best reveal where the problem is but with require() it will simply
return FALSE and keep processing and then the error will be later in
the code which is not as convenient for figuring out what went wrong.
Alternately you can use stopifnot(require(...whatever...)).

- please try to cut your data down as far as feasible.  If each file
had 3 lines, say, the same error would have been revealed and it would
have been easier to manage.  Also it would have been possible to
remove all the columns not used and still illustrate this error.  The
very process of reducing it to the smallest dataset you can often
reveal the error.

- if you must post in this fashion then note that read.zoo uses
read.table which can read directly off the net:

new.txt - http://r.789695.n4.nabble.com/file/n4531011/new.txt;
new - read.zoo(new.txt, ...whatever...)

- its better to write out TRUE and FALSE since F and T can be ordinary
variables that a program can create but TRUE and FALSE are keywords so
they can't be overwritten.

- you may or may not prefer this style but it would be possible to replace this:

cls - c(NULL, NA, numeric,
  NULL, NULL,
  NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL, NULL, NULL)

with this:

cls - rep(c(NULL, NA, numeric, NULL), c(1, 1, 1, 15))

-- 
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] STAR Spatio Temporal AutoRegressive models

2012-04-04 Thread vasilis
Hi there,
do you know if there is a package that fits spatio temporal autoregressive
models in R?
thanks
vasilis

--
View this message in context: 
http://r.789695.n4.nabble.com/STAR-Spatio-Temporal-AutoRegressive-models-tp4531793p4531793.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] read.socket utils package : something is going wrong

2012-04-04 Thread msalese
Found solution.
I've changed the library and functions to open and read sockets.

Using base package I wrote:

msg3-function=subscribe|item=MI.EQCON.1|schema=last_price;ask;bid
msg4-function=unsubscribe
#open socket connection
socketPointer-socketConnection('localhost', port=5333, server=FALSE)
#subscribe
writeLines(msg3, socketPointer)
#read data from file
readLines(con=socketPointer,n=1,ok=TRUE,warn=TRUE,encoding='UTF-8')
#unsubscribe
writeLines(msg4, socketPointer)
#close socket
close(socketPointer)

Now it works fine.

--
View this message in context: 
http://r.789695.n4.nabble.com/read-socket-utils-package-something-is-going-wrong-tp4531374p4531764.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] identify time span in date vector

2012-04-04 Thread David Winsemius


On Apr 4, 2012, at 8:19 AM, Petr PIKAL wrote:


Hi



Dear Petr,

thanks for taking your time.

For this input, the first element should be selected since there are

more
than 3 more dates within one year (basically, all other dates are  
within



one year) and at least one of them is more than 3 month later.

In the meantime, I came up with some code (probably) doing what I  
want:


identify_first_date = function(dates)
{
within_one_year = as.matrix(dist(dates))  366  ###  
next



dates in same year?
within_one_year[upper.tri(within_one_year, diag=TRUE)]=FALSE

within_one_month = as.matrix(dist(dates))  91###  
next

dates within 90 days?
within_one_month[upper.tri(within_one_month, diag=TRUE)]=FALSE

dates[
  which(
  apply(within_one_year,2,sum)  apply(within_one_month,2,sum) 
### more dates in one year than in one month
  apply(within_one_year,2,sum) =3   ### more than 4
dates in one year
  )[1]]
}

I guess, the code could be improved, though, it takes some time.


Your first condition can be fulfilled by

c(as.numeric(diff(dates))365, F)  c(as.numeric(diff(dates))91,F))

so if you put in your function

identify_first_date2 = function(dates)
{
within_one_year = as.matrix(dist(dates))  366
within_one_year[upper.tri(within_one_year, diag=TRUE)]=FALSE

distance-as.numeric(diff(dates))

dates[ which( c(distance365, F)  c(distance91,F) 
apply(within_one_year,2,sum) =3)[1]]
}

You shall get some improvement, however I am still struggling to  
evaluate

how many consecutive dates are within one year.



I added a couple of dates to the test case on which my original  
erroneous sugegstion failed:


 dput(dates)
structure(c(11323, 11325, 11334, 11335, 11432, 11688, 12418), class =  
Date)


This returns a list of intervals or perhaps stretches (?) spanning  
less than 365 days to assemble candidates for the first criterion:


intervals1 - lapply(1:(length(dates)-4) , function(x)   
dates[which(dates - dates[x]  365  dates - dates[x] =0)] )

 intervals1
[[1]]
[1] 2001-01-01 2001-01-03 2001-01-12 2001-01-13 2001-04-20

[[2]]
[1] 2001-01-03 2001-01-12 2001-01-13 2001-04-20 2002-01-01

[[3]]
[1] 2001-01-12 2001-01-13 2001-04-20 2002-01-01


This then test whether the second to last element (the penultimate  
one in correct use of that often misused term) is at least 90 days out:


 sapply(intervals1, function(x) x[length(x)-1] - x[1] = 90)
[1] FALSE  TRUE  TRUE
 intervals1[which( sapply(intervals1, function(x) x[length(x)-1] -  
x[1] 90)) ]

[[1]]
[1] 2001-01-03 2001-01-12 2001-01-13 2001-04-20 2002-01-01

[[2]]
[1] 2001-01-12 2001-01-13 2001-04-20 2002-01-01


And this returns the starting date from that result:

 intervals1[which( sapply(intervals1, function(x) x[length(x)-1] -  
x[1] 90)) ][[1]][1]

[1] 2001-01-03

I see that I should have added a test for length greater than 3 but  
that should not be difficult.


 intervals1[which( sapply(intervals1,
   function(x) x[length(x)-1] - x[1] 90  length(x) 3)) ][[1]][1]
[1] 2001-01-03


--
David.







Best,
Felix


-Ursprüngliche Nachricht-
Von: Petr PIKAL [mailto:petr.pi...@precheza.cz]
Gesendet: Mittwoch, 4. April 2012 09:47
An: Fischer, Felix
Cc: r-help@r-project.org
Betreff: Odp: [R] identify time span in date vector

Hi

Can you please be more specific? Based on this input, what do you  
want

as a result?



set.seed(111)
dates = as.Date(sort(rnorm(10,3000,100)), origin = 2000-1-1) dates

[1] 2007-08-01 2007-10-21 2007-12-08 2007-12-15 2008-01-29
2008-02-14 2008-02-16 2008-03-01
[9] 2008-04-02 2008-04-11




Regards
Petr



Hello everyone,

i try to identify the first element of a date vector, for which the
following condition holds: at least 3 more dates within the next 365

days,

but at least one of these must be between 3-12 month later.

dates = as.Date(sort(rnorm(10,3000,100)), origin = 2000-1-1)

Has anyone an idea how to do this economically? I'll need to apply
this

to

a large dataset with date vectors of various lengths and I can think

only

of quite difficult algorithms :(

Any ideas would be appreciated,
Felix


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


David Winsemius, MD
West Hartford, CT

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

[R] npRmpi trouble - mpi.comm.spawn causes segfault

2012-04-04 Thread Peter Man

Dear all,

I have a large dataset of randomly generated weighed sample for which I 
wish to compute a kernel density estimate.
I have used the np package successfully for smaller datasets, however 
for the larger ones, they take too long when
using the cross validation options for bandwidth selection (cv.ls or 
cv.ml). Of course, they are much quicker with normal-reference.


To speed things up, I tried to use the npRmpi package. I had a lot of 
trouble installing it - but after appealing to google and finding the 
following page:


http://webappl.blogspot.co.uk/2012/01/install-rmpi-with-mpich2-environment.html

npRmpi was finally installed (basically I just added the flags -lmpl 
-lopa to the definition of PKG_LIBS in the configure script, and in the 
R CMD INSTALL call, I passed the configure.args as the correct paths to 
my MPICH2 installation).


However, when I call the mpi.spawn.Rslaves(nslaves=1) command, I get 
the following errors:


##
 mpi.spawn.Rslaves(nslaves=1)

 *** caught segfault ***
address 0x2df0c9f, cause 'memory not mapped'

Traceback:
 1: .Call(mpi_comm_spawn, as.character(slave), 
as.character(slavearg), as.integer(nslaves), as.integer(info), 
as.integer(root), as.integer(intercomm), PACKAGE = npRmpi)
 2: mpi.comm.spawn(slave = system.file(Rslaves.sh, package = 
npRmpi), slavearg = arg, nslaves = nslaves, info = 0, root = 
root, intercomm = intercomm)

 3: mpi.spawn.Rslaves(nslaves = 1)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
##

I also installed Rmpi (I installed Rmpi before npRmpi, and in a similar 
fashion), and calling the same function mpi.spawn.Rslaves gives the 
following error:


[mpiexec@manet.somewhere.group] match_arg 
(/home/userspace/plwm2/CPP/mpich2-1.4.1p1_gcc4.6.2/src/pm/hydra/utils/args/args.c:122): 
unrecognized argument pmi_args
[mpiexec@manet.somewhere.group] HYDU_parse_array 
(/home/userspace/plwm2/CPP/mpich2-1.4.1p1_gcc4.6.2/src/pm/hydra/utils/args/args.c:140): 
argument matching returned error
[mpiexec@manet.somewhere.group] parse_args 
(/home/userspace/plwm2/CPP/mpich2-1.4.1p1_gcc4.6.2/src/pm/hydra/ui/mpich/utils.c:1387): 
error parsing input array
[mpiexec@manet.somewhere.group] HYD_uii_mpx_get_parameters 
(/home/userspace/plwm2/CPP/mpich2-1.4.1p1_gcc4.6.2/src/pm/hydra/ui/mpich/utils.c:1438): 
unable to parse user arguments



Please help!!!

Thanks.

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] spaghetti plots in R

2012-04-04 Thread uday
I would like to plat some spaghetti plots from my data , ma data is as
follows 
ak[1:3,]
  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7] 
[,8]  [,9]
[1,] 0.3211745 0.4132568 0.5649930 0.6920562 0.7760113 0.8118568 0.8609301
0.9088819 0.9326736
[2,] 0.3159234 0.4071270 0.5579212 0.6844584 0.7684690 0.8243702 0.8677043
0.8931288 0.9261926
[3,] 0.3075260 0.3993699 0.5493242 0.6765600 0.7614591 0.8127050 0.8537816
0.8884786 0.9343690
 [,10] [,11][,12]
[1,] 0.9605178 1 1.003940
[2,] 0.9647617 1 1.012930
[3,] 0.9618874 1 1.007103
dim(ak[1:3,])
[1]  3 12

pre[1:3,]
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[,9][,10]
[1,] 10.34615 52.02116 146.1736 243.2864 347.4150 431.6711 521.4271 629.0045
729.9594 827.8628
[2,] 10.34615 52.02539 146.3670 244.3871 350.1785 454.6706 546.5499 638.3344
741.9849 842.5700
[3,] 10.34615 52.02754 146.4656 244.9480 351.5865 457.1768 550.1341 643.0880
748.1114 850.0670
[,11][,12]
[1,] 921.5508 956.4445
[2,] 953.9648 995.8201
[3,] 951.6384 987.9105

dim(pre) 3 12 

I have tried 
plot(ak[1,],pre[1,],type=l)
lines(ak[2,],pre[2,],type=l,col=red)
but it only works for few data, but I have very big list and data is in
matrix format. I would be very glad if someone can help me to fix this
issue. 


--
View this message in context: 
http://r.789695.n4.nabble.com/spaghetti-plots-in-R-tp4532021p4532021.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] spaghetti plots in R

2012-04-04 Thread Liviu Andronic
On Wed, Apr 4, 2012 at 4:22 PM, uday uday_143...@hotmail.com wrote:
 I would like to plat some spaghetti plots from my data , ma data is as

See:
require(sos)
findFn('spaghetti')


Liviu


 follows
 ak[1:3,]
          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
 [,8]      [,9]
 [1,] 0.3211745 0.4132568 0.5649930 0.6920562 0.7760113 0.8118568 0.8609301
 0.9088819 0.9326736
 [2,] 0.3159234 0.4071270 0.5579212 0.6844584 0.7684690 0.8243702 0.8677043
 0.8931288 0.9261926
 [3,] 0.3075260 0.3993699 0.5493242 0.6765600 0.7614591 0.8127050 0.8537816
 0.8884786 0.9343690
         [,10] [,11]    [,12]
 [1,] 0.9605178     1 1.003940
 [2,] 0.9647617     1 1.012930
 [3,] 0.9618874     1 1.007103
 dim(ak[1:3,])
 [1]  3 12

 pre[1:3,]
         [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]     [,8]
 [,9]    [,10]
 [1,] 10.34615 52.02116 146.1736 243.2864 347.4150 431.6711 521.4271 629.0045
 729.9594 827.8628
 [2,] 10.34615 52.02539 146.3670 244.3871 350.1785 454.6706 546.5499 638.3344
 741.9849 842.5700
 [3,] 10.34615 52.02754 146.4656 244.9480 351.5865 457.1768 550.1341 643.0880
 748.1114 850.0670
        [,11]    [,12]
 [1,] 921.5508 956.4445
 [2,] 953.9648 995.8201
 [3,] 951.6384 987.9105

 dim(pre) 3 12

 I have tried
 plot(ak[1,],pre[1,],type=l)
 lines(ak[2,],pre[2,],type=l,col=red)
 but it only works for few data, but I have very big list and data is in
 matrix format. I would be very glad if someone can help me to fix this
 issue.


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/spaghetti-plots-in-R-tp4532021p4532021.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.



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
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] convert a list to a data frame

2012-04-04 Thread Sam Steingold
I have a huge list (returned by fromJSON) with elements like this:

$`zz/3260`
$`zz/3260`$name
[1] myname

$`zz/3260`$status
[1] active

$`zz/3260`$vectors
$`zz/3260`$vectors$`vector/241`
$`zz/3260`$vectors$`vector/241`$channel
[1] channel/300

$`zz/3260`$vectors$`vector/241`$targets
$`zz/3260`$vectors$`vector/241`$targets[[1]]
$`zz/3260`$vectors$`vector/241`$targets[[1]]$range_start
[1] 0

$`zz/3260`$vectors$`vector/241`$targets[[1]]$range_end
[1] 99

I want a data frame with these column values for the above list element:
zz=3260, name=myname, status=active, vector=241, channel=300
range_start=0, range_end=99

(and sometimes $vectors is an empty list, yuk!)

my plan is to
1 extract a list of fields
2 convert it to a vector (which I know how to put into a data frame)

how do I do that?
I can get zz/3260 with names() and split it with gsub().
I can get myname with as.vector(unlist(sapply(a,[,1

is there a shortcut?

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://truepeace.org http://mideasttruth.com
http://memri.org http://honestreporting.com http://jihadwatch.org
If you try to fail, and succeed, which have you done?

__
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] plot with a regression line(s)

2012-04-04 Thread Sam Steingold
I am sure a common need is to plot a scatterplot with some fitted
line(s) and maybe save to a file.
I have this:

plot.glm - function (x, y, file = NULL, xlab = deparse(substitute(x)),
  ylab = deparse(substitute(y)), main = NULL) {
  m - glm(y ~ x)
  if (!is.null(file))
pdf(file = file)
  plot(x, y, xlab = xlab, ylab = ylab, main = main)
  lines(x, y = m$fitted.values, col = green)
  if (!is.null(file))
dev.off()
  print(m)
}

is there a better/easier/more general way?

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://truepeace.org http://openvotingconsortium.org
http://jihadwatch.org http://iris.org.il http://honestreporting.com
Even Windows doesn't suck, when you use Common Lisp

__
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] convert a list to a data frame

2012-04-04 Thread Bert Gunter
Please first search yourself before posting.

Google on R convert list to data frame.

-- Bert

On Wed, Apr 4, 2012 at 8:11 AM, Sam Steingold s...@gnu.org wrote:
 I have a huge list (returned by fromJSON) with elements like this:

 $`zz/3260`
 $`zz/3260`$name
 [1] myname

 $`zz/3260`$status
 [1] active

 $`zz/3260`$vectors
 $`zz/3260`$vectors$`vector/241`
 $`zz/3260`$vectors$`vector/241`$channel
 [1] channel/300

 $`zz/3260`$vectors$`vector/241`$targets
 $`zz/3260`$vectors$`vector/241`$targets[[1]]
 $`zz/3260`$vectors$`vector/241`$targets[[1]]$range_start
 [1] 0

 $`zz/3260`$vectors$`vector/241`$targets[[1]]$range_end
 [1] 99

 I want a data frame with these column values for the above list element:
 zz=3260, name=myname, status=active, vector=241, channel=300
 range_start=0, range_end=99

 (and sometimes $vectors is an empty list, yuk!)

 my plan is to
 1 extract a list of fields
 2 convert it to a vector (which I know how to put into a data frame)

 how do I do that?
 I can get zz/3260 with names() and split it with gsub().
 I can get myname with as.vector(unlist(sapply(a,[,1

 is there a shortcut?

 --
 Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 
 11.0.11004000
 http://www.childpsy.net/ http://truepeace.org http://mideasttruth.com
 http://memri.org http://honestreporting.com http://jihadwatch.org
 If you try to fail, and succeed, which have you done?

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] plot with a regression line(s)

2012-04-04 Thread R. Michael Weylandt michael.weyla...@gmail.com
I'm not sure what your definition of easier would be, but there are some style 
things you might want to be aware of:

I) the name is likely to hit up against the S3 generic plot() when applied to a 
glm object. This might lead to strange bugs at some point. 
II) you can test !is.null once and use on.exit() to delay the clean-up call to 
dev.off()
III) I'm not sure about glm objects but abline() applied to an lm object 
automatically plots a best fit line saving you a line or so of code. 
IV) You probably don't want to print() m at the end: the REPL will print it 
automatically in interactive top level calls and it will be rather noisy if you 
start wrapping this in other calls. 

Hope this helps,
Michael

On Apr 4, 2012, at 11:13 AM, Sam Steingold s...@gnu.org wrote:

 I am sure a common need is to plot a scatterplot with some fitted
 line(s) and maybe save to a file.
 I have this:
 
 plot.glm - function (x, y, file = NULL, xlab = deparse(substitute(x)),
  ylab = deparse(substitute(y)), main = NULL) {
  m - glm(y ~ x)
  if (!is.null(file))
pdf(file = file)
  plot(x, y, xlab = xlab, ylab = ylab, main = main)
  lines(x, y = m$fitted.values, col = green)
  if (!is.null(file))
dev.off()
  print(m)
 }
 
 is there a better/easier/more general way?
 
 -- 
 Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 
 11.0.11004000
 http://www.childpsy.net/ http://truepeace.org http://openvotingconsortium.org
 http://jihadwatch.org http://iris.org.il http://honestreporting.com
 Even Windows doesn't suck, when you use Common Lisp
 
 __
 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] Trying to understand factors

2012-04-04 Thread MacQueen, Don
I'd like to make the distinction between the purpose of factors, i.e.,
what they are intended for, and how that purpose is accomplished.

Their purpose is for use in statistical models. The simplest example is
analysis of variance, where predictors are commonly referred to as
factors. Factors in R are intended to be used as factors in statistical
models. Similarly, in the anova literature, the different values of the
predictor are often referred to as levels.

So R creates factors by grouping the array categories into levels, as you
described. Underlying the levels are numeric codes that the modeling
functions use. Try  as.numeric(statef) and compare with as.numeric(state)

Because of this, I personally don't make anything into a factor unless I
intend to use it in a model. Or, occasionally, because of a useful side
effect. For example:

(the following needs to be viewed using a monospaced font)


 set.seed(21)

 mns - sample(month.abb,100,replace=TRUE)
 table(mns)
mns
Apr Aug Dec Feb Jan Jul Jun Mar May Nov Oct Sep
  3  12  18   8   8  14   2   9   4   6   8   8


## same:
 mnsf1 - factor(mns)
 table(mnsf1)
mnsf1
Apr Aug Dec Feb Jan Jul Jun Mar May Nov Oct Sep
  3  12  18   8   8  14   2   9   4   6   8   8


## now the months are in the correct order
 mnsf2 - factor(mns, levels=month.abb)
 table(mnsf2)
mnsf2
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
  8   8   9   3   4   2  14  12   8   8   6  18

Compare
   sort(mnsf1)

   sort(mnsf2)and compare how the underlying numeric codes are assigned
to the categories.




So, I know this wasn't about your main question, but I hope you find it
useful anyway.

-Don


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 3/30/12 9:50 AM, Julio Sergio julioser...@gmail.com wrote:


I'm trying to figure out about factors, however the on-line documentation
is 
rather sparse. I guess, factors are intended for grouping arrays members
into 
categories, which R names Levels. And so we have:

 * state - c(tas, sa,  qld, nsw, nsw, nt,  wa,  wa,
  qld, vic, nsw, vic, qld, qld, sa,  tas,
  sa,  nt,  wa,  vic, qld, nsw, nsw, wa,
  sa,  act, nsw, vic, vic, act)
 * statef - factor(state)
 * statef
 [1] tas sa  qld nsw nsw nt  wa  wa  qld vic nsw vic qld qld sa  tas sa
nt  wa 
 [20] vic qld nsw nsw wa  sa  act nsw vic vic act
 Levels: act nsw nt qld sa tas vic wa

With this, just visually, I know what the cateogries or Levels are.
Nonetheless, 
two questions arise here: How can I have, computationally as opposed to
visually, access to the names of these categories, and how do I get the
indexes 
of the original array elements that belong to a particular category, say,
act?
This is, for instance, to select from another parallel array, the
corresponding elements, say


 * incomes - c(60, 49, 40, 61, 64, 60, 59, 54, 62, 69, 70, 42, 56,
61, 61, 61, 58, 51, 48, 65, 49, 49, 41, 48, 52, 46,
59, 46, 58, 43)

So to select, the corresponding elements to act:

  46 43


Do you have any comments on this?

Thanks,

--Sergio.

__
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] plot with a regression line(s)

2012-04-04 Thread David Winsemius


On Apr 4, 2012, at 11:30 AM, R. Michael Weylandt michael.weyla...@gmail.com 
 wrote:


I'm not sure what your definition of easier would be, but there are  
some style things you might want to be aware of:


I) the name is likely to hit up against the S3 generic plot() when  
applied to a glm object. This might lead to strange bugs at some  
point.
II) you can test !is.null once and use on.exit() to delay the clean- 
up call to dev.off()
III) I'm not sure about glm objects but abline() applied to an lm  
object automatically plots a best fit line saving you a line or so  
of code.


If you offer a regression object to abline's 'reg' parameter and that  
object has a coef() method you might get a result. But if the link  
function of the regression is not matched to the plot's scale (as  
might happen with a logistic or poisson fit) then results may not be  
as expected. Most people will probably want to use `predict(reg- 
object, newdata= , type = response)` with .


IV) You probably don't want to print() m at the end: the REPL will  
print it automatically in interactive top level calls and it will be  
rather noisy if you start wrapping this in other calls.


Hope this helps,
Michael

On Apr 4, 2012, at 11:13 AM, Sam Steingold s...@gnu.org wrote:


I am sure a common need is to plot a scatterplot with some fitted
line(s) and maybe save to a file.
I have this:

plot.glm - function (x, y, file = NULL, xlab =  
deparse(substitute(x)),

ylab = deparse(substitute(y)), main = NULL) {
m - glm(y ~ x)
if (!is.null(file))
  pdf(file = file)
plot(x, y, xlab = xlab, ylab = ylab, main = main)
lines(x, y = m$fitted.values, col = green)
if (!is.null(file))
  dev.off()
print(m)
}

is there a better/easier/more general way?

--






David Winsemius, MD
West Hartford, CT

__
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] spaghetti plots in R

2012-04-04 Thread uday
Hi Liviu ,
thanks for post , but I could not find findFn('spaghetti') , I can see the
following functions in sos package 
Extract.findFn
findFn  
 grepFn
hits 
 installPackages 
PackageSum2
 PackageSummary
 print.findFn 
 sortFindFn
summary.findFn
 unionFindFn
 writeFindFn2xls


--
View this message in context: 
http://r.789695.n4.nabble.com/spaghetti-plots-in-R-tp4532021p4532171.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] spaghetti plots in R

2012-04-04 Thread Liviu Andronic
On Wed, Apr 4, 2012 at 5:04 PM, uday uday_143...@hotmail.com wrote:
 Hi Liviu ,
 thanks for post , but I could not find findFn('spaghetti') , I can see the
 following functions in sos package
 Extract.findFn
 findFn

After installing 'sos', use the 'findFn()' function. For example, run
findFn('spaghetti')

See the documentation of ?findFn. Alternatively, look into RcmdrPlugin.sos.

Regards
Liviu

__
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] cluster analysis with pairwise data

2012-04-04 Thread David L Carlson
You can create distance matrices for each Variable, square them, sum them,
and take the square root. As for getting the data into a data frame, the
simplest would be to enter the three variables into six columns like the
following:

data
 [,1] [,2] [,3] [,4] [,5] [,6]
[1,]121542
[2,]783   8865
[3,]47   12444

Then use dist() on each pair of columns:

1:2, 3:4, 5:6 . . .

e.g. for the 3 rows of data you provided

size - nrow(data)*(nrow(data)-1)/2
dm - dist(rep(0, size))
for(i in seq(1, 6, 2)) {
  dm - dm + dist(data[,i:(i+1)])^2
}
dm - sqrt(dm)
dm

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of paladini
Sent: Wednesday, April 04, 2012 6:32 AM
To: r-help@r-project.org
Subject: [R] cluster analysis with pairwise data

Hello,
I want to do a cluster analysis with my data. The problem is, that the 
variables dont't consist of single value but the entries are pairs of 
values.
That lokks like this:


Variable 1:Variable2:  Variable3:  ...
(1,2)  (1,5)   (4,2)
(7,8)  (3,88)  (6,5)
(4,7)  (12,4)  (4,4)
.   .  .
.   .  .
.   .  .
Is it possible to perform a cluster-analysis with this kind of data in 
R ?
I dont even know how to get this data in a matrix or a dada-frame or 
anything like this.

It would be really nice if somebody could help me.

Best regards and happy Easter

Claudia

__
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] Filling empty List in a FOR LOOP

2012-04-04 Thread MacQueen, Don
Try

  A[[1]] - NA

(It is of course up to you to do the tests, presumably using if(), to
decide when to assign NA to the list element.)

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 3/31/12 7:53 PM, michaelyb cel81009...@gmail.com wrote:

Hello all,

I am trying to automate a list to be filled in a FOR LOOP.
Basically I need to load info from a third source and store it into a
list.
This list goes to object A; The next list brought in by the LOOP goe to
object B.. os on ans so forth.

When the iteration on the LOOP goes well (which means it isn't empty) I
get
something like this:

A   
[[1]]
  [,1]   
 [1,] 1130
 [2,] 1132
 [3,] 1134
 [4,] 1136
 [5,] 1138
 [6,] 1140
 [7,] 1142
 
[[2]]
  [,1]  
 [1,] 7.54
 [2,] 6.55
 [3,] 4.20
 [4,] 3.50
 [5,] 2.92
 [6,] 2.42
 [7,] 1.99

However when the source is empty I get the following:

A
[[1]]
 [,1]

[[2]]
 [,1]

I need to store NA in the latter one. I have tried A[is.na(A)] but I get
an
error message. 
Any help would be greatly appreciated.

Thank you in advance

--
View this message in context:
http://r.789695.n4.nabble.com/Filling-empty-List-in-a-FOR-LOOP-tp4522694p4
522694.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] A contour plot question - vis.gam () function in mgcv

2012-04-04 Thread ilai
On Tue, Apr 3, 2012 at 6:22 PM, Peter Ehlers ehl...@ucalgary.ca wrote:
 On 2012-04-03 15:49, ilai wrote:

 Try to plot the points first followed by vis.gam(...,type='contour',
 color='bw', add=T) instead of vis.gam followed by points.

 HTH


 Or, if vis.gam gives you default scales that you wish to preserve,
 then just replot the contours over the points with

   vis.gam(., add = TRUE)

 Peter Ehlers

I would say no. This works as a quick and dirty but as a general rule,
in my view replot should be discouraged because of the reduced print
quality of the visible elements from the original. Maybe a minor
issue, but annoying to give a presentation and realize labels in the
plot are all fuzzy when projected on the big screen (never happened to
me of course, I'm talking about a friend...:). To preserve the scales
in this case would be better to explicit set limits
plot(...,pch=19,xlim,ylim) ; vis.gam(., add = TRUE)
rather than
vis.gam()
points()
vis.gam()

Cheers



 On Tue, Apr 3, 2012 at 2:48 PM, Ravi Varadhanrvarad...@jhmi.edu  wrote:

 Hi,

 Please see the attached contour plot (I am sorry about the big file).
  This was created using the vis.gam() function in mgcv package.  However,
 my question is somewhat broader.

 In generating this figure, I first created the contours using vis.gam()
 and then I plotted the points.  These point are plotted on top of the
 contours so that some of the contour lines are only partially visible.  Is
 there a way to make the contour lines fully visible?  I cannot reverse the
 order and plot the points first and then call vis.gam().  Or, can I?  Are
 there other options?

 Thanks for any help or hints.

 Best,
 Ravi


 Ravi Varadhan, Ph.D.
 Assistant Professor
 The Center on Aging and Health
 Division of Geriatric Medicine  Gerontology

 Johns Hopkins University
 rvarad...@jhmi.edumailto:rvarad...@jhmi.edu
 410-502-2619


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


Re: [R] cluster analysis with pairwise data

2012-04-04 Thread Petr Savicky
On Wed, Apr 04, 2012 at 01:32:10PM +0200, paladini wrote:
 Hello,
 I want to do a cluster analysis with my data. The problem is, that the 
 variables dont't consist of single value but the entries are pairs of 
 values.
 That lokks like this:
 
 
 Variable 1:Variable2:  Variable3:  ...
 (1,2)  (1,5)   (4,2)
 (7,8)  (3,88)  (6,5)
 (4,7)  (12,4)  (4,4)
 .   .  .
 .   .  .
 .   .  .
 Is it possible to perform a cluster-analysis with this kind of data in 
 R ?
 I dont even know how to get this data in a matrix or a dada-frame or 
 anything like this.

Hi.

The data as they are may be read into R as character data. The
exact way depends on the format of the data in the file. The
result may look like the following.

  Var1 - c((1,2), (7,8), (4,7))
  Var2 - c((1,5), (3,88), (12,4))
  Var3 - c((4,2), (6,5), (4,4))
  DF - data.frame(Var1, Var2, Var3, stringsAsFactors=FALSE)

If you want to use a distance between pairs depending on the
numbers (and not only equal/different pair), then the data should
to be transformed to a numeric format. For example, as follows

  trans - function(x)
  {
  y - strsplit(gsub([()], , x), ,)
  unname(t(vapply(y, FUN=as.numeric, FUN.VALUE=c(0, 0
  }

  DF - data.frame(Var1=trans(Var1), Var2=trans(Var2), Var2=trans(Var3))
  DF

Var1.1 Var1.2 Var2.1 Var2.2 Var2.1.1 Var2.2.1
  1  1  2  1  542
  2  7  8  3 8865
  3  4  7 12  444

Then, see library(help=cluster).

Hope this helps.

Petr Savicky.

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


Re: [R] Looking for the name of a certain kind of quantile plot

2012-04-04 Thread cberry
Carl Witthoft c...@witthoft.com writes:

 Hi,
 While playing with quantile-quantile plots, I wrote up some code which
 plots something strangely different.  Here's the pseudocode:

 testhist - hist(sample_data)
 refhist - hist(rnorm(n, mean=0,sd=1))  # for some large-ish n
 cumtest - cumsum(testhist)
 cumref - cumsum(refhist)

 plot(cumref,cumtest)


Sounds like a 'pp-plot'. See

  http://en.wikipedia.org/wiki/P-P_plot

Why not provide reproducible code?

Chuck


 This produces a straight line of slope 1 for a sample with the same
 parameters as the reference sample, and produces S-curves for samples
 with different sigmas.  A sample with nonzero mean looks almost
 exponential (or logarithmic, depending on the sign of the mean).

 So my question is: is there a name for this sort of plot,  and is it
 of any real use in statistical analysis?

 thanks.
 Carl

-- 
Charles C. BerryDept of Family/Preventive Medicine
cberry at ucsd edu  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
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] markov regime switching models

2012-04-04 Thread Marie Morel

Dear Sir,
I saw a question from a member in 2007 asking for regime switching model 
and I am looking for the same kind of model.
I also saw a project named RSNL but I don't know if this one is 
available and if we can have access to the code to change things if 
needed... actually I used to build my own models and not ask somebody 
but this one is relatively easy but long to implement so I wanted to 
skip this phase :-)

I thus wanted to know if this model was available for download ?
Thanks for your answer
Mary

__
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] image.plot adding x-axis labels. Please Help

2012-04-04 Thread ilai
On Wed, Apr 4, 2012 at 6:05 AM, David Winsemius dwinsem...@comcast.net wrote:

 On Apr 3, 2012, at 11:16 PM, David Lyon wrote:

 Sorry that didnt work for me, any ideas?


 You _could_ indicate which package the image.plot function comes from. You
 _could_ include dput on a sufficient segment of `data1` to offer a
 reproducible test case. You _could_ indicate in what fashion the axis() call
 didn't work. I used to look such matters up, add code and make guesses,
 but got tired of doing extra work that was really the responsibility of the
 questioner.

 --
 David

Thank you David, you're absolutely right. The critical point here is
par settings of fields::image.plot not the axis(1,at=?...) as could be
understood from the original partial question.

I forgot to cc the list on my private communications with the OP.
Future googlers, the same solution can be achieved with

A- matrix(1:50,nr=10)
par(mar=c(5.1,2.1,4.1,4.1))
image(t(A),axes=F,col='transparent')
axis(1,at=seq(0,1,l=ncol(A)),labels=LETTERS[1:ncol(A)])
require(fields)
image.plot(t(A),add=T,legend.mar=3.1)


Cheers




 - Original Message -
 From: ilai ke...@math.montana.edu
 To: David Lyon david_ly...@yahoo.com
 Cc: r-help@r-project.org r-help@r-project.org
 Sent: Tuesday, April 3, 2012 10:43 PM
 Subject: Re: [R] image.plot adding x-axis labels. Please Help

 On Tue, Apr 3, 2012 at 7:25 PM, David Lyon david_ly...@yahoo.com wrote:

 if I had a data file like this:
 1.42 1.29 -0.13
 1.46 1.34 -0.12
 1.45 1.32 -0.13
 1.36 1.26 -0.10
 1.33 1.29 -0.04

 I want to create a image plot like this:
 data1-read.table(A)

 image.plot(t(data1), axes=FALSE, xlab=NA, ylab=NA)

 I cant get the labels for the x axis right can some kind person help me?


 axis(1,at=seq(0,1,l=ncol(data1)),labels=LETTERS[1:ncol(data1)])


 axis(1.???.labels=c(A, B, C))


 Many thanks in advance!

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


 David Winsemius, MD
 West Hartford, CT


__
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] simulate correlated binary, categorical and continuous variable

2012-04-04 Thread Greg Snow
How are you calculating the correlations?  That may be part of the
problem, when you categorize a continuous variable you get a factor
whose internal representation is a set of integers.  If you try to get
a correlation with that variable it will not be the polychoric
correlation.

Also do you need your data to have the exact proportions and means
that you show below? or represent random samples from those
populations and therefore the actual proportions and means will vary a
bit from what is specified?

If you are interested in tetrachoric and polychoric correlations, then
generating the latent normals and categorizing seems the most
straightforward method.

Also, which function (from which package) are you using to generate
your normal variables?  That may have some effect.

On Sun, Apr 1, 2012 at 7:00 PM, Burak Aydin burak235...@hotmail.com wrote:
 Hello Greg,
 Sorry for the confusion.
 Lets say, I have a population.  I have 6 variables. They are correlated to
 each other. I can get you pearson correlation, tetrachoric or polychoric
 correlation coefficients.
 2 of them continuous, 2 binary, 2 categorical.
 Lets assume following conditions;
 Co1 and Co2 are normally distributed continuous random variables. Co1-- N
 (0,1), Co2--N(100,15)
 Ca1 and Ca2 are categorical variables. Ca1 probabilities
 =c(.02,.18,.28,.22,.30), Ca2 probs =c(.06,.18,.76)
 Bi1 and Bi2 are binaries, Marginal probabilities Bi1 p= 0.4,  Bi2 p=0.5.
 And , again, I have the correlations.

 When I try to simulate this population I fail. If I keep the means and
 probabilities same I lost the correct correlations. When I keep
 correlations, I loose precision on means and frequencies/probabilities.
 See these links please
 http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/copulademo.html
 http://stats.stackexchange.com/questions/22856/how-to-generate-correlated-test-data-that-has-bernoulli-categorical-and-contin
 http://www.springerlink.com/content/011x633m554u843g/



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/simulate-correlated-binary-categorical-and-continuous-variable-tp4516433p4524863.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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@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] convert a list to a data frame

2012-04-04 Thread Sam Steingold
sorry, google does give a good start.

 Google on R convert list to data frame.

 as.data.frame(do.call(rbind,a))

returns an object which I don't understand.
 summary(f)
 name.Length  name.Class  name.Modestatus 
 1  -none- characterLength:4445   
 1  -none- characterClass :character  
 1  -none- characterMode  :character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 1  -none- character  
 vectors.Length  vectors.Class  vectors.Mode
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 0   -none-  list   
 [ reached getOption(max.print) -- omitted 4412 rows ]]

this is not a data frame I am used to.

why do f$v and f$ve return the same as f$vectors?!




-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://camera.org http://openvotingconsortium.org
http://dhimmi.com http://iris.org.il http://thereligionofpeace.com
There are two ways to write error-free programs; only the third one works.

__
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] cluster analysis with pairwise data

2012-04-04 Thread ilai
On Wed, Apr 4, 2012 at 10:12 AM, Petr Savicky savi...@cs.cas.cz wrote:
 On Wed, Apr 04, 2012 at 01:32:10PM +0200, paladini wrote:

  Var1 - c((1,2), (7,8), (4,7))
  Var2 - c((1,5), (3,88), (12,4))
  Var3 - c((4,2), (6,5), (4,4))
  DF - data.frame(Var1, Var2, Var3, stringsAsFactors=FALSE)

 If you want to use a distance between pairs depending on the
 numbers (and not only equal/different pair), then the data should
 to be transformed to a numeric format.

Or if the pairs have unique meaning ?daisy , also in the cluster
package, comes in handy (in this case you'll want to keep Vi as
factors in the call to DF).

Cheers

For example, as follows

  trans - function(x)
  {
      y - strsplit(gsub([()], , x), ,)
      unname(t(vapply(y, FUN=as.numeric, FUN.VALUE=c(0, 0
  }

  DF - data.frame(Var1=trans(Var1), Var2=trans(Var2), Var2=trans(Var3))
  DF

    Var1.1 Var1.2 Var2.1 Var2.2 Var2.1.1 Var2.2.1
  1      1      2      1      5        4        2
  2      7      8      3     88        6        5
  3      4      7     12      4        4        4

 Then, see library(help=cluster).

 Hope this helps.

 Petr Savicky.

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

__
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] convert a list to a data frame

2012-04-04 Thread Bert Gunter
??? What is a?

?str

str(a)

?do.call


On Wed, Apr 4, 2012 at 9:34 AM, Sam Steingold s...@gnu.org wrote:
 sorry, google does give a good start.

 Google on R convert list to data frame.

  as.data.frame(do.call(rbind,a))

 returns an object which I don't understand.
 summary(f)
  name.Length  name.Class  name.Mode    status
  1          -none-     character    Length:4445
  1          -none-     character    Class :character
  1          -none-     character    Mode  :character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  1          -none-     character
  vectors.Length  vectors.Class  vectors.Mode
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  0       -none-  list
  [ reached getOption(max.print) -- omitted 4412 rows ]]

 this is not a data frame I am used to.

 why do f$v and f$ve return the same as f$vectors?!




 --
 Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 
 11.0.11004000
 http://www.childpsy.net/ http://camera.org http://openvotingconsortium.org
 http://dhimmi.com http://iris.org.il http://thereligionofpeace.com
 There are two ways to write error-free programs; only the third one works.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

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


Re: [R] unable to move temporary installation

2012-04-04 Thread Uwe Ligges



On 03.04.2012 19:43, Drew Tyre wrote:

A final followup. I have identified a rather extreme workaround. The
problem arises when the function utils:::unpackPkgZip uses file.rename(...)
to move the unzipped binary package from the temporary directory that it
was unpacked into into the proper directory in the library tree. If one does
debug(utils:::unpackPkgZip)
and then steps through the function line by line, it works.


Then check your virus scanner ot the speed of IO if this is a remote 
file system.


Uwe Ligges




Thank you.

On Mon, Apr 2, 2012 at 12:06 PM, Drew Tyreaty...@unl.edu  wrote:


OK - so I followed the following steps, which I think rule out those causes

1) I uninstalled all remaining versions of R, and then deleted all the
directories in c:\progra~1\R
2) I restarted the computer
3) I installed 2.14.2, and attempted to install the Rcmdr package. Same
error message for both the cars package and the Rcmdr package.
4) I then exited and confirmed that I have write permission to
C:\progra~1\R\R-2.14.2\libraries both by looking at the permissions, and by
creating a directory in there. I appear to have full control, and I could
create the directory. note that R is able to create the temporary directory
to install the package, but not the correct, final directory.
5) I then uninstalled 2.14.2, and installed 2.15.0, hoping for a fix. No
luck. Same error message.
6) I then tried installing the packages to a different directory, one that
I created, c:\test, using
install.packages(Rcmdr,c:\\test)
This time, the car package installed correctly, but Rcmdr still had the
same warning message

Warning: unable to move temporary installation
‘c:\test\file136c67c337b3\Rcmdr’ to ‘c:\test\Rcmdr’

There is clearly something messed up on this computer, but I'm at a loss
for how to get around it. Thanks for the suggestions, and I guess I have to
work on a different computer!

2012/3/31 Uwe Liggeslig...@statistik.tu-dortmund.de


On 31.03.2012 16:15, Drew Tyre wrote:


Hi all,

I'm having a strange error that prevents me from installing new

packages,

or updating packages after reinstalling. The error message is
Warning: unable to move temporary installation ‘C:\Program
Files\R\R-2.14.2\library\**file15045004ac2\sandwich’ to ‘C:\Program
Files\R\R-2.14.2\library\**sandwich’
for one of the packages that is failing to install/update. This error
started happening after I attempted installing lme4Eigen from the

R-Forge

repositories - that installation failed too.

Any suggestions for fixes welcome. I don't want to upgrade to 2.15 just
yet
because I'm in the middle of a project (although if that's the solution

I

guess I'll have to do it).



Probably the package is in use by another instance of R. Otherwise, check
permissions.

Best,
Uwe Ligges


  R version 2.14.2 (2012-02-29)

Platform: i386-pc-mingw32/i386 (32-bit)

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

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

loaded via a namespace (and not attached):
[1] tools_2.14.2





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

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.






--
Drew Tyre

School of Natural Resources
University of Nebraska-Lincoln
416 Hardin Hall, East Campus
3310 Holdrege Street
Lincoln, NE 68583-0974

phone: +1 402 472 4054
fax: +1 402 472 2946
email: aty...@unl.edu
http://snr.unl.edu/tyre
http://aminpractice.blogspot.com
http://www.flickr.com/photos/atiretoo

 [[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] Fisher's LSD multiple comparisons in a two-way ANOVA

2012-04-04 Thread Jinsong Zhao

On 2012-04-03 20:03, Rmh wrote:

yes.  See ?glht in the multcomp package, and the examples using glht in ?MMC in 
the HH package.

Sent from my iPhone



Thank you very much for the clues. However, I can't figure out how to 
construct the linfct in glht.


I also tried to inverse the computation based on:
http://www.gigawiz.com/images12/twowayrmposthoc.jpg
However, I can't catch the MSE used in the above figure.

Regards,
Jinsong

__
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] unable to move temporary installation

2012-04-04 Thread Henrik Bengtsson
My $.01 contribution without having read the complete thread:

Some other process/service is locking your file/directory.  There are
a few Windows tools out there helping your to narrow down exactly
which, e.g.

  http://www.guidingtech.com/10175/tools-to-delete-locked-files-in-windows/

/Henrik


On Wed, Apr 4, 2012 at 10:07 AM, Uwe Ligges
lig...@statistik.tu-dortmund.de wrote:


 On 03.04.2012 19:43, Drew Tyre wrote:

 A final followup. I have identified a rather extreme workaround. The
 problem arises when the function utils:::unpackPkgZip uses
 file.rename(...)
 to move the unzipped binary package from the temporary directory that it
 was unpacked into into the proper directory in the library tree. If one
 does
 debug(utils:::unpackPkgZip)
 and then steps through the function line by line, it works.


 Then check your virus scanner ot the speed of IO if this is a remote file
 system.

 Uwe Ligges




 Thank you.

 On Mon, Apr 2, 2012 at 12:06 PM, Drew Tyreaty...@unl.edu  wrote:

 OK - so I followed the following steps, which I think rule out those
 causes

 1) I uninstalled all remaining versions of R, and then deleted all the
 directories in c:\progra~1\R
 2) I restarted the computer
 3) I installed 2.14.2, and attempted to install the Rcmdr package. Same
 error message for both the cars package and the Rcmdr package.
 4) I then exited and confirmed that I have write permission to
 C:\progra~1\R\R-2.14.2\libraries both by looking at the permissions, and
 by
 creating a directory in there. I appear to have full control, and I could
 create the directory. note that R is able to create the temporary
 directory
 to install the package, but not the correct, final directory.
 5) I then uninstalled 2.14.2, and installed 2.15.0, hoping for a fix. No
 luck. Same error message.
 6) I then tried installing the packages to a different directory, one
 that
 I created, c:\test, using
 install.packages(Rcmdr,c:\\test)
 This time, the car package installed correctly, but Rcmdr still had the
 same warning message

 Warning: unable to move temporary installation
 ‘c:\test\file136c67c337b3\Rcmdr’ to ‘c:\test\Rcmdr’

 There is clearly something messed up on this computer, but I'm at a loss
 for how to get around it. Thanks for the suggestions, and I guess I have
 to
 work on a different computer!

 2012/3/31 Uwe Liggeslig...@statistik.tu-dortmund.de

 On 31.03.2012 16:15, Drew Tyre wrote:

 Hi all,

 I'm having a strange error that prevents me from installing new

 packages,

 or updating packages after reinstalling. The error message is
 Warning: unable to move temporary installation ‘C:\Program
 Files\R\R-2.14.2\library\**file15045004ac2\sandwich’ to ‘C:\Program
 Files\R\R-2.14.2\library\**sandwich’
 for one of the packages that is failing to install/update. This error
 started happening after I attempted installing lme4Eigen from the

 R-Forge

 repositories - that installation failed too.

 Any suggestions for fixes welcome. I don't want to upgrade to 2.15 just
 yet
 because I'm in the middle of a project (although if that's the solution

 I

 guess I'll have to do it).


 Probably the package is in use by another instance of R. Otherwise,
 check
 permissions.

 Best,
 Uwe Ligges


  R version 2.14.2 (2012-02-29)

 Platform: i386-pc-mingw32/i386 (32-bit)

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

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

 loaded via a namespace (and not attached):
 [1] tools_2.14.2





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

 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.




 --
 Drew Tyre

 School of Natural Resources
 University of Nebraska-Lincoln
 416 Hardin Hall, East Campus
 3310 Holdrege Street
 Lincoln, NE 68583-0974

 phone: +1 402 472 4054
 fax: +1 402 472 2946
 email: aty...@unl.edu
 http://snr.unl.edu/tyre
 http://aminpractice.blogspot.com
 http://www.flickr.com/photos/atiretoo

         [[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] BRugs crash, question

2012-04-04 Thread Jack Tanner
Bob O'Hara rni.boh at gmail.com writes:

 
 On 4 April 2012 05:35, Jack Tanner ihok at hotmail.com wrote:
 
  samplesBgr(beta) # crash
  samplesBgr(beta, plot=FALSE) # also crash
 
  Have you plotted your histories? I haven't used samplesBgr() much, so I
 don't know how stable it is (although I do know it's slow).

Yes, plotting histories, densities works fine. Above, beta was an array of
parameters; plotBgr of a singleton parameter also crashes.

 samplesStats() calls internal OpenBUGS functions (not R functions), so
 that would mean saving the whole BUGS run (like externalise in OpenBUGS
 itself. From you code fit$Stats should give you the same as
 sampleStats('*'): if you want more use BRugsFit(..., coda=T) and work with
 the coda object it produces (check the documentation for BRugsFit and coda).

I thought about that, but that's not good either. fit$Stats doesn't have
parameter names attached. Is there a way to figure out where in
fit$Stats[,mean], say, beta ends and theta begins? They seem to be in
arbitrary order, as below.

The downside to BrugsFit(..., coda=TRUE) is that you don't get DIC (even if you
also pass DIC=TRUE).

 str(fit)
List of 3
 $ Stats:'data.frame':  194 obs. of  8 variables:
  ..$ mean : num [1:194] 0.536 0.552 0.037 0.33 0.327 ...
  ..$ sd   : num [1:194] 0.4505 0.214 0.1398 0.0789 0.3183 ...
  ..$ MC_error : num [1:194] 0.02775 0.011 0.00696 0.00346 0.02071 ...
  ..$ val2.5pc : num [1:194] -0.341 0.16 -0.215 0.179 -0.291 ...
  ..$ median   : num [1:194] 0.5238 0.5409 0.0331 0.3279 0.3227 ...
  ..$ val97.5pc: num [1:194] 1.429 1.043 0.327 0.488 0.974 ...
  ..$ start: int [1:194] 1001 1001 1001 1001 1001 1001 1001 1001 1001 1001 
...
  ..$ sample   : int [1:194] 750 750 750 750 750 750 750 750 750 750 ...
 $ DIC  :'data.frame':  3 obs. of  4 variables:
  ..$ Dbar: num [1:3] 8.94 1661 1670
  ..$ Dhat: num [1:3] 17.2 1556 1573
  ..$ DIC : num [1:3] 0.686 1766 1767
  ..$ pD  : num [1:3] -8.26 105.3 97.01

__
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] Print std. Error separately from mle-class object

2012-04-04 Thread Aziz, Muhammad Fayez
Hi,

I am using power.law.fit to get an mle-class object in tmp and print 
summary(tmp), coef(tmp) and logLik(tmp). I wanted to print the std. error for 
alpha separately as I want to show these values concisely in a graph legend. 
coef(summary(tmp)) displays the alpha and std. error jointly, while I need to 
print them separately on two lines.

Regards,
Fayez
__
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] crosstabs and histograms with flexible binning of dates

2012-04-04 Thread davideps
Hi,

First, thank you to Duncan Mackay for getting me started processing dates
with R. Unfortunately, I need to do a little more than I initially expected.
I have 5K lines of data that look like this:

ID AREA   DATE
0001   Center 2010-10-15
0002   Center 2010-01-02
0003   NorthWest  2010-02-05
0004   SouthWest  2010-05-11

I would like to create a script to create crosstabs like the one below, but
that (1) could be used to easily create small multiples with lattice or
ggplot2 and (2) provides flexible binning options, such as monthly from a
specific day. Should I manually create the crosstab or can I use a histogram
function to generate it on the way to generating a graphic? 

AREA 1/2010-3/2010 4/2010-6/20107/2010-9/2010   10/2010-12/2010
Center 1 0   0   1
NorthWest  1 0   0   0
SouthWest  0 1   0   0

Below is my code to handle the arbitrary bins, but I'm guessing there are
useful libraries and more elegant approaches. Any pointers would be
appreciated.

import(foreign)

# LOAD FILE 
#parcels=read.dbf()  #depending on source file
parcels=read.delim(~/Projects/GIS_DATA/Parcels_NSP_BlockGroup.txt)
attach(parcels)

# DEFINE BINNING
basedate=as.Date(2011/05/11)
currentdate=basedate
interval=3 #width of interval in months. 3 = quarterly
num_intervals=5 #how many intervals to include after basedate

for (i in c(1:num_intervals)) {
  startdate=currentdate
  enddate=seq(startdate,by=month,length=interval)[interval]  #create a
sequence of months of length interval and take last one.
  # crosstab construction of single column here
  # add column to final dataframe
  currentdate=enddate
  }


Thank you,
-david

__
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] spaghetti plots in R

2012-04-04 Thread uday
Hi Liviu ,
now I can see that function but the problem is that its only applicable for
single data frame. as I wrote in my first post that I got 2 different matrix
with same dimensions ( 3x 12 here in example) , so if I plot normal plot
using plot function 
plot(ak[1,],pre[1,],type=l)
lines(ak[2,],pre[2,],type=l,col=red)

but every files contains more than 1000 observations. 
Is it possible to use this function for two different matrix data ?

if yes then please let me know how to do it .


Thanks 
Uday 

--
View this message in context: 
http://r.789695.n4.nabble.com/spaghetti-plots-in-R-tp4532021p4532452.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] Trying to merge new data set to bottom of old data set. Both are zoo objects.

2012-04-04 Thread knavero
Okay, will do. Thanks for all the handy advice Gabor. Ugh, it's such a stupid
bug once I actually know what is going on. I need to go over my Unix
date/time format specifiers, and I'll probably use the rep function to
simplify and reducing the amount of code. A lot of that is definitely new to
me. As for shortening the read in data, I do it find it tricky sometimes
since you have to incrementally test it in the sense that you want to
shorten it to the point that it still reproduces the problem. Anyway, I'll
try to make the data significantly shorter in my next post if possible.
Thanks again.

--
View this message in context: 
http://r.789695.n4.nabble.com/Trying-to-merge-new-data-set-to-bottom-of-old-data-set-Both-are-zoo-objects-tp4530888p4532484.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] spaghetti plots in R

2012-04-04 Thread Rui Barradas
Hello,


uday wrote
 
 Hi Liviu ,
 now I can see that function but the problem is that its only applicable
 for single data frame. as I wrote in my first post that I got 2 different
 matrix with same dimensions ( 3x 12 here in example) , so if I plot normal
 plot using plot function 
 plot(ak[1,],pre[1,],type=l)
 lines(ak[2,],pre[2,],type=l,col=red)
 
 but every files contains more than 1000 observations. 
 Is it possible to use this function for two different matrix data ?
 
 if yes then please let me know how to do it .
 
 
 Thanks 
 Uday
 


Why not ?matplot  - Plot the columns of one matrix against the columns of
another. 



ak - as.matrix(read.table(text=
0.3211745 0.4132568 0.5649930 0.6920562 0.7760113 0.8118568 0.8609301
0.9088819 0.9326736 0.9605178 1 1.003940
0.3159234 0.4071270 0.5579212 0.6844584 0.7684690 0.8243702 0.8677043
0.8931288 0.9261926 0.9647617 1 1.012930
0.3075260 0.3993699 0.5493242 0.6765600 0.7614591 0.8127050 0.8537816
0.8884786 0.9343690 0.9618874 1 1.007103
))

ak

pre - as.matrix(read.table(text=
10.34615 52.02116 146.1736 243.2864 347.4150 431.6711 521.4271 629.0045
729.9594 827.8628 921.5508 956.4445
10.34615 52.02539 146.3670 244.3871 350.1785 454.6706 546.5499 638.3344
741.9849 842.5700 953.9648 995.8201
10.34615 52.02754 146.4656 244.9480 351.5865 457.1768 550.1341 643.0880
748.1114 850.0670 951.6384 987.9105
))


matplot(t(ak), t(pre), type=l)

Note that t() was needed.

Hope this helps,

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/spaghetti-plots-in-R-tp4532021p4532706.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] using metafor for meta-analysis of before-after studies

2012-04-04 Thread MP . Sylvestre
Greetings,
I wish to conduct a meta-analysis for which the outcome is a continuous  
variable measured on the same individuals before and after an intervention.  
Hence, the comparison is not made between two groups, but within groups, at  
diffrent times.

Each study reports the mean outcome and SD before the intervention and the  
mean outcome and SD after the intervention. While p-values for paired  
t-test (or similar methods for paired data) are reported in the studies, no  
estimate of the variability of the individual differences are available.

Can metafor deal with this sort of meta-analysis? I know that I can  
technically run metafor on these data, assuming that the groups are  
independent but my inference is likely to be wrong. On the other hand, I  
have no idea of the correlation within individuals.

Thanks in advance,
MP

[[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] spaghetti plots in R

2012-04-04 Thread R. Michael Weylandt
Can't you just combine your matrices into a single matrix: rbind() or
cbind() should do the job.

Michael

On Wed, Apr 4, 2012 at 12:24 PM, uday uday_143...@hotmail.com wrote:
 Hi Liviu ,
 now I can see that function but the problem is that its only applicable for
 single data frame. as I wrote in my first post that I got 2 different matrix
 with same dimensions ( 3x 12 here in example) , so if I plot normal plot
 using plot function
 plot(ak[1,],pre[1,],type=l)
 lines(ak[2,],pre[2,],type=l,col=red)

 but every files contains more than 1000 observations.
 Is it possible to use this function for two different matrix data ?

 if yes then please let me know how to do it .


 Thanks
 Uday

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/spaghetti-plots-in-R-tp4532021p4532452.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] Question about randomForest

2012-04-04 Thread Liaw, Andy
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Saruman
 
 I dont see how this answered the original question of the poster.
 
 He was quite clear: the value of the predictions coming out 
 of RF do not
 match what comes out of the predict function using the same 
 RF object and
 the same data. Therefore, what is predict() doing that is 
 different from RF?
 Yes, RF is making its predictions using OOB, but nowhere does 
 it say way
 predict() is doing; indeed, it says if newdata is not given, then the
 results are just the OOB predictions. But newdata=oldata, then
 predict(newdata) != OOB predictions. So what is it then? 

Let me make this as clear as I possibly can:  If predict() is called without 
newdata, all it can do is assume prediction on the training set is desired.  In 
that case it returns the OOB prediction.  If newdata is given in predict(), it 
assumes it is new data and thus makes prediction using all trees.  If you 
just feed the training data as newdata, then yes, you will get overfitted 
predictions.  It almost never make sense (to me anyway) to make predictions on 
the training set.
 
 Opens another issue, which is if newdata is close but not 
 exactly oldata,
 then you get overfitted results?

Possibly, depending on how close the new data are to the training set.  This 
applies to nearly _ALL_ methods, not just RF.

Andy
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Question-about-randomForest-tp41
11311p4529770.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.
 
Notice:  This e-mail message, together with any attachme...{{dropped:11}}

__
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] plot with a regression line(s)

2012-04-04 Thread S Ellison
 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Sam Steingold

 plot.glm - function (x, y, file = NULL, xlab = 
 deparse(substitute(x)),
   ylab = deparse(substitute(y)), main = NULL) {
   m - glm(y ~ x)
   if (!is.null(file))
 pdf(file = file)
   plot(x, y, xlab = xlab, ylab = ylab, main = main)
   lines(x, y = m$fitted.values, col = green)
   if (!is.null(file))
 dev.off()
   print(m)
 }
 
 is there a better/easier/more general way?


There is no guarantee that x is sorted in ascending order for a glm (or any 
other model), so lines(x, fitted()) can give very spiny results. Even if 
sorted, non-linear fits with large gaps in x will not give smooth lines.

Better to use something along the lines of the budworm example in the glm help 
page, which uses predict() on a new sequence.
If you want something a bit more general, you can use either range(x) to get 
the new sequence limits or  par(usr)[1:2]  to gets the current plot x limits.


S Ellison
***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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 NOEL using R and logistic regression - Toxicology

2012-04-04 Thread Danielle Duncan
Thanks everyone for the advice, you raise interesting points. Maybe the
best thing for me to do is do an ANOVA in R with binomial data (if
possible) and find the lowest dose that gives a significant difference from
the controls.

On Mon, Apr 2, 2012 at 2:45 PM, Danielle Duncan dldunc...@alaska.eduwrote:

 Hello, I used the glm function in R to fit a dose-response relationship
 and then have been using dose.p to calculate the LC50, however I would like
 to calculate the NOEL (no observed effect level), ie the lowest dose above
 which responses start occurring. Does anyone know how to do this?




-- 
Wilderness isn’t the wide open spaces. It’s the wild things in it”

[[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] convert a list to a data frame

2012-04-04 Thread Sam Steingold
Thanks for your reply!

1. the strings I replaced with  and  are very long; I wish I
could replace them in the object all, not just in text

2. `all` is the result of
  as.data.frame(do.call(rbind,l),stringsAsFactors = FALSE)

3. I get my data frame as

  fr - data.frame(audience = 
as.numeric(gsub(ZZZ/,'',row.names(all))),
   name = as.vector(unlist(all$name)),
   status = gsub(Y/,'',all$status),
   stringsAsFactors = FALSE)

 str(all)
'data.frame':   4454 obs. of  3 variables:
 $ name   :List of 4454
  ..$ ZZZ/1   : chr 0
  ..$ ZZZ/2   : chr 1
  ..$ ZZZ/3   : chr 2
  ..$ ZZZ/4   : chr 3
  ..$ ZZZ/5   : chr 4
  ..$ ZZZ/6   : chr 5
  ..$ ZZZ/7   : chr 6
  ..$ ZZZ/8   : chr 7
  ..$ ZZZ/9   : chr 8
  ..$ ZZZ/10  : chr 9
  ..$ ZZZ/11  : chr 10
  ..$ ZZZ/12  : chr 11
  ..$ ZZZ/13  : chr 12
  ..$ ZZZ/14  : chr 13
  ..$ ZZZ/15  : chr 14
  ..$ ZZZ/16  : chr 15
  ..$ ZZZ/17  : chr 16
  ..$ ZZZ/18  : chr 17
  ..$ ZZZ/19  : chr 18
  ..$ ZZZ/20  : chr 19
  ..$ ZZZ/21  : chr 20
  ..$ ZZZ/22  : chr 21
  ..$ ZZZ/23  : chr 22
  ..$ ZZZ/24  : chr 23
  ..$ ZZZ/25  : chr 24
  ..$ ZZZ/26  : chr 25
  ..$ ZZZ/27  : chr 26
  ..$ ZZZ/28  : chr 27
  ..$ ZZZ/29  : chr 28
  ..$ ZZZ/30  : chr 29
  ..$ ZZZ/31  : chr 30
  ..$ ZZZ/32  : chr 31
  ..$ ZZZ/33  : chr 32
  ..$ ZZZ/34  : chr 33
  ..$ ZZZ/35  : chr 34
  ..$ ZZZ/36  : chr 35
  ..$ ZZZ/37  : chr 36
  ..$ ZZZ/38  : chr 37
  ..$ ZZZ/39  : chr 38
  ..$ ZZZ/40  : chr 39
  ..$ ZZZ/41  : chr 40
  ..$ ZZZ/42  : chr 41
  ..$ ZZZ/43  : chr 42
  ..$ ZZZ/44  : chr 43
  ..$ ZZZ/45  : chr 44
  ..$ ZZZ/46  : chr 45
  ..$ ZZZ/47  : chr 46
  ..$ ZZZ/48  : chr 47
  ..$ ZZZ/49  : chr 48
  ..$ ZZZ/50  : chr 49
  ..$ ZZZ/51  : chr 50
  ..$ ZZZ/52  : chr 51
  ..$ ZZZ/53  : chr 52
  ..$ ZZZ/54  : chr 53
  ..$ ZZZ/55  : chr 54
  ..$ ZZZ/56  : chr 55
  ..$ ZZZ/57  : chr 56
  ..$ ZZZ/58  : chr 57
  ..$ ZZZ/59  : chr 58
  ..$ ZZZ/60  : chr 59
  ..$ ZZZ/61  : chr 60
  ..$ ZZZ/62  : chr 61
  ..$ ZZZ/63  : chr 62
  ..$ ZZZ/64  : chr 63
  ..$ ZZZ/65  : chr 64
  ..$ ZZZ/66  : chr 65
  ..$ ZZZ/82  : chr 66
  ..$ ZZZ/84  : chr 67
  ..$ ZZZ/85  : chr 68
  ..$ ZZZ/86  : chr 69
  ..$ ZZZ/87  : chr 70
  ..$ ZZZ/88  : chr 71
  ..$ ZZZ/89  : chr 72
  ..$ ZZZ/90  : chr 73
  ..$ ZZZ/91  : chr 74
  ..$ ZZZ/92  : chr 75
  ..$ ZZZ/93  : chr 76
  ..$ ZZZ/94  : chr 77
  ..$ ZZZ/95  : chr 78
  ..$ ZZZ/96  : chr 79
  ..$ ZZZ/97  : chr 80
  ..$ ZZZ/98  : chr 81
  ..$ ZZZ/99  : chr 82
  ..$ ZZZ/100 : chr 83
  ..$ ZZZ/101 : chr 84
  ..$ ZZZ/102 : chr 85
  ..$ ZZZ/103 : chr 86
  ..$ ZZZ/104 : chr 87
  ..$ ZZZ/105 : chr 88
  ..$ ZZZ/107 : chr 89
  ..$ ZZZ/108 : chr 90
  ..$ ZZZ/109 : chr 91
  ..$ ZZZ/111 : chr 92
  ..$ ZZZ/112 : chr 93
  ..$ ZZZ/113 : chr 94
  ..$ ZZZ/114 : chr 95
  ..$ ZZZ/115 : chr 96
  ..$ ZZZ/116 : chr 97
  ..$ ZZZ/117 : chr 98
  .. [list output truncated]
 $ status :List of 4454
  ..$ ZZZ/1   : chr Y/csactive
  ..$ ZZZ/2   : chr Y/csactive
  ..$ ZZZ/3   : chr Y/csactive
  ..$ ZZZ/4   : chr Y/csactive
  ..$ ZZZ/5   : chr Y/csactive
  ..$ ZZZ/6   : chr Y/csactive
  ..$ ZZZ/7   : chr Y/csactive
  ..$ ZZZ/8   : chr Y/csactive
  ..$ ZZZ/9   : chr Y/csactive
  ..$ ZZZ/10  : chr Y/csactive
  ..$ ZZZ/11  : chr Y/csactive
  ..$ ZZZ/12  : chr Y/csactive
  ..$ ZZZ/13  : chr Y/csactive
  ..$ ZZZ/14  : chr Y/csactive
  ..$ ZZZ/15  : chr Y/csactive
  ..$ ZZZ/16  : chr Y/csactive
  ..$ ZZZ/17  : chr Y/csactive
  ..$ ZZZ/18  : chr Y/csactive
  ..$ ZZZ/19  : chr Y/csactive
  ..$ ZZZ/20  : chr Y/csactive
  ..$ ZZZ/21  : chr Y/csactive
  ..$ ZZZ/22  : chr Y/csactive
  ..$ ZZZ/23  : chr Y/csactive
  ..$ ZZZ/24  : chr Y/csactive
  ..$ ZZZ/25  : chr Y/csactive
  ..$ ZZZ/26  : chr Y/csactive
  ..$ ZZZ/27  : chr Y/csactive
  ..$ ZZZ/28  : chr 

Re: [R] Calculating NOEL using R and logistic regression - Toxicology

2012-04-04 Thread Danielle Duncan
I suppose I'll just report a LC10 using the dose.p function in the package
MASS using my glm fitted logistic regression on binomial data. Thanks
everyone for ideas  input! The LOEC seems to be a flawed
calculation...I'll research it. Again, thanks all!

On Mon, Apr 2, 2012 at 2:45 PM, Danielle Duncan dldunc...@alaska.eduwrote:

 Hello, I used the glm function in R to fit a dose-response relationship
 and then have been using dose.p to calculate the LC50, however I would like
 to calculate the NOEL (no observed effect level), ie the lowest dose above
 which responses start occurring. Does anyone know how to do this?




-- 
Wilderness isn’t the wide open spaces. It’s the wild things in it”

[[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] Rgui maintains open file handles after Sweave error

2012-04-04 Thread Alexander Shenkin
Hello Folks,

When I run the document below through sweave, rgui.exe/rsession.exe
leaves a file handle open to the sweave-001.pdf graphic (as verified by
process explorer).  Pdflatex.exe then crashes (with a Permission Denied
error) because the graphic file is locked.

This only seems to happen when there is an error in the sweave document.
 When there are no errors, no file handles are left open.  However, once
a file handle is stuck open, I can find no other way of closing it save
for quitting out of R.

Any help would be greatly appreciated!  It would be nice to be able to
write flawless sweave every time, but flawed as I am, I am having to
restart R continuously.

Thanks,
Allie


OS: Windows 7 Pro x64 SP1


 sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: i386-pc-mingw32/i386 (32-bit)


test.Rnw:

\documentclass{article}
\title {file handle test}
\author{test author}
\usepackage{Sweave}
\begin {document}
\maketitle

\SweaveOpts{prefix.string=sweave}

\begin{figure}
\begin{center}

fig=TRUE, echo=FALSE=
df = data.frame(a=rnorm(100), b=rnorm(100), group = c(g1,
g2, g3, g4))
plot(df$a, df$y, foo)
@

\caption{test figure one}
\label{fig:one}
\end{center}
\end{figure}
\end{document}



Sweave command run:

Sweave(test.Rnw, syntax=SweaveSyntaxNoweb)



Sweave.sty:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{Sweave}{}

\RequirePackage{ifthen}
\newboolean{Sweave@gin}
\setboolean{Sweave@gin}{true}
\newboolean{Sweave@ae}
\setboolean{Sweave@ae}{true}

\DeclareOption{nogin}{\setboolean{Sweave@gin}{false}}
\DeclareOption{noae}{\setboolean{Sweave@ae}{false}}
\ProcessOptions

\RequirePackage{graphicx,fancyvrb}
\IfFileExists{upquote.sty}{\RequirePackage{upquote}}{}

\ifthenelse{\boolean{Sweave@gin}}{\setkeys{Gin}{width=0.8\textwidth}}{}%
\ifthenelse{\boolean{Sweave@ae}}{%
  \RequirePackage[T1]{fontenc}
  \RequirePackage{ae}
}{}%

\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}

\newenvironment{Schunk}{}{}

\newcommand{\Sconcordance}[1]{%
  \ifx\pdfoutput\undefined%
  \csname newcount\endcsname\pdfoutput\fi%
  \ifcase\pdfoutput\special{#1}%
  \else\immediate\pdfobj{#1}\fi}

__
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 avoid this : underflow occurred in 'lgammacor'

2012-04-04 Thread casperyc
Hi all,

I am constructing a likelihood involving the following

lbeta(j + a, k - j + b)

where j,k are constants and a and b are parameters (0).

While doing the optimization, the error sometimes occurs,

In lbeta(j + a, k - j + b) : underflow occurred in 'lgammacor'

Is there a way to avoid it?

I am not sure what's being used in ' 'lgammacor''.

Thanks!

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

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-avoid-this-underflow-occurred-in-lgammacor-tp4532940p4532940.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] Rgui maintains open file handles after Sweave error

2012-04-04 Thread Henrik Bengtsson
See ?closeAllConnections

Suggestion to the maintainer of Sweave: atomify the figure
generation, e.g. use { pdf(); on.exit(dev.off()); {...}; } or similar,
instead of { pdf(); {...}; dev.off(); } possibly by leaving a copy of
the fault figure file for troubleshooting.

/Henrik

On Wed, Apr 4, 2012 at 12:25 PM, Alexander Shenkin ashen...@ufl.edu wrote:
 Hello Folks,

 When I run the document below through sweave, rgui.exe/rsession.exe
 leaves a file handle open to the sweave-001.pdf graphic (as verified by
 process explorer).  Pdflatex.exe then crashes (with a Permission Denied
 error) because the graphic file is locked.

 This only seems to happen when there is an error in the sweave document.
  When there are no errors, no file handles are left open.  However, once
 a file handle is stuck open, I can find no other way of closing it save
 for quitting out of R.

 Any help would be greatly appreciated!  It would be nice to be able to
 write flawless sweave every time, but flawed as I am, I am having to
 restart R continuously.

 Thanks,
 Allie


 OS: Windows 7 Pro x64 SP1


 sessionInfo()
 R version 2.14.2 (2012-02-29)
 Platform: i386-pc-mingw32/i386 (32-bit)


 test.Rnw:

    \documentclass{article}
    \title {file handle test}
    \author{test author}
    \usepackage{Sweave}
    \begin {document}
    \maketitle

    \SweaveOpts{prefix.string=sweave}

    \begin{figure}
    \begin{center}

    fig=TRUE, echo=FALSE=
        df = data.frame(a=rnorm(100), b=rnorm(100), group = c(g1,
 g2, g3, g4))
        plot(df$a, df$y, foo)
    @

    \caption{test figure one}
    \label{fig:one}
    \end{center}
    \end{figure}
    \end{document}



 Sweave command run:

    Sweave(test.Rnw, syntax=SweaveSyntaxNoweb)



 Sweave.sty:

    \NeedsTeXFormat{LaTeX2e}
    \ProvidesPackage{Sweave}{}

    \RequirePackage{ifthen}
    \newboolean{Sweave@gin}
    \setboolean{Sweave@gin}{true}
    \newboolean{Sweave@ae}
    \setboolean{Sweave@ae}{true}

    \DeclareOption{nogin}{\setboolean{Sweave@gin}{false}}
    \DeclareOption{noae}{\setboolean{Sweave@ae}{false}}
    \ProcessOptions

    \RequirePackage{graphicx,fancyvrb}
    \IfFileExists{upquote.sty}{\RequirePackage{upquote}}{}

    \ifthenelse{\boolean{Sweave@gin}}{\setkeys{Gin}{width=0.8\textwidth}}{}%
    \ifthenelse{\boolean{Sweave@ae}}{%
      \RequirePackage[T1]{fontenc}
      \RequirePackage{ae}
    }{}%

    \DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
    \DefineVerbatimEnvironment{Soutput}{Verbatim}{}
    \DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}

    \newenvironment{Schunk}{}{}

    \newcommand{\Sconcordance}[1]{%
      \ifx\pdfoutput\undefined%
      \csname newcount\endcsname\pdfoutput\fi%
      \ifcase\pdfoutput\special{#1}%
      \else\immediate\pdfobj{#1}\fi}

 __
 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] Rgui maintains open file handles after Sweave error

2012-04-04 Thread Alexander Shenkin
Thanks for the reply, Henrik.  Process Explorer still shows the file
handle as being open, but R only shows the following:

 showConnections(all=TRUE)
  description class  mode text   isopen   can read can write
0 stdin terminal r  text opened yesno
1 stdoutterminal w  text opened no yes
2 stderrterminal w  text opened no yes


On 4/4/2012 2:45 PM, Henrik Bengtsson wrote:
 See ?closeAllConnections
 
 Suggestion to the maintainer of Sweave: atomify the figure
 generation, e.g. use { pdf(); on.exit(dev.off()); {...}; } or similar,
 instead of { pdf(); {...}; dev.off(); } possibly by leaving a copy of
 the fault figure file for troubleshooting.
 
 /Henrik
 
 On Wed, Apr 4, 2012 at 12:25 PM, Alexander Shenkin ashen...@ufl.edu wrote:
 Hello Folks,

 When I run the document below through sweave, rgui.exe/rsession.exe
 leaves a file handle open to the sweave-001.pdf graphic (as verified by
 process explorer).  Pdflatex.exe then crashes (with a Permission Denied
 error) because the graphic file is locked.

 This only seems to happen when there is an error in the sweave document.
  When there are no errors, no file handles are left open.  However, once
 a file handle is stuck open, I can find no other way of closing it save
 for quitting out of R.

 Any help would be greatly appreciated!  It would be nice to be able to
 write flawless sweave every time, but flawed as I am, I am having to
 restart R continuously.

 Thanks,
 Allie


 OS: Windows 7 Pro x64 SP1


 sessionInfo()
 R version 2.14.2 (2012-02-29)
 Platform: i386-pc-mingw32/i386 (32-bit)


 test.Rnw:

\documentclass{article}
\title {file handle test}
\author{test author}
\usepackage{Sweave}
\begin {document}
\maketitle

\SweaveOpts{prefix.string=sweave}

\begin{figure}
\begin{center}

fig=TRUE, echo=FALSE=
df = data.frame(a=rnorm(100), b=rnorm(100), group = c(g1,
 g2, g3, g4))
plot(df$a, df$y, foo)
@

\caption{test figure one}
\label{fig:one}
\end{center}
\end{figure}
\end{document}



 Sweave command run:

Sweave(test.Rnw, syntax=SweaveSyntaxNoweb)



 Sweave.sty:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{Sweave}{}

\RequirePackage{ifthen}
\newboolean{Sweave@gin}
\setboolean{Sweave@gin}{true}
\newboolean{Sweave@ae}
\setboolean{Sweave@ae}{true}

\DeclareOption{nogin}{\setboolean{Sweave@gin}{false}}
\DeclareOption{noae}{\setboolean{Sweave@ae}{false}}
\ProcessOptions

\RequirePackage{graphicx,fancyvrb}
\IfFileExists{upquote.sty}{\RequirePackage{upquote}}{}

\ifthenelse{\boolean{Sweave@gin}}{\setkeys{Gin}{width=0.8\textwidth}}{}%
\ifthenelse{\boolean{Sweave@ae}}{%
  \RequirePackage[T1]{fontenc}
  \RequirePackage{ae}
}{}%

\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}

\newenvironment{Schunk}{}{}

\newcommand{\Sconcordance}[1]{%
  \ifx\pdfoutput\undefined%
  \csname newcount\endcsname\pdfoutput\fi%
  \ifcase\pdfoutput\special{#1}%
  \else\immediate\pdfobj{#1}\fi}

 __
 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] Rgui maintains open file handles after Sweave error

2012-04-04 Thread Yihui Xie
Herik's suggestion is an absolutely good practice which guarantees the
device is always closed. That is what I did in the knitr package, so
you can probably take a look at http://yihui.name/knitr/

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Wed, Apr 4, 2012 at 2:52 PM, Alexander Shenkin ashen...@ufl.edu wrote:
 Thanks for the reply, Henrik.  Process Explorer still shows the file
 handle as being open, but R only shows the following:

 showConnections(all=TRUE)
  description class      mode text   isopen   can read can write
 0 stdin     terminal r  text opened yes    no
 1 stdout    terminal w  text opened no     yes
 2 stderr    terminal w  text opened no     yes


 On 4/4/2012 2:45 PM, Henrik Bengtsson wrote:
 See ?closeAllConnections

 Suggestion to the maintainer of Sweave: atomify the figure
 generation, e.g. use { pdf(); on.exit(dev.off()); {...}; } or similar,
 instead of { pdf(); {...}; dev.off(); } possibly by leaving a copy of
 the fault figure file for troubleshooting.

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


[R] Deadlines Approaching: R User Conference Registration, Hotels, Student Scholarships

2012-04-04 Thread Frank Harrell

DEADLINE FAST APPROACHING – 8th Annual International R User Conference
useR! 2012, Nashville, Tennessee USA

Registration Deadlines:
Early Registration: Passed
Regular Registration: Mar 1- May 12
Late Registration: May 13 – June 4
On-Site Registration: June 12 – June 15

Please note: Nashville is offering several large entertainment events 
the month of June, and hotels are quickly selling out.  It's imperative 
that you make your hotel accommodations for the conference as soon as 
possible.  For those of you who have submitted abstracts we will be 
notifying you this week regarding acceptance as an oral presentation or 
as a poster.


Students: A limited number of $500 reimbursements for registration and 
travel expenses are available, based on merit and need.  Please apply by 
sending an application to Tatsuki Koyama at 
tatsuki.koy...@vanderbilt.edu by April 15.  Include a brief CV, a copy 
of your abstract if one was submitted, a statement that demonstrates 
your need for financial assistance, and a letter of support from your 
supervisor.


Please join us at the 8th Annual International R User Conference useR!
2012 in Nashville, Tennessee.  For more conference details, please visit 
http://biostat.mc.vanderbilt.edu/UseR-2012


Thanks
Frank

--
Frank E Harrell Jr Professor and Chairman  School of Medicine
   Department of Biostatistics Vanderbilt University

__
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] Selecting obs within groups defined by 2 variables

2012-04-04 Thread Naomi Sugie
Hello,

I am relatively new to R, and I am trying to select the last  
observation within a group, where the group is defined by two  
variables.  One of the variables is a date.

In the below example, C3 varies within C2, which varies within C1. I  
need to select the last observation in C3 for 4 groups (C1*C2):  1x,  
1y, 2x, and 2y.  In my real dataset, C2 is a date (mm/dd/yy)

C1  C2  C3
1   x   1
1   x   2
1   y   1
1   y   2
2   x   1
2   x   2
2   y   1
2   y   2

I have found code (from UCLA R FAQs and this list's archives) for  
selecting the last observation when a group is defined by ONE variable  
(e.g., C1):

last -by(mydata, mydata$C1, tail, n=1)
lastd-do.call(rbind, as.list(last))

The by function does not seem to allow two variables in the Indices  
argument:
last -by(mydata, mydata$C1 mydata$C2, tail, n=1) THIS DOESN'T WORK

I tried creating a new variable C1*C2, but I think this is risky since  
it may not be unique depending on my values of C1 and C2 (I have a  
very large dataset)

Thank you for the help,



[[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] meta-analysis, outcome = OR associated with a continuous independent variable

2012-04-04 Thread Marie-Pierre Sylvestre
Hello everyone,
I want to do a meta-analysis of case-control studies on which an OR was
computed based on a continuous exposure. I have found several several
packages (metafor, rmeta, meta) but unless I misunderstood their main
functions,  it seems to me that they focus on two-group comparisons (binary
independent variable), and do not have the option of using a continuous
independent variable.


If this is right, do you have any suggestions for a meta-analysis with
continuous independent variable? I using lme or lme4 with weights my only
option?

Thanks in advance,
MP

[[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] Selecting obs within groups defined by 2 variables

2012-04-04 Thread Peter Alspach
Tena koe Naomi

There are lots of ways to do this.  Here are a couple (note I've made a minor 
modification to your example):

 naomi
  C1 C2 C3
1  1  x  1
2  1  x  2
3  1  y  1
4  1  y  2
5  2  x  1
6  2  x  2
7  2  x  3
8  2  y  1
9  2  y  2

 tapply(naomi[,3], naomi[,1:2], function(x) x[length(x)])
   C2
C1  x y
  1 2 2
  2 3 2

 aggregate(naomi[,3], naomi[,1:2], function(x) x[length(x)])
  C1 C2 x
1  1  x 2
2  2  x 3
3  1  y 2
4  2  y 2

HTH 

Peter Alspach

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Naomi Sugie
Sent: Thursday, 5 April 2012 8:21 a.m.
To: r-help@r-project.org
Subject: [R] Selecting obs within groups defined by 2 variables

Hello,

I am relatively new to R, and I am trying to select the last  
observation within a group, where the group is defined by two  
variables.  One of the variables is a date.

In the below example, C3 varies within C2, which varies within C1. I  
need to select the last observation in C3 for 4 groups (C1*C2):  1x,  
1y, 2x, and 2y.  In my real dataset, C2 is a date (mm/dd/yy)

C1  C2  C3
1   x   1
1   x   2
1   y   1
1   y   2
2   x   1
2   x   2
2   y   1
2   y   2

I have found code (from UCLA R FAQs and this list's archives) for  
selecting the last observation when a group is defined by ONE variable  
(e.g., C1):

last -by(mydata, mydata$C1, tail, n=1)
lastd-do.call(rbind, as.list(last))

The by function does not seem to allow two variables in the Indices  
argument:
last -by(mydata, mydata$C1 mydata$C2, tail, n=1) THIS DOESN'T WORK

I tried creating a new variable C1*C2, but I think this is risky since  
it may not be unique depending on my values of C1 and C2 (I have a  
very large dataset)

Thank you for the help,



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

The contents of this e-mail are confidential and may be subject to legal 
privilege.
 If you are not the intended recipient you must not use, disseminate, 
distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received 
this
 e-mail in error, please notify the sender and delete all material pertaining 
to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the 
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

__
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] recover lost global function

2012-04-04 Thread Sam Steingold
Since R has the same namespace for functions and variables,
 c - 1
kills the global function, which can be restored by
 c - get(c,mode=function)

Is there a way to prevent R from overriding globals
or at least warning when I do that
or at least warning when I replace a functional value with non-functional?

thanks.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://iris.org.il http://camera.org http://ffii.org
http://dhimmi.com http://mideasttruth.com http://pmw.org.il
Garbage In, Gospel Out

__
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] convert a list to a data frame

2012-04-04 Thread Sam Steingold
 * Sam Steingold f...@tah.bet [2012-04-04 14:58:15 -0400]:

 1. the strings I replaced with  and  are very long; I wish I
 could replace them in the object all, not just in text

i.e., I have a long list with elements with long names.
how do I replace all these long names with something shorter?
row.names(list) - ...
does not do the trick.

 lapply(all.v,names)[97:103]
 $`ZZZ/2030`
 [1] VECTOR/188

 $`ZZZ/2031`
 [1] VECTOR/187

 $`ZZZ/2032`
 [1] VECTOR/186

 $`ZZZ/2033`
 [1] VECTOR/185

 $`ZZZ/2034`
 [1] VECTOR/183
 [2] VECTOR/184

 $`ZZZ/2035`
 [1] VECTOR/182

 $`ZZZ/2036`
 [1] VECTOR/181

 for that I will need 2 lines in the resulting data frame.
 how do I do that?

done by a judicious use of rep.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://iris.org.il
http://thereligionofpeace.com http://mideasttruth.com http://ffii.org
Those who can laugh at themselves will never cease to be amused.

__
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] recover lost global function

2012-04-04 Thread Duncan Murdoch

On 12-04-04 4:52 PM, Sam Steingold wrote:

Since R has the same namespace for functions and variables,

c- 1

kills the global function, which can be restored by

c- get(c,mode=function)


Is there a way to prevent R from overriding globals
or at least warning when I do that
or at least warning when I replace a functional value with non-functional?


It doesn't kill it, it just hides it.  You can still get the original by 
telling R which one you want, e.g. base::c.


You'll get a warning when you do this in a package, e.g. library(Hmisc) 
will tell you that it has hidden 5 functions from view.


There's no warning when you mask a function with a non-function at top 
level, and little need for one, because R does the right search based on 
the fact that you're making a function call:


 c
[1] 1
 c(1,2)
[1] 1 2

It only matters when you need to pass the function as an argument, e.g. 
to one of the apply() family of functions.


Duncan Murdoch

__
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] extract data

2012-04-04 Thread Roslina Zakaria
HI,

I would like to extract data in a specific way.  For example, the rainfall data

0,0,1.5,0,0, 3,1,2.5,0,0,0,0, 2.3,0,0,0, 2.1,1.4,0,0,0, 3,2,1,0,0,0...

data_1: 1.5, 2.3   ( a single nonzero data between zeros data)
data_2: 3.1, 2.5, 2.1,1.4   ( two nonzero data between zeros data)
data_3: 3,1,2.5, 3,2,1   ( three nonzero data between zeros data)


Thank you so much for any help given.

Roslina

[[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] extract data

2012-04-04 Thread Roslina Zakaria
HI,



I would like to extract data in a specific way.  For example, the rainfall data



0,0,1.5,0,0, 3,1,2.5,0,0,0,0, 2.3,0,0,0, 2.1,1.4,0,0,0, 3,2,1,0,0,0...



data_1: 1.5, 2.3   ( a single nonzero data between zeros data)

data_2: 3.1, 2.5, 2.1,1.4   ( two nonzero data between zeros data)

data_3: 3,1,2.5, 3,2,1   ( three nonzero data between zeros data)




Thank you so much for any help given.



Roslina


[[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] recover lost global function

2012-04-04 Thread Sam Steingold
 * Duncan Murdoch zheqbpu.qha...@tznvy.pbz [2012-04-04 17:00:32 -0400]:

 There's no warning when you mask a function with a non-function at top
 level, and little need for one, because R does the right search based on
 the fact that you're making a function call:

 c
 [1] 1
 c(1,2)
 [1] 1 2

why then am I getting these warnings from cmpfile?

Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 

I did overwrite all to a data frame, but it only appears in a funtion
position all(...) in the file being compiled.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://mideasttruth.com http://truepeace.org
http://americancensorship.org http://palestinefacts.org http://ffii.org
will write code that writes code that writes code for food

__
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] recover lost global function

2012-04-04 Thread Sam Steingold
 * Duncan Murdoch zheqbpu.qha...@tznvy.pbz [2012-04-04 17:00:32 -0400]:

 There's no warning when you mask a function with a non-function at top
 level, and little need for one, because R does the right search based on
 the fact that you're making a function call:

 c
 [1] 1
 c(1,2)
 [1] 1 2

why then am I getting these warnings from cmpfile?

Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 
Note: no visible global function definition for 'all' 

I did overwrite all to a data frame, but it only appears in a function
position all(...) in the file being compiled.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://mideasttruth.com http://truepeace.org
http://americancensorship.org http://palestinefacts.org http://ffii.org
will write code that writes code that writes code for food

__
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] meta-analysis, outcome = OR associated with a continuous independent variable

2012-04-04 Thread Thomas Lumley
On Thu, Apr 5, 2012 at 8:24 AM, Marie-Pierre Sylvestre
mp.sylves...@gmail.com wrote:
 Hello everyone,
 I want to do a meta-analysis of case-control studies on which an OR was
 computed based on a continuous exposure. I have found several several
 packages (metafor, rmeta, meta) but unless I misunderstood their main
 functions,  it seems to me that they focus on two-group comparisons (binary
 independent variable), and do not have the option of using a continuous
 independent variable.


There's no problem in using continuous exposures in meta.summaries()
in the rmeta package.  For each study, compute your log odds ratio and
its standard error, and feed them in.

You just need to make sure that the odds ratio is in the same units in
each study, of course.

   -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

__
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] convert a list to a data frame

2012-04-04 Thread David Winsemius


On Apr 4, 2012, at 4:54 PM, Sam Steingold wrote:


* Sam Steingold f...@tah.bet [2012-04-04 14:58:15 -0400]:

1. the strings I replaced with  and  are very long; I wish I
could replace them in the object all, not just in text


i.e., I have a long list with elements with long names.
how do I replace all these long names with something shorter?
row.names(list) - ...
does not do the trick.


Lists do not have rownames. They have names.

You _really_ should learn to post code that creates meaningful test  
cases. If, for example, you want to ask a question about a list to  
which you desire replacing names, then post:


testlis - list(`ZZZ/2030` = VECTOR/188,
`ZZZ/2031` = VECTOR/187,
`ZZZ/2033` = VECTOR/186,
`ZZZ/2037` = VECTOR/185)

To which the respondent has only to copy that to a console to test the  
fairly simple solution :



 names(testlis) - sub(^Z+, Z, names(testlis))
 testlis
$`Z/2030`
[1] VECTOR/188

$`Z/2031`
[1] VECTOR/187

$`Z/2033`
[1] VECTOR/186

$`Z/2037`
[1] VECTOR/185

A quick way to construct possibly minimal examples from existing  
objects is to post the results of dput(head(listname))


--
David.



lapply(all.v,names)[97:103]

$

$`ZZZ/2031`
[1] VECTOR/187

$`ZZZ/2032`
[1] VECTOR/186

$`ZZZ/2033`
[1] VECTOR/185

$`ZZZ/2034`
[1] VECTOR/183
[2] VECTOR/184

$`ZZZ/2035`
[1] VECTOR/182

$`ZZZ/2036`
[1] VECTOR/181

for that I will need 2 lines in the resulting data frame.
how do I do that?


done by a judicious use of rep.

--
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X  
11.0.11004000

http://www.childpsy.net/ http://iris.org.il
http://thereligionofpeace.com http://mideasttruth.com http://ffii.org
Those who can laugh at themselves will never cease to be amused.

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


David Winsemius, MD
West Hartford, CT

__
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] Selecting obs within groups defined by 2 variables

2012-04-04 Thread Naomi Sugie

Hi Peter,
Thanks! This was very helpful and worked perfectly.
Naomi

On Apr 4, 2012, at 4:52 PM, Peter Alspach wrote:


Tena koe Naomi

There are lots of ways to do this.  Here are a couple (note I've  
made a minor modification to your example):



naomi

 C1 C2 C3
1  1  x  1
2  1  x  2
3  1  y  1
4  1  y  2
5  2  x  1
6  2  x  2
7  2  x  3
8  2  y  1
9  2  y  2


tapply(naomi[,3], naomi[,1:2], function(x) x[length(x)])

  C2
C1  x y
 1 2 2
 2 3 2


aggregate(naomi[,3], naomi[,1:2], function(x) x[length(x)])

 C1 C2 x
1  1  x 2
2  2  x 3
3  1  y 2
4  2  y 2

HTH 

Peter Alspach

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
] On Behalf Of Naomi Sugie

Sent: Thursday, 5 April 2012 8:21 a.m.
To: r-help@r-project.org
Subject: [R] Selecting obs within groups defined by 2 variables

Hello,

I am relatively new to R, and I am trying to select the last
observation within a group, where the group is defined by two
variables.  One of the variables is a date.

In the below example, C3 varies within C2, which varies within C1. I
need to select the last observation in C3 for 4 groups (C1*C2):  1x,
1y, 2x, and 2y.  In my real dataset, C2 is a date (mm/dd/yy)

C1  C2  C3
1   x   1
1   x   2
1   y   1
1   y   2
2   x   1
2   x   2
2   y   1
2   y   2

I have found code (from UCLA R FAQs and this list's archives) for
selecting the last observation when a group is defined by ONE variable
(e.g., C1):

last -by(mydata, mydata$C1, tail, n=1)
lastd-do.call(rbind, as.list(last))

The by function does not seem to allow two variables in the Indices
argument:
last -by(mydata, mydata$C1 mydata$C2, tail, n=1) THIS DOESN'T WORK

I tried creating a new variable C1*C2, but I think this is risky since
it may not be unique depending on my values of C1 and C2 (I have a
very large dataset)

Thank you for the help,



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

The contents of this e-mail are confidential and may be subject to  
legal privilege.
If you are not the intended recipient you must not use, disseminate,  
distribute or
reproduce all or any part of this e-mail or attachments.  If you  
have received this
e-mail in error, please notify the sender and delete all material  
pertaining to this
e-mail.  Any opinion or views expressed in this e-mail are those of  
the individual
sender and may not represent those of The New Zealand Institute for  
Plant and

Food Research Limited.


__
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 lines and points on the second plot when using gap.plot in plotrix

2012-04-04 Thread sophykim
you need to subtract the length of gap in y-axis.
Good luck!

--
View this message in context: 
http://r.789695.n4.nabble.com/Plotting-lines-and-points-on-the-second-plot-when-using-gap-plot-in-plotrix-tp804226p4533129.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] Selecting obs within groups defined by 2 variables

2012-04-04 Thread Rui Barradas
Hello,


 The by function does not seem to allow two variables in the Indices  
 argument:
 

Yes it does, but you must use a list of variables.
(Read the help for 'by': INDICESa factor or a list of factors, each of
length nrow(data).)

mydata - read.table(text=
C1 C2 C3
1 x 1
1 x 2
1 y 1
1 y 2
2 x 1
2 x 2
2 y 1
2 y 2
, header=TRUE)

last -by(mydata, list(mydata$C1, mydata$C2), tail, n=1)
last

# Another way, output is more usefull.
last2 - aggregate(mydata, list(mydata$C1, mydata$C2), tail, n=1)
last2[, -(1:2)]

Hope this helps,

Rui Barradas






--
View this message in context: 
http://r.789695.n4.nabble.com/Selecting-obs-within-groups-defined-by-2-variables-tp4533125p4533169.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] Subscript Error

2012-04-04 Thread z2.0


json_dir is a list of JSON lists mapping lat/long route points between
locations using CloudMade's API.
post_url is the URL of the HTTP request

for (n in json_dir) {
i = i + 1
if (typeof(json_dir[[i]]) != NULL) {
if (i == 1) {
dat_add - ldply(json_dir[[i]], function(x)
t(data.frame(x)), .progress = text)
names(dat_add) - c(lat, lon)
json_path - list(dat_add)
} else {
dat_add - ldply(json_dir[[i]], function(x)
t(data.frame(x)), .progress = text)
names(dat_add) - c(lat, lon)
json_path - c(json_path, list(dat_add))
}

p = p + geom_path(aes(lon, lat), data = json_path[[i]])
}
print(paste(Processed , i,  of , as.character(length(json_dir)),
 in route set., sep = ))
}

This runs until i = 101 and then errors out with, 
Error in json_path[[i]] : subscript out of bounds

typeof(json_dir[[101]]) = list, so it's not that the first if-block is
somehow resetting json_path in an errant fashion.

Do lists have a default, built-in limit on no. of elements? Each element I'm
passing contains hundreds or thousands of lat/long pairs, so it's also
possible I'm hitting some upper bound on per-object memory, if that exists,
but Googling around leads me to think that's not the case.

I think I've fucked something up in my logic, but I'm not sure what.


--
View this message in context: 
http://r.789695.n4.nabble.com/Subscript-Error-tp4533219p4533219.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] Using download.file() to grab information from a Password Protected Website

2012-04-04 Thread Michael Roberts
I am new to R and have been spinning my wheels on the following.

*Issue:*  I have a membership to a website, and I want to grab data from
the website using download.file().

download.file(url, destfile, method, quiet = T, mode = w, cacheOK = TRUE)
The R Documentation is helpful.  However, I have been unsuccessful in
figuring out how to access the website using my username and password.

Using an example, can someone show me how to embed the username and
password into download.file() so that I can grab the data?  Better yet, can
I tell R to always use the username and password when accessing the site?
Will I need information other than the url, username and password?

Thanks for your time and help!

MTR

[[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] convert a list to a data frame

2012-04-04 Thread z2.0
Have you looked at plyr?

Generally, ldply works well for this sort of thing.

--
View this message in context: 
http://r.789695.n4.nabble.com/convert-a-list-to-a-data-frame-tp4532206p4533257.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] extract data

2012-04-04 Thread Rui Barradas
Hello,


Roslina Zakaria wrote
 
 HI,
 
 
 
 I would like to extract data in a specific way.  For example, the rainfall
 data
 
 
 
 0,0,1.5,0,0, 3,1,2.5,0,0,0,0, 2.3,0,0,0, 2.1,1.4,0,0,0, 3,2,1,0,0,0...
 
 
 
 data_1: 1.5, 2.3   ( a single nonzero data between zeros data)
 
 data_2: 3.1, 2.5, 2.1,1.4   ( two nonzero data between zeros data)
 
 data_3: 3,1,2.5, 3,2,1   ( three nonzero data between zeros data)
 
 
 
 
 Thank you so much for any help given.
 
 
 
 Roslina
 
 
   [[alternative HTML version deleted]]
 
 
 __
 R-help@ 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.
 


Your data_2 is wrong, not on the given vector.
Anyway, try this,


x - c(0,0,1.5,0,0, 3,1,2.5,0,0,0,0, 2.3,0,0,0, 2.1,1.4,0,0,0, 3,2,1,0,0,0)

f.runs - function(x, run){
z - rle(x != 0)
zz - cumsum(z$lengths)
i - cbind(zz[z$values  z$lengths == run] - (run - 1), zz[z$values 
z$lengths == run])
apply(i, 1, function(j) x[ j[1]:j[2] ])
}

f.runs(x, 1)
f.runs(x, 2)
f.runs(x, 3)


Hope this helps,

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/extract-data-tp4533176p4533288.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] how to load functions from file

2012-04-04 Thread Rolf Turner

On 04/04/12 22:32, Bert Gunter wrote:

Rolf:

Google on load functions into R.
A post referencing source() (from Henrik Bengtsson is the first hit.



Tried that just now.  The only hits I got were to *your* post; no hits
on any post from Henrik Bengtsson.

These things are never as easy and straightforward as the cognoscenti
would have you believe.

cheers,

Rolf

__
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] Shapiro-Wilk cpoefficients: 2 Qs

2012-04-04 Thread Ted Harding
Greetings!
I want to have the coefficients that R uses in shapiro.test()
for the Shapiro-Wilk test for a prticular sample size, i.e.
the a[i] in

  W = Sum(a[i]*x[i])/(Sum(x[i] - mean(x))^2)

(where the x[i] are sorted). Two questions:

Q1:
Is there a readymade R function from which I can extract these?

Q2:
I was wondering if I might be able to modify the code for the
function shapiro.test() so as to obtain these. When I enter

  shapiro.test

I get:

function (x) 
{
DNAME - deparse(substitute(x))
x - sort(x[complete.cases(x)])
stopifnot(is.numeric(x))
n - length(x)
if (n  3 || n  5000) 
stop(sample size must be between 3 and 5000)
rng - x[n] - x[1L]
if (rng == 0) 
stop(all 'x' values are identical)
if (rng  1e-10) 
x - x/rng
n2 - n%/%2L
sw - .C(R_swilk, init = FALSE, as.single(x), n, n1 = n, 
n2, a = single(n2), w = double(1), pw = double(1), ifault = integer(1L))
if (sw$ifault  sw$ifault != 7) 
stop(gettextf(ifault=%d. This should not happen, sw$ifault), 
domain = NA)
RVAL - list(statistic = c(W = sw$w), p.value = sw$pw, method =
Shapiro-Wilk normality test, 
data.name = DNAME)
class(RVAL) - htest
return(RVAL)
}
environment: namespace:stats


So, on the off-chance that the variable 'sw' computed therein might
contain something useful, I changed return(RVAL) to return(sw),
just in case the coefficients might be lurking as a component of sw,
and used this to define a function SW_ted(). I then ran

  SW_ted(rnorm(30))
  # Error in SW_ted(rnorm(30)) : object 'R_swilk' not found

Since shapiro.test(rnorm(30)) works perfectly, and since the
stats: namespace is already present, I am wondering why
object 'R_swilk' not found when it clearly can be found by
shapiro.test().

So why is it that in the .C call:

  sw - .C(R_swilk, ... )

my modifiction of shapiro.test() doesn't find it?

(No doubt there is some dumb oversight behind this, but I'd be
grateful to be told what it is)!

With thanks,
Ted.

-
E-Mail: (Ted Harding) ted.hard...@wlandres.net
Date: 04-Apr-2012  Time: 23:06:32
This message was sent by XFMail

__
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 load functions from file

2012-04-04 Thread Sarah Goslee
I just tried it, because I'm curious that way.

If I search for
load functions into R
I get only this thread.

If I search for
load functions into R
(no quotes), I get the referenced discussion from Henrik Bengtsson:
ttps://stat.ethz.ch/pipermail/r-help/2008-September/173606.html

As in so many areas of dealing with R, details matter.

Sarah

On Wed, Apr 4, 2012 at 6:05 PM, Rolf Turner rolf.tur...@xtra.co.nz wrote:
 On 04/04/12 22:32, Bert Gunter wrote:

 Rolf:

 Google on load functions into R.
 A post referencing source() (from Henrik Bengtsson is the first hit.


 Tried that just now.  The only hits I got were to *your* post; no hits
 on any post from Henrik Bengtsson.

 These things are never as easy and straightforward as the cognoscenti
 would have you believe.

    cheers,

        Rolf



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

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


Re: [R] how to load functions from file

2012-04-04 Thread Rolf Turner

On 05/04/12 10:10, Sarah Goslee wrote:

I just tried it, because I'm curious that way.

If I search for
load functions into R
I get only this thread.

If I search for
load functions into R
(no quotes), I get the referenced discussion from Henrik Bengtsson:
ttps://stat.ethz.ch/pipermail/r-help/2008-September/173606.html

As in so many areas of dealing with R, details matter.


Indeed.  But to me, this is a highly counter-intuitive detail.
Put yourself in the place of a newbie trying to find how to
load functions into R.

cheers,

Rolf

__
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] Print std. Error separately from mle-class object

2012-04-04 Thread Jeff Newmiller
Are you aware that the summary function normally returns a data value that you 
can extract values from and format to your hearts desire?
try
str(coef(summary(tmp)))
and read ?mle-class
(and try to provide a reproducible example next time)
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Aziz, Muhammad Fayez az...@illinois.edu wrote:

Hi,

I am using power.law.fit to get an mle-class object in tmp and print
summary(tmp), coef(tmp) and logLik(tmp). I wanted to print the std.
error for alpha separately as I want to show these values concisely in
a graph legend. coef(summary(tmp)) displays the alpha and std. error
jointly, while I need to print them separately on two lines.

Regards,
Fayez
__
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 load functions from file

2012-04-04 Thread David Winsemius


On Apr 4, 2012, at 6:10 PM, Sarah Goslee wrote:


I just tried it, because I'm curious that way.

If I search for
load functions into R
I get only this thread.

If I search for
load functions into R
(no quotes), I get the referenced discussion from Henrik Bengtsson:
ttps://stat.ethz.ch/pipermail/r-help/2008-September/173606.html

As in so many areas of dealing with R, details matter.


I sometime check how many hops using links in the help system that it  
takes to get from a not-quite-right-term to the right help page.  
Usually it's a pretty small number. In this case the links from the  
load page are save - dump (where source is discussed and not  
just linked at the bottom) - source. So arguably the number of hops  
needed are only two but at most three. (And obviously I'm not counting  
the dput link or the other ones higher up the page. So I do  
understand that I may be asking people to read 9 or 10 pages before  
they post a question. That seems an acceptable effort.)


The help system is not advertised as the preferred method of learning  
R, but it was the method I grew up with.


--
David.



Sarah

On Wed, Apr 4, 2012 at 6:05 PM, Rolf Turner rolf.tur...@xtra.co.nz  
wrote:

On 04/04/12 22:32, Bert Gunter wrote:


Rolf:

Google on load functions into R.
A post referencing source() (from Henrik Bengtsson is the first hit.



Tried that just now.  The only hits I got were to *your* post; no  
hits

on any post from Henrik Bengtsson.

These things are never as easy and straightforward as the cognoscenti
would have you believe.

   cheers,

   Rolf




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

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


David Winsemius, MD
West Hartford, CT

__
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] Remove carriage return in writing tab-delimited file.

2012-04-04 Thread kickout
Having problems with the write.table function. I can write a tab delimited
file just fine, but for each line in my matrix its inputs a carriage return
when i dont want it to.

For example my matrix might be:

ID V1 V2 V3
FARY1004 1 2 3
FARY2067 2 3 1
FARY4587 2 2 2

And I want the written File to be:

FARY1004 1 2 3FARY2067 2 3 1FARY4587 2 2
2

TIA

--
View this message in context: 
http://r.789695.n4.nabble.com/Remove-carriage-return-in-writing-tab-delimited-file-tp4533322p4533322.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   >