[R] do not execute newline command

2011-04-05 Thread Lorenzo Cattarino
Hi R-users,

To automate the creation of scripts, I converted the code (example below) into 
a character string and wrote the object to a file:

Repeat - 
myvec - c(1:12)
cat('vector= ', myvec, '\n')


write (Repeat, 'yourpath/test.R')

the problem is that one line of the code is a cat command. In the output file 
(i.e. test.R), the newline symbol gets executed and I don't want that.

Any idea on how to do that?
Thanks
Lorenzo


[[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] kmeans clustering java

2011-04-05 Thread jcg3441
Hello, 

I have been trying for a few days to do kmeans on a matrix of data which I
populate from java. 

Here's my code: 

String[] Rargs = {--vanilla};
Rengine re = new Rengine(Rargs, false, null);
System.out.println(Rengine created, waiting for R);
// the engine creates R is a new thread, so we should wait until 
it's
// ready
if (!re.waitForR()) {
  System.out.println(Cannot load R);
  return null;
}   
re.eval (rmatrix - matrix(data = NA, nrow = +rows+, ncol
=+(columns-1)+, byrow = FALSE));//,dimnames = ));
REXP rp= re.eval(hDr);
//loop through the matrix and give the upgma_matrix the correct 
values
for (int i = 0; i  rows-1; i++)
{
re.eval (i-  +i);
   for (int j = 1; j  columns; j++)
{
re.eval (j-  +j);
//R matrices start at index 1 (java at 0), so add 1 to  
current
position
re.eval (ii - i+1);
re.eval (jj - j);
   //add values for the lower triangle..
re.eval (rmatrix [ii,jj] - + data[i][j].toString());
System.out.print(data[i][j].toString()+,);
 }
   System.out.println();
 }

REXP rt = re.eval(r_matrix);
String bindString = DATAMATRIX - cbind(rmatrix[,1],;
for (int k = 0; kcolumns-2;k++ ){
if(kcolumns-3){
bindString = bindString+rmatrix[,+(k+2)+],;
}else{
bindString = bindString+rmatrix[,+(k+2)+]);
}
}

rt = re.eval(bindString);
//cluster using kmeans
rt = re.eval(DATAMATRIX;);
rt = re.eval(CLST-DATAMATRIX);
rt = re.eval(CLST - kmeans(CLST,3),true);

but when I check on rt, it comes back as null. 

Any suggestions? 

Jose

--
View this message in context: 
http://r.789695.n4.nabble.com/kmeans-clustering-java-tp3427159p3427159.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] several Filled.contour plots on the same device...

2011-04-05 Thread sunaj
Billy.Requena,
I bow myself into the dust - exactly what I was looking for. 
Thx,
Sunaj

--
View this message in context: 
http://r.789695.n4.nabble.com/several-Filled-contour-plots-on-the-same-device-tp819040p3427236.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] Euclidean Distance in R

2011-04-05 Thread Paul Duckett
Hi

1. I have two raster files *.asc (identical size)
2. The data in each contain presence or absence data in each cell
represented by a 1 or 0 respectively
3. I would like to take the location of each 1 (presence cell) in
raster file 1 and measure the euclidean distance to the nearest 1
(presence cell) in raster file 2.

Obviously in some cases there will be overlap so the distance will be zero.

4. I would like the output file to have each individual measurement on
a seperate line in a single file.


I am very new to R, so any help would be appreciated.

Best regards
Paul
-- 
Paul Duckett - PhD Candidate
Conservation Genetics Lab
E8A 264
Biological Sciences
Faculty of Science
Macquarie University
North Ryde
NSW 2109
http://paulduckett.redbubble.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] ANCOVA for linear regressions without intercept

2011-04-05 Thread Yusuke Fukuda
Hi Steve

It worked with my data! I didn't think of combining the categories before doing 
ANOVA to test for the difference. This is the final answer to my question.

Thank you very much for your time.

Regards,

Yusuke 

-Original Message-
From: Steven McKinney [mailto:smckin...@bccrc.ca] 
Sent: Tuesday, 5 April 2011 12:08 PM
To: Yusuke Fukuda; 'Peter Ehlers'
Cc: r-help@r-project.org
Subject: RE: [R] ANCOVA for linear regressions without intercept

Hi Yusuke,

Does the following get what you are after?

### Make some test data.
 set.seed(123)
 edf - data.frame(sex = c(rep(Male, 10), rep(Female, 10), rep(Unknown, 
 10)),
+   head_length = c(1.2 * c(170:179 + rnorm(10)), 0.8 * 
c(150:159 + rnorm(10)), c(160:169 + rnorm(10)))/10,
+   body_length = c(c(170:179 + rnorm(10)), c(150:159 + 
rnorm(10)), c(160:169 + rnorm(10)))
+   )
 edf$sex - factor(as.character(edf$sex))
 plot(edf$head_length, edf$body_length, pch = as.numeric(edf$sex), col = 
 as.numeric(edf$sex), xlim = c(0, 25), ylim = c(0, 190))
 lmf - lm(body_length ~ head_length * sex, data = edf)


### The full model - do keep an eye on those intercepts and try to ensure they 
are not far from 0.
 summary(lmf)

Call:
lm(formula = body_length ~ head_length * sex, data = edf)

Residuals:
 Min   1Q   Median   3Q  Max 
-2.73783 -0.68133  0.02147  0.50858  2.38931 

Coefficients:
   Estimate Std. Error t value Pr(|t|)
(Intercept)  -3.578 25.425  -0.141   0.8893
head_length  12.772  2.054   6.2182e-06 ***
sexMale  15.122 37.464   0.404   0.6901
sexUnknown   40.308 33.137   1.216   0.2357
head_length:sexMale  -4.977  2.438  -2.042   0.0523 .  
head_length:sexUnknown   -4.971  2.428  -2.047   0.0517 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 1.384 on 24 degrees of freedom
Multiple R-squared: 0.9802, Adjusted R-squared: 0.9761 
F-statistic: 237.7 on 5 and 24 DF,  p-value:  2.2e-16 

### Now suppress intercepts.  head_length:sex should give interactions (slopes) 
only.
 lmrf - lm(body_length ~ -1 + head_length : sex, data = edf)
 summary(lmrf)

Call:
lm(formula = body_length ~ -1 + head_length:sex, data = edf)

Residuals:
 Min   1Q   Median   3Q  Max 
-3.02782 -0.61861 -0.01079  0.68785  2.57544 

Coefficients:
   Estimate Std. Error t value Pr(|t|)
head_length:sexFemale  12.482530.03549   351.8   2e-16 ***
head_length:sexMale 8.345000.02097   398.0   2e-16 ***
head_length:sexUnknown 10.038440.02677   375.0   2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 1.389 on 27 degrees of freedom
Multiple R-squared: 0., Adjusted R-squared: 0. 
F-statistic: 1.409e+05 on 3 and 27 DF,  p-value:  2.2e-16 

### Check the numeric coding of the factor
 with(edf, table(sex, as.numeric(sex)))
 
sex1  2  3
  Female  10  0  0
  Male 0 10  0
  Unknown  0  0 10

 abline(a = 0, b = coef(lmrf)[1], col = 1) ## Females = Black
 abline(a = 0, b = coef(lmrf)[2], col = 2) ## Males = Red
 abline(a = 0, b = coef(lmrf)[3], col = 3) ## Unknown = Green

### If no diff between males and females, then males and females can be 
combined into one group.
 edf$MvF - as.character(edf$sex)
 edf$MvF[edf$MvF != Unknown] - MorF
 edf$MvF - factor(edf$MvF)
 with(edf, table(MvF, sex))
 sex
MvF   Female Male Unknown
  MorF10   10   0
  Unknown  00  10
 lmr1f  - lm(body_length ~ -1 + head_length : MvF, data = edf)
 summary(lmr1f)

Call:
lm(formula = body_length ~ -1 + head_length:MvF, data = edf)

Residuals:
Min  1Q  Median  3Q Max 
-23.976 -21.656   0.077  35.899  39.839 

Coefficients:
   Estimate Std. Error t value Pr(|t|)
head_length:MvFMorF  9.4156 0.3429   27.46   2e-16 ***
head_length:MvFUnknown  10.0384 0.5085   19.74   2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 26.39 on 28 degrees of freedom
Multiple R-squared: 0.9761, Adjusted R-squared: 0.9744 
F-statistic: 571.9 on 2 and 28 DF,  p-value:  2.2e-16 

### Test the hypothesis that male and female heights are equivalent
 anova(lmr1f, lmrf)
Analysis of Variance Table

Model 1: body_length ~ -1 + head_length:MvF
Model 2: body_length ~ -1 + head_length:sex
  Res.Df RSS Df Sum of Sq FPr(F)
1 28 19496.1 
2 2752.1  1 19444 10077  2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

### Plot the reduced model regression lines
 abline(a = 0, b = coef(lmr1f)[1], col = blue, lty = 2)
 abline(a = 0, b = coef(lmr1f)[2], col = orange, lty = 2, lwd = 4)
 

The other two tests can be set up and run similarly.  Don't
forget to adjust for 

Re: [R] ANCOVA for linear regressions without intercept

2011-04-05 Thread Yusuke Fukuda
Hi Steve

Wow, this could be the way to get around to what I was after. I will have a 
close look and see if it works with my data. Will let you know how it goes. 

Thank you.

Yusuke


-Original Message-
From: Steven McKinney [mailto:smckin...@bccrc.ca] 
Sent: Tuesday, 5 April 2011 12:08 PM
To: Yusuke Fukuda; 'Peter Ehlers'
Cc: r-help@r-project.org
Subject: RE: [R] ANCOVA for linear regressions without intercept

Hi Yusuke,

Does the following get what you are after?

### Make some test data.
 set.seed(123)
 edf - data.frame(sex = c(rep(Male, 10), rep(Female, 10), rep(Unknown, 
 10)),
+   head_length = c(1.2 * c(170:179 + rnorm(10)), 0.8 * 
c(150:159 + rnorm(10)), c(160:169 + rnorm(10)))/10,
+   body_length = c(c(170:179 + rnorm(10)), c(150:159 + 
rnorm(10)), c(160:169 + rnorm(10)))
+   )
 edf$sex - factor(as.character(edf$sex))
 plot(edf$head_length, edf$body_length, pch = as.numeric(edf$sex), col = 
 as.numeric(edf$sex), xlim = c(0, 25), ylim = c(0, 190))
 lmf - lm(body_length ~ head_length * sex, data = edf)


### The full model - do keep an eye on those intercepts and try to ensure they 
are not far from 0.
 summary(lmf)

Call:
lm(formula = body_length ~ head_length * sex, data = edf)

Residuals:
 Min   1Q   Median   3Q  Max 
-2.73783 -0.68133  0.02147  0.50858  2.38931 

Coefficients:
   Estimate Std. Error t value Pr(|t|)
(Intercept)  -3.578 25.425  -0.141   0.8893
head_length  12.772  2.054   6.2182e-06 ***
sexMale  15.122 37.464   0.404   0.6901
sexUnknown   40.308 33.137   1.216   0.2357
head_length:sexMale  -4.977  2.438  -2.042   0.0523 .  
head_length:sexUnknown   -4.971  2.428  -2.047   0.0517 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 1.384 on 24 degrees of freedom
Multiple R-squared: 0.9802, Adjusted R-squared: 0.9761 
F-statistic: 237.7 on 5 and 24 DF,  p-value:  2.2e-16 

### Now suppress intercepts.  head_length:sex should give interactions (slopes) 
only.
 lmrf - lm(body_length ~ -1 + head_length : sex, data = edf)
 summary(lmrf)

Call:
lm(formula = body_length ~ -1 + head_length:sex, data = edf)

Residuals:
 Min   1Q   Median   3Q  Max 
-3.02782 -0.61861 -0.01079  0.68785  2.57544 

Coefficients:
   Estimate Std. Error t value Pr(|t|)
head_length:sexFemale  12.482530.03549   351.8   2e-16 ***
head_length:sexMale 8.345000.02097   398.0   2e-16 ***
head_length:sexUnknown 10.038440.02677   375.0   2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 1.389 on 27 degrees of freedom
Multiple R-squared: 0., Adjusted R-squared: 0. 
F-statistic: 1.409e+05 on 3 and 27 DF,  p-value:  2.2e-16 

### Check the numeric coding of the factor
 with(edf, table(sex, as.numeric(sex)))
 
sex1  2  3
  Female  10  0  0
  Male 0 10  0
  Unknown  0  0 10

 abline(a = 0, b = coef(lmrf)[1], col = 1) ## Females = Black
 abline(a = 0, b = coef(lmrf)[2], col = 2) ## Males = Red
 abline(a = 0, b = coef(lmrf)[3], col = 3) ## Unknown = Green

### If no diff between males and females, then males and females can be 
combined into one group.
 edf$MvF - as.character(edf$sex)
 edf$MvF[edf$MvF != Unknown] - MorF
 edf$MvF - factor(edf$MvF)
 with(edf, table(MvF, sex))
 sex
MvF   Female Male Unknown
  MorF10   10   0
  Unknown  00  10
 lmr1f  - lm(body_length ~ -1 + head_length : MvF, data = edf)
 summary(lmr1f)

Call:
lm(formula = body_length ~ -1 + head_length:MvF, data = edf)

Residuals:
Min  1Q  Median  3Q Max 
-23.976 -21.656   0.077  35.899  39.839 

Coefficients:
   Estimate Std. Error t value Pr(|t|)
head_length:MvFMorF  9.4156 0.3429   27.46   2e-16 ***
head_length:MvFUnknown  10.0384 0.5085   19.74   2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 26.39 on 28 degrees of freedom
Multiple R-squared: 0.9761, Adjusted R-squared: 0.9744 
F-statistic: 571.9 on 2 and 28 DF,  p-value:  2.2e-16 

### Test the hypothesis that male and female heights are equivalent
 anova(lmr1f, lmrf)
Analysis of Variance Table

Model 1: body_length ~ -1 + head_length:MvF
Model 2: body_length ~ -1 + head_length:sex
  Res.Df RSS Df Sum of Sq FPr(F)
1 28 19496.1 
2 2752.1  1 19444 10077  2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

### Plot the reduced model regression lines
 abline(a = 0, b = coef(lmr1f)[1], col = blue, lty = 2)
 abline(a = 0, b = coef(lmr1f)[2], col = orange, lty = 2, lwd = 4)
 

The other two tests can be set up and run similarly.  Don't
forget to adjust for multiple comparisons...

HTH

Steve



[R] Saving console and graph output to same file

2011-04-05 Thread Nikhil Abhyankar
Hello All,

How do I save the output of the R console and the graphic output to the same
PDF file and append these to each other?

I need to have a frequency table and a corresponding graph, one below the
other in a file. I have tried with sending the cross table to the graph
window using 'textplot' and then saving the graphic output. However, the
table does not look nice in the graph output.

Is there any way the output from the console can be saved in a file and then
the output from the graph window be appended to the same file?

Thanks

Nikhil

[[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] Granger Causality in a VAR Model

2011-04-05 Thread Pfaff, Bernhard Dr.
The below email was cross-posted to R-Sig-Finance and has been answered there.  

 -Ursprüngliche Nachricht-
 Von: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] Im Auftrag von ivan
 Gesendet: Montag, 4. April 2011 20:24
 An: r-help@r-project.org
 Betreff: [R] Granger Causality in a VAR Model
 
 Dear Community,
 
 I am new to R and have a question concerning the causality () 
 test in the vars package. I need to test whether, say, the 
 variable y Granger causes the variable x, given z as a 
 control variable.
 
 I estimated the VAR model as follows: model-VAR(cbind(x,y,z),p=2)
 
 Then I did the following: causality(model, cause=y). I 
 thing this tests the Granger causality of y on the vector 
 (x,z), though. How can I implement the test for y causing x 
 controlled for z? Thus, the F-test comparing the two models 
 M1:x~lagged(x)+lagged(z) and M2:x~lagged(x)+lagged(y)+lagged(z)?
 
 Thank you in advance.
 
 Best Regards
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
*
Confidentiality Note: The information contained in this ...{{dropped:10}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Creating multiple vector/list names-novice

2011-04-05 Thread michalseneca
The exact would be for example that I shoul be able then to choose a from
abc. and I cannot do that.

--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-multiple-vector-list-names-novice-tp3425616p3427283.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] system() command in R

2011-04-05 Thread nandan amar
On 4 April 2011 16:54, rasanpreet kaur suri rasanpreet.k...@gmail.comwrote:

 Hi all,
 I have a local server insalled on my system and have to start that from
 within my R function.

 here is how I start it:

 cmd-sh start-server.sh

 system(cmd, wait=FALSE)

 My function has to start the server and proceed with further steps. The
 server starts but the further steps of the program are not executed.The
 cursor keeps waiting after the server is started.

 How r u executing further steps after starting server, meant for server
from R  ??


i tried removing the wait=FALSE, but it still keeps waiting.

 I also tried putting the start-server in a separate function and my further
 script in a separate function and then run them together, but it still
 waits. The transition from the start of server to next step is not
 happening.

 Please help. I have been stuck on this for quite some time now.

 --
 Rasanpreet Kaur

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




-- 
Amar Kumar Nandan
Karnataka, India, 560100
http://aknandan.co.nr

[[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] do not execute newline command

2011-04-05 Thread Kenn Konstabel
On Tue, Apr 5, 2011 at 10:40 AM, Lorenzo Cattarino
l.cattar...@uq.edu.au wrote:
 Hi R-users,

 To automate the creation of scripts, I converted the code (example below) 
 into a character string and wrote the object to a file:

 Repeat - 
 myvec - c(1:12)
 cat('vector= ', myvec, '\n')
 

 write (Repeat, 'yourpath/test.R')

 the problem is that one line of the code is a cat command. In the output 
 file (i.e. test.R), the newline symbol gets executed and I don't want that.

 Any idea on how to do that?

You can escape the newline symbol (i.e., write an extra \ before it):

Repeat - 
myvec - c(1:12)
cat('vector= ', myvec, '\\n')


write (Repeat, 'test.R')



 Thanks
 Lorenzo


        [[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] Euclidean Distance in R

2011-04-05 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 05/04/11 03:43, Paul Duckett wrote:
 Hi

Hi

 
 1. I have two raster files *.asc (identical size)

This question is much more appropriate for the r-sig-geo mailing list
(https://stat.ethz.ch/mailman/listinfo/r-sig-geo), which focusses on
spatial analysis / modelling in R.

I am sure you will get an answer there.

I take the liberty to CC this mail to the list - and I would encourage
you to subscribe to the mailing list.

Cheers,

Rainer


 2. The data in each contain presence or absence data in each cell
 represented by a 1 or 0 respectively
 3. I would like to take the location of each 1 (presence cell) in
 raster file 1 and measure the euclidean distance to the nearest 1
 (presence cell) in raster file 2.
 
 Obviously in some cases there will be overlap so the distance will be zero.
 
 4. I would like the output file to have each individual measurement on
 a seperate line in a single file.
 
 
 I am very new to R, so any help would be appreciated.
 
 Best regards
 Paul


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:+33 - (0)9 53 10 27 44
Cell:   +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2a0sUACgkQoYgNqgF2egqpqACfa2FdwXYwn7i+woC6RnFnURE8
p2kAn1Q833jkNyG9EfkQUIoycsdlDJWp
=aykq
-END PGP SIGNATURE-

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Euclidean Distance in R

2011-04-05 Thread ONKELINX, Thierry
Dear Paul,

The command

RSiteSearch(nearest neighbour)

Will give you the answer that you need. (The second hit is the function you 
want).

Best regards,

Thierry


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie  Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics  Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey
  

 -Oorspronkelijk bericht-
 Van: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] Namens Paul Duckett
 Verzonden: dinsdag 5 april 2011 3:44
 Aan: R-help@r-project.org
 Onderwerp: [R] Euclidean Distance in R
 
 Hi
 
 1. I have two raster files *.asc (identical size) 2. The data 
 in each contain presence or absence data in each cell 
 represented by a 1 or 0 respectively 3. I would like to take 
 the location of each 1 (presence cell) in raster file 1 and 
 measure the euclidean distance to the nearest 1 (presence 
 cell) in raster file 2.
 
 Obviously in some cases there will be overlap so the distance 
 will be zero.
 
 4. I would like the output file to have each individual 
 measurement on a seperate line in a single file.
 
 
 I am very new to R, so any help would be appreciated.
 
 Best regards
 Paul
 --
 Paul Duckett - PhD Candidate
 Conservation Genetics Lab
 E8A 264
 Biological Sciences
 Faculty of Science
 Macquarie University
 North Ryde
 NSW 2109
 http://paulduckett.redbubble.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] Saving console and graph output to same file

2011-04-05 Thread Philipp Pagel
On Tue, Apr 05, 2011 at 10:53:03AM +0530, Nikhil Abhyankar wrote:
 Hello All,
 
 How do I save the output of the R console and the graphic output to the same
 PDF file and append these to each other?
 
 I need to have a frequency table and a corresponding graph, one below the
 other in a file. I have tried with sending the cross table to the graph
 window using 'textplot' and then saving the graphic output. However, the
 table does not look nice in the graph output.
 
 Is there any way the output from the console can be saved in a file and then
 the output from the graph window be appended to the same file?

Sweave an odfWeave are very nice methods for generating reports with
both text, R code, Results from R and Graphics.

cu
Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] General binary search?

2011-04-05 Thread Matthew Dowle
Try data.table:::sortedmatch, which is implemented in C.
It requires it's input to be sorted (and doesn't check)

Stavros Macrakis macra...@alum.mit.edu wrote in message 
news:BANLkTi=j2lf5syxytv1dd4k9wr0zgk8...@mail.gmail.com...
 Is there a generic binary search routine in a standard library which

   a) works for character vectors
   b) runs in O(log(N)) time?

 I'm aware of findInterval(x,vec), but it is restricted to numeric vectors.

 I'm also aware of various hashing solutions (e.g. new.env(hash=TRUE) and
 fastmatch), but I need the greatest-lower-bound match in my application.

 findInterval is also slow for large N=length(vec) because of the O(N)
 checking it does, as Duncan Murdoch has pointed
 outhttps://stat.ethz.ch/pipermail/r-help/2008-September/174584.html:
 though
 its documentation says it runs in O(n * log(N)), it actually runs in O(n *
 log(N) + N), which is quite noticeable for largish N.  But that is easy
 enough to work around by writing a variant of findInterval which calls
 find_interv_vec without checking.

-s

 PS Yes, binary search is a one-liner in R, but I always prefer to use
 standard, fast native libraries when possible

 binarysearch - function(val,tab,L,H) {while (H=L) { M=L+(H-L) %/% 2; if
 (tab[M]val) H-M-1 else if (tab[M]val) L-M+1 else return(M)};
 return(L-1)}

 [[alternative HTML version deleted]]


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


Re: [R] RODBC excel - need to preserve (or extract) numeric column names

2011-04-05 Thread Enrico Schumann
At least for Excel 2003 on my computer (Win XP) I can persuade Excel to
treat cells like text by prepending a ' to the entry (eg, '1000). Then
sqlFetch/RODBC should import these cells as character. [But a number would
not be valid column name for a data.frame, and you may run into other
trouble. See ?make.names]

regards,
enrico



 -Ursprüngliche Nachricht-
 Von: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] Im Auftrag von Folkes, Michael
 Gesendet: Dienstag, 5. April 2011 00:05
 An: r-help@r-project.org
 Betreff: [R] RODBC excel - need to preserve (or extract) 
 numeric column names
 
 I'm using RODBC to read an excel file (not mine!).  But I'm 
 struggling to find a way to preserve the column names that 
 have a numeric value.  sqlFetch() drops the value and calls 
 them f1, f2, f3,... (ie field number).  this is a different 
 approach from read.csv, which will append V prior to the 
 numeric column name.  sqlFetch isn't so helpful. 
  
 Is there a way to get the first line of data from the excel 
 file and place it in a vector?  Perhaps I can use that method 
 and rename the dataframe column names later?
  
 thanks!
 Michael
  
 ___
 Michael Folkes
 Salmon Stock Assessment
 Canadian Dept. of Fisheries  Oceans 
 Pacific Biological Station
 3190 Hammond Bay Rd.
 Nanaimo, B.C., Canada
 V9T-6N7
 Ph (250) 756-7264 Fax (250) 756-7053  
 michael.fol...@dfo-mpo.gc.ca mailto:michael.fol...@dfo-mpo.gc.ca 
 
   [[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] grImport/ghostscript problems

2011-04-05 Thread guillaume Le Ray
Hi Al,

I'm facing exactly the same problem as you are, have you manage to fix it?
If yes I eager to know the trick.

Regards,

Guillaume

2011/3/27 Al Roark hrbuil...@hotmail.com

 Paul Murrell p.murrell at auckland.ac.nz writes:

 
  Hi
 
  On 28/03/2011 8:13 a.m., Al Roark wrote:
  
   Hi All: I've been struggling for a while trying to get grImport up
   and running.  I'm on a Windows 7 (home premium 64 bit) machine
   running R-2.12.2 along with GPL Ghostscript 9.01. I've set my Windows
   PATH variable to point to the Ghostscript \bin and \lib directories,
   and I've created the R_GSCMD environment variable pointing to
   gswin32c.exe. I don't have any experience with Ghostscript, but with
   the setup described above I can view the postscript file with the
   following command to the Windows command prompt: gswin32c.exe
   D:\Sndbx\vasarely.ps However, I can't get the PostScriptTrace()
   function to work on the same file.  Submitting
   PostScriptTrace(D:/Sndbx/vasarely.ps) gives me the error: Error in
   PostScriptTrace(D:/Sndbx/vasarely.ps) :   status 127 in running
   command 'gswin32c.exe -q -dBATCH -dNOPAUSE -sDEVICE=pswrite
   -sOutputFile=C:\Users\Al\AppData\Local\Temp\RtmppPjDAf\file5db99cb
   -sstdout=vasarely.ps.xml capturevasarely.ps' Your suggestions are
   much appreciated. Cheers, Al [[alternative HTML version deleted]]
 
  You could try running the ghostscript command that is printed in the
  error message at the Windows command prompt to see more info about the
  problem (might need to remove the '-q' so that ghostscript prints
  messages to the screen).
 
  Paul
 

 Thanks for your reply.

 Perhaps this is a Ghostscript problem. When I run the Ghostscript command,
 I'm
 met with the rather unhelpful error: 'GPL Ghostscript 9.01: Unrecoverable
 error,
 exit code 1 (occurs whether or not I remove the -q)'.

 Interestingly, if I remove the final argument (in this case,
 capturevasarely.ps)
 the Ghostscript command executes, placing a file (appears to be xml) in the
 temporary directory. However, I'm not sure what to do with this result.

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


[[alternative HTML version deleted]]

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


Re: [R] Creating multiple vector/list names-novice

2011-04-05 Thread Uwe Ligges



On 05.04.2011 09:07, michalseneca wrote:

The exact would be for example that I shoul be able then to choose a from
abc. and I cannot do that.


The is rather unhelpful for helpers without quoting what your original 
question and the answers were.


Uwe Ligges


--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-multiple-vector-list-names-novice-tp3425616p3427283.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] Problem using svm.tune

2011-04-05 Thread Uwe Ligges



On 04.04.2011 12:43, sadaf zaidi wrote:

Dear Sir,

I am stuck with a nagging problem in using R for SVM regression. My data has 5
dimensions and 400 observations. The independent variables are :
Peb, Ksub, Sub, and Xtt.
The dependent variable is: Rexp.
I tried using the svm.tune function as well as_tune(svm.), to tune the
hyper parameters: gamma, epsilon and C.

Since I am new to R, I am probably not using the svm.tune function properly. I
am getting the following error message:
Error in predict.svm(ret, xhold, decision.values=TRUE): Model is empty!
May you please help me!SADAF ZAIDI



Please show us a reproducible examples with all your code. Otherwise it 
is hard to find where the error comes from.


Uwe Ligges



[[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] Animation for pers3d

2011-04-05 Thread Grigory Alexandrovich
Hello all,

I use persp3d from the rgl-package to plot a sruface. The typical call
is persp3d(x, y, z)
With cooridinate-vectros x, y and a function-values matrix z.

Now I have different z's, say z_1,...,z_n

Question:

Is it possible to generate an animation from a sequence of such calls,
for different z's?
I would like to see how the surface is beeing changed in the time.

Thank you
Grigory Alexandrovich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] converting call objects into character

2011-04-05 Thread Samuel Le
Hi,

David and Douglas, thanks for the effort in helping me.
It seems that deparse(match.call()) is doing the trick.

I learned that the class call is not easy to handle in R.

Samuel

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: 03 April 2011 18:56
To: Douglas Bates
Cc: Samuel Le; r-help@r-project.org
Subject: Re: [R] converting call objects into character


On Apr 3, 2011, at 1:22 PM, Douglas Bates wrote:

 On Sun, Apr 3, 2011 at 11:42 AM, David Winsemius dwinsem...@comcast.net
  wrote:

 On Apr 3, 2011, at 12:14 PM, Samuel Le wrote:

 Dear all,



 I would like to log the calls to my functions. I am trying to do
 this
 using the function match.call():

 fTest-function(x)

 {  theCall-match.call()
  print(theCall)
  return(list(x=x, logf = theCall))
 }


 fTest(x=2)$x
 [1] 2
 fTest(x=2)$logf
 fTest(x = 2)
 str(fTest(x=2)$logf)
  language fTest(x = 2)

 You may want to convert that  call component to a character object,
 since:

 cat(fTest(x=2)$logf)
 Error in cat(list(...), file, sep, fill, labels, append) :
  argument 1 (type 'language') cannot be handled by 'cat'

 If you want to examine a call object you need to ensure that it is not
 evaluated.  Evaluating a number or a character string is not a problem
 because

 eval(4)

 is the same as

 4

 However, evaluating a function call should be different from the call
 itself.  As David shows, the str function is careful not to evaluate
 the call object.  (Martin and I found ourselves going around in
 circles when looking at the structure of a fitted model object that
 included a call and he kindly changed the behavior of str().)

 So you need to decide when a function, such as print(), evaluates its
 arguments or when it doesn't, which can get kind of complicated.  An
 alternative is to use match.call() repeatedly instead of trying to
 save the value, as in

 fTest
 function(x) {
print(match.call())
list(x=x, logf = match.call())
 }
 fTest(x=2)
 fTest(x = 2)
 $x
 [1] 2

 $logf
 fTest(x = 2)

 The trick there is that the value of match.call() is the unevaluated
 call whereas

 myCall - match.call()
 print(myCall)

 evaluates myCall in the call to print, thereby evaluating the function
 fTest again.

 Is this sufficiently confusing?  :-)

Yes, I am now sufficiently confused^W , ... er, motivated to look for
another route. I think the way out of the confusion is to turn the
call into text and since as.character doesn't do a very neat a job, I
would suggest instead: deparse()

  fTest - function(x) {
+print(match.call())
+list(x=x, logf = deparse(match.call()))
+ }
  fTest(x=3)$logf
fTest(x = 3)
[1] fTest(x = 3)
  cat(fTest(x=3)$logf)
fTest(x = 3)
fTest(x = 3)

cat() is a convenient test of the capacity of an object to be written
to a file. It has an append parameter that implies it could serve the
logging function requested by the OP.



 I can see theCall printed into the console, but I don't manage to
 convert it into a character to write it into a log file with other
 informations.

 Can anyone help?


David Winsemius, MD
West Hartford, CT



__ Information from ESET NOD32 Antivirus, version of virus signature 
database 6011 (20110403) __

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



__ Information from ESET NOD32 Antivirus, version of virus signature 
database 6016 (20110405) __

The message was checked by ESET NOD32 Antivirus.

http://www.eset.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] system() command in R

2011-04-05 Thread rasanpreet kaur suri
Hi,
 The further steps do not get executed because the server keeps
waiting. and they are in the same function as the start server.

if server started manually then they run normally from the R environment. Is
that what you wanted to know?  I hope I answered it .



On Tue, Apr 5, 2011 at 10:07 AM, nandan amar nandan.a...@gmail.com wrote:



 On 4 April 2011 16:54, rasanpreet kaur suri rasanpreet.k...@gmail.comwrote:

 Hi all,
 I have a local server insalled on my system and have to start that from
 within my R function.

 here is how I start it:

 cmd-sh start-server.sh

 system(cmd, wait=FALSE)

 My function has to start the server and proceed with further steps. The
 server starts but the further steps of the program are not executed.The
 cursor keeps waiting after the server is started.

 How r u executing further steps after starting server, meant for server
 from R  ??


 i tried removing the wait=FALSE, but it still keeps waiting.

 I also tried putting the start-server in a separate function and my
 further
 script in a separate function and then run them together, but it still
 waits. The transition from the start of server to next step is not
 happening.

 Please help. I have been stuck on this for quite some time now.

 --
 Rasanpreet Kaur

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




 --
 Amar Kumar Nandan
 Karnataka, India, 560100
 http://aknandan.co.nr




-- 
Rasanpreet Kaur

[[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] Adjusting p values of a matrix

2011-04-05 Thread January Weiner
 1. This is not an R question, AFAICS.

I am afraid I was not clear enough. I am wondering how to best correct
p values that are stored in a matrix, or, in more general: how to
apply a function that takes a vector as an argument to the upper right
(or, equivalently, lower left) half of a matrix, excluding the
diagonal. for... in loop is a trivial, but slow and not elegant
solution.

Naturally, what correction should I use in case of tests which clearly
are not independent is another matter, and I agree on that with you.

Best regards,

January


 2. Sounds like a research topic.  I don't think there's a meaningful
 simple answer. I suspect it strongly depends on the model and context.

 -- Bert

 On Mon, Apr 4, 2011 at 8:02 AM, January Weiner
 january.wei...@mpiib-berlin.mpg.de wrote:
 Dear all,

 I have an n x n matrix of p-values. The matrix is symmetrical, as it
 describes the each against each p values of correlation
 coefficients.

 How can I best correct the p values of the matrix? Notably, the total
 number of the tests performed is n(n-1)/2, since I do not test the
 correlation of each variable with itself. That means, I only want to
 correct one half of the matrix, not including the diagonal. Therefore,
 simply writing

 pmat - p.adjust( pmat, method= fdr )
 # where pmat is an n x n matrix

 ...doesn't cut it.

 Of course, I can turn the matrix in to a three column data frame with
 n(n-1)/2 rows, but that is slow and not elegant.

 regards,
 j.

 --
  Dr. January Weiner 3 --
 Max Planck Institute for Infection Biology
 Charitéplatz 1
 D-10117 Berlin, Germany
 Web   : www.mpiib-berlin.mpg.de
 Tel     : +49-30-28460514

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




 --
 Men by nature long to get on to the ultimate truths, and will often
 be impatient with elementary studies or fight shy of them. If it were
 possible to reach the ultimate truths without the elementary studies
 usually prefixed to them, these would not be preparatory studies but
 superfluous diversions.

 -- Maimonides (1135-1204)

 Bert Gunter
 Genentech Nonclinical Biostatistics




-- 
 Dr. January Weiner 3 --
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin, Germany
Web   : www.mpiib-berlin.mpg.de
Tel     : +49-30-28460514

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] frailty

2011-04-05 Thread hsr
Hi R-users

I spend a lot of time searching on the web but I didn’t found a clear
answer.
I have some doubts with 'frailty' function of 'survival' package.

The following model with the function R ‘coxph’ was fitted: 

modx - coxph(Surv(to_stroke, stroke) ~ age + sbp + dbp + sex +
frailty(center,distribution = gamma, method='aic'), data=datax)

Then I get survival (eg to 10 years) for the mean of the covariates:

survfit1 - survfit(modx)
timesele- 3652.25
tab - as.data.frame(cbind(survfit1$time, survfit1$surv))
names(tab) - c(time, surv)
meansurv - tab[tab$time==max(tab$time[tab$timetimesele]), ]$surv

‘survfit.coxph’ allows the entry of 'newdata' with the characteristics of
individuals that I want. This function doesn’t allow entering a value of
'center' (frailty term). However, when it performs the linear predictor
(modx$linear.predictors) it takes into account the frailty calculated for
each ‘center’ and applies to the value of the individual. 

My thought is: By extracting the average survival is not necessary to
consider the frailty term performed for each ‘center’ because the expected
value of the frailty terms is 0 (some centers will have more frailty and
other ones less). However, as each individual belongs to one ‘center’ it is
needed to take into account the frailty of that ‘center’ to perform the
linear predictor.

My doubt is: How the ‘survfit.coxph’ calculates the survival function with a
frailty term? 

Am I right with my thought ?
Can anybody help me with my doubt?

Thanks in adavance.





--
View this message in context: 
http://r.789695.n4.nabble.com/frailty-tp3427452p3427452.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] Adjusting p values of a matrix

2011-04-05 Thread January Weiner
        as.matrix(p.adjust(as.dist(pmat)))

Perfect! Thanks.

j.



 Benno

 On 4.Apr.2011, at 17:02, January Weiner wrote:

 Dear all,

 I have an n x n matrix of p-values. The matrix is symmetrical, as it
 describes the each against each p values of correlation
 coefficients.

 How can I best correct the p values of the matrix? Notably, the total
 number of the tests performed is n(n-1)/2, since I do not test the
 correlation of each variable with itself. That means, I only want to
 correct one half of the matrix, not including the diagonal. Therefore,
 simply writing

 pmat - p.adjust( pmat, method= fdr )
 # where pmat is an n x n matrix

 ...doesn't cut it.

 Of course, I can turn the matrix in to a three column data frame with
 n(n-1)/2 rows, but that is slow and not elegant.

 regards,
 j.

 --
  Dr. January Weiner 3 --
 Max Planck Institute for Infection Biology
 Charitéplatz 1
 D-10117 Berlin, Germany
 Web   : www.mpiib-berlin.mpg.de
 Tel     : +49-30-28460514

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






-- 
 Dr. January Weiner 3 --
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin, Germany
Web   : www.mpiib-berlin.mpg.de
Tel     : +49-30-28460514

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 in splitting a list

2011-04-05 Thread Lars Bishop
Dear R users,

Let's say I have a list with components being 'm' matrices (as exemplified
in the mylist object below). Now, I'd like to subset this list based on an
index vector, which will partition each matrix 'm' in 2 sub-matrices. My
questions are:

1. Is there an elegant way to have the results shown in mylist2 for an
arbitrary number of matrices in mylist?

2. The column names are 'lost' for mylist2[[2]] and mylist2[[4]] (but not
for mylist2[[1]] and mylist2[[3]]). Is there a way to keep the column names
in the results of mylist2?

mylist - list(matrix(1:9,3,3), matrix(10:18,3,3))
colnames(mylist[[1]])=c('x1','x2','x3')
colnames(mylist[[2]])=c('x4','x5','x6')
index - list(2)
index[[1]] - c(TRUE,FALSE,TRUE)
index[[2]] - c(FALSE,TRUE,TRUE)
mylist2 - list(as.matrix(mylist[[1]][,index[[1]]]),
as.matrix(mylist[[1]][,!index[[1]]]),
as.matrix(mylist[[2]][,index[[2]]]),
as.matrix(mylist[[2]][,!index[[2]]]))
Thanks for any help,
Lars.

[[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] gap.barplot doesn't support data arrays?

2011-04-05 Thread Jim Lemon

On 04/04/2011 11:39 PM, Andrew D. Steen wrote:

I am trying to make a barplot with a broken axis using gap.barplot (in the
indispensable plotrix package).


Aww, gee, you've won me.


This works well when the data is a vector:


twogrp-c(rnorm(10)+4,rnorm(10)+20)
gap.barplot(twogrp,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=Group

values,main=Barplot with gap)

But when the data is an array (for a bar plot with multiple series) I get an
error and a strange plot with no y-tics and bars stretching downwards, as if
all the values were negative:


twogrp2-array(twogrp, dim=c(2,5))


gap.barplot(twogrp2,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=Group
values,main=Barplot with gap)

Error in rect(xtics[bigones] - halfwidth, botgap, xtics[bigones] +
halfwidth,  :
   cannot mix zero-length and non-zero-length coordinates

However, the main title and axis labels do appear correctly.

Are data arrays unsupported for gap.barplot, or am I missing something?


Hi Drew,
You are right, as is Peter, gap.barplot doesn't support arrays, only 
vectors (I'll fix the docs). However, it wasn't too hard to whip up a 
rough but perhaps serviceable fix in the attached function. You may need 
to do some mods to the function to get exactly what you want. Try this:


# your twogrp2 left out the high values
twogrp2-array(twogrp,dim=c(2,10))
source(gap.barp.R)
gap.barp(twogrp2,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),
 xtics=1:10,ylab=Groupvalues,main=Barplot with gap,col=2:3)

gap.barp returns the modified y values so that you can include the error 
bars.


To paraphrase the immortal P.J. O'Rourke,

Perhaps R users shouldn't do some things in plots, but they certainly 
can do them


Jim
gap.barp-function (y,gap,xaxlab,xtics,yaxlab,ytics,xlim=NA,ylim=NA,
 xlab=NULL,ylab=NULL,main=NULL,horiz=FALSE,col=NULL,...) {
 if (missing(y)) stop(y values required)
 if(missing(xtics)) xtics - 1:length(y)
 if (missing(gap)) stop(gap must be specified)
 if (is.null(ylab)) ylab - deparse(substitute(y))
 if (is.null(col)) col - color.gradient(c(0,1),c(0,1,0),c(1,0),length(y))
 else if(length(col)  length(y)) rep(col,length.out=length(y))
 littleones - which(y = gap[1])
 bigones - which(y = gap[2])
 valid.y-y[!is.na(y)]
 if(any(valid.y  gap[1]  valid.y  gap[2]))
  warning(gap includes some values of y)
 gapsize - gap[2] - gap[1]
 if(missing(xaxlab)) xaxlab - as.character(xtics)
 if(is.na(xlim[1])) xlim - range(xtics)
 if(is.na(ylim[1])) ylim - c(min(valid.y),max(valid.y) - gapsize)
 if(missing(ytics)) ytics - pretty(y)
 bigtics-which(yticsgap[2])
 if(missing(yaxlab)) yaxlab - ytics
 ytics[bigtics]-ytics[bigtics]-gapsize
 y[bigones]-y[bigones]-gapsize
 barp(y,names.arg=xaxlab,col=col,xlab=xlab,ylab=ylab,height.at=ytics,
  height.lab=yaxlab,main=main,...)
 axis.break(2,gap[1],style=gap)
 invisible(y)
}
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] converting call objects into character

2011-04-05 Thread Gabor Grothendieck
On Sun, Apr 3, 2011 at 12:14 PM, Samuel Le samuel...@srlglobal.com wrote:
 Dear all,



 I would like to log the calls to my functions. I am trying to do this using 
 the function match.call():



 fTest-function(x)

 {

      theCall-match.call()

      print(theCall)

      return(x)

 }



 fTest(2)

 fTest(x = 2)

 [1] 2



 I can see theCall printed into the console, but I don't manage to convert 
 it into a character to write it into a log file with other informations.


See ?trace

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Error in color2D.matplot : Error in plot.new() : figure margins too large

2011-04-05 Thread Jim Lemon

Hi all,
Just to let you know that the error was in the calculation (and the 
error message maybe peculiar to the original poster's system), not 
color2D.matplot. The message sent to the original poster was long and 
not very meaningful to those who didn't get the data and code (i.e. 
everybody except me).


Jim

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


Re: [R] Animation for pers3d

2011-04-05 Thread Duncan Murdoch

On 11-04-05 5:43 AM, Grigory Alexandrovich wrote:

Hello all,

I use persp3d from the rgl-package to plot a sruface. The typical call
is persp3d(x, y, z)
With cooridinate-vectros x, y and a function-values matrix z.

Now I have different z's, say z_1,...,z_n

Question:

Is it possible to generate an animation from a sequence of such calls,
for different z's?
I would like to see how the surface is beeing changed in the time.


Yes, you can do animations.  See example(persp3d) for one that changes 
the viewpoint.  If you want to change the content of the plot, save the 
result of persp3d() on the first call, e.g.


objs - persp3d( ... )
surface - objs[surface]

then delete and re-plot the surface element:

rgl.pop(id=surface)
# compute new x y z
surface - surface3d(x, y, z)

If the scale changes during the animation it's likely to look ugly, so 
set the limits in the persp3d call (or turn off the axes).


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] gap.barplot doesn't support data arrays?

2011-04-05 Thread Andrew D. Steen
Jim,
That works great.  Thanks much for the quick help.

Cheers,
Drew

 -Original Message-
 From: Jim Lemon [mailto:j...@bitwrit.com.au]
 Sent: Tuesday, April 05, 2011 2:12 PM
 To: Andrew D. Steen
 Cc: r-help@r-project.org
 Subject: Re: [R] gap.barplot doesn't support data arrays?
 
 On 04/04/2011 11:39 PM, Andrew D. Steen wrote:
  I am trying to make a barplot with a broken axis using gap.barplot
 (in
  the indispensable plotrix package).
 
 Aww, gee, you've won me.
 
  This works well when the data is a vector:
 
  twogrp-c(rnorm(10)+4,rnorm(10)+20)
 
 gap.barplot(twogrp,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=
  Group
  values,main=Barplot with gap)
 
  But when the data is an array (for a bar plot with multiple series) I
  get an error and a strange plot with no y-tics and bars stretching
  downwards, as if all the values were negative:
 
  twogrp2-array(twogrp, dim=c(2,5))
 
 
 gap.barplot(twogrp2,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),ylab=
  Group
  values,main=Barplot with gap)
 
  Error in rect(xtics[bigones] - halfwidth, botgap, xtics[bigones] +
  halfwidth,  :
 cannot mix zero-length and non-zero-length coordinates
 
  However, the main title and axis labels do appear correctly.
 
  Are data arrays unsupported for gap.barplot, or am I missing
 something?
 
 Hi Drew,
 You are right, as is Peter, gap.barplot doesn't support arrays, only
 vectors (I'll fix the docs). However, it wasn't too hard to whip up a
 rough but perhaps serviceable fix in the attached function. You may
 need to do some mods to the function to get exactly what you want. Try
 this:
 
 # your twogrp2 left out the high values
 twogrp2-array(twogrp,dim=c(2,10))
 source(gap.barp.R)
 gap.barp(twogrp2,gap=c(8,16),xlab=Index,ytics=c(3,6,17,20),
   xtics=1:10,ylab=Groupvalues,main=Barplot with gap,col=2:3)
 
 gap.barp returns the modified y values so that you can include the
 error bars.
 
 To paraphrase the immortal P.J. O'Rourke,
 
 Perhaps R users shouldn't do some things in plots, but they certainly
 can do them
 
 Jim

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


Re: [R] Help in splitting a list

2011-04-05 Thread Henrique Dallazuanna
Try this:

mapply('[', lapply(mylist, as.data.frame), c(index, lapply(index,
`!`)), SIMPLIFY = FALSE)


On Tue, Apr 5, 2011 at 7:46 AM, Lars Bishop lars...@gmail.com wrote:
 Dear R users,

 Let's say I have a list with components being 'm' matrices (as exemplified
 in the mylist object below). Now, I'd like to subset this list based on an
 index vector, which will partition each matrix 'm' in 2 sub-matrices. My
 questions are:

 1. Is there an elegant way to have the results shown in mylist2 for an
 arbitrary number of matrices in mylist?

 2. The column names are 'lost' for mylist2[[2]] and mylist2[[4]] (but not
 for mylist2[[1]] and mylist2[[3]]). Is there a way to keep the column names
 in the results of mylist2?

 mylist - list(matrix(1:9,3,3), matrix(10:18,3,3))
 colnames(mylist[[1]])=c('x1','x2','x3')
 colnames(mylist[[2]])=c('x4','x5','x6')
 index - list(2)
 index[[1]] - c(TRUE,FALSE,TRUE)
 index[[2]] - c(FALSE,TRUE,TRUE)
 mylist2 - list(as.matrix(mylist[[1]][,index[[1]]]),
                as.matrix(mylist[[1]][,!index[[1]]]),
                as.matrix(mylist[[2]][,index[[2]]]),
                as.matrix(mylist[[2]][,!index[[2]]]))
 Thanks for any help,
 Lars.

        [[alternative HTML version deleted]]

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




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

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


Re: [R] lattice: how to center a subtitle?

2011-04-05 Thread Deepayan Sarkar
On Tue, Apr 5, 2011 at 6:12 AM, David Scott d.sc...@auckland.ac.nz wrote:

[...]

 I am not sure where I read it and I can't find it again, but my
 understanding is that expressions using bquote with lattice need to be
 enclosed in as.expression() to work. That is in contrast to what happens in
 base graphics.

 Here is a simple example.

 a - 2
 plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
 require(lattice)
 xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
 xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

 Which produces:

 a - 2
 plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
 require(lattice)
 Loading required package: lattice
 xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
 Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond = list(c(1L,  :
  object 'alpha' not found
 xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

 Using expression() rather than as.expression() doesn't produce the desired
 affect. Try it yourself.

 As to why this is the case .

Let's see: ?xyplot says

  'main': Typically a character string or expression describing
  the main title to be placed on top of each page. [...]

So, lattice is fairly explicit, by R standards, in requiring 'main' to
be character or expression. On the other hand, ?title says

 The labels passed to 'title' can be character strings or language
 objects (names, calls or expressions), or [...]

so it additionally accepts names and calls.

Now, we have

 a - 2
 foo - bquote(alpha == .(a))

 foo # Looks OK
alpha == 2
 mode(foo) # But
[1] call
 is.expression(foo) # not an expression
[1] FALSE

 is.expression(expression(foo)) ## YES, but
[1] TRUE
 expression(foo) ## not what we want
expression(foo)

 is.expression(as.expression(foo))
[1] TRUE
 as.expression(foo) ## This IS what we want
expression(alpha == 2)

So I submit that lattice is behaving exactly as suggested by its documentation.

Now you would naturally argue that this is hiding behind
technicalities, and if call objects work for plot(), it should work
for lattice as well. But watch this:

 plot(1:10, main = foo) # works perfectly

 arglist - list(1:10, main = foo)
 arglist # Looks like what we want
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10

$main
alpha == 2

 do.call(plot, arglist)
Error in as.graphicsAnnot(main) : object 'alpha' not found

...which I would say is unexpected behaviour, if not a bug.

The moral of the story is that unevaluated calls are dangerous objects
(try this one out for fun:

foo - bquote(q(.(x)), list(x = no))
do.call(plot, list(1:10, main = foo))

), and carrying them around is not a good idea.

Lattice does use the do.call paradigm quite a bit, and I think it
might be quite difficult to fix it up to handle non-expression
language objects (which will still not fix the type of problem shown
above).

-Deepayan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] system() command in R

2011-04-05 Thread Mike Marchywka












 Date: Tue, 5 Apr 2011 13:37:12 +0530
 From: nandan.a...@gmail.com
 To: rasanpreet.k...@gmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] system() command in R

 On 4 April 2011 16:54, rasanpreet kaur suri wrote:

  Hi all,
  I have a local server insalled on my system and have to start that from
  within my R function.
 
  here is how I start it:
 
  cmd-sh start-server.sh
 
  system(cmd, wait=FALSE)
 
  My function has to start the server and proceed with further steps. The
  server starts but the further steps of the program are not executed.The
  cursor keeps waiting after the server is started.
 
  How r u executing further steps after starting server, meant for server
 from R ??


 i tried removing the wait=FALSE, but it still keeps waiting.
 
  I also tried putting the start-server in a separate function and my further
  script in a separate function and then run them together, but it still
  waits. The transition from the start of server to next step is not
  happening.
 
  Please help. I have been stuck on this for quite some time now.
 
  --

I hadn't done this in R but expect to do so soon.
I just got done with some java code to do something similar
and you can expect in any implementation these things will be 
system dependent. It often helps to have simple test cases
to isolate the problem. Here I made a tst script called foo
that takes a minute or so to exevute and generates some output.

If I type
system(./foo,wait=F) 

the prompt comes back right away but stdout seems to still
go to my console and maybe stdin is not redicrected either
and it could eat your input ( no idea, but this is probably not what you
want).

I did try this that could fix your problem, on debian anyway
it seems to work,

system(nohup ./foo )

you can man nohup for details. 














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



 --
 Amar Kumar Nandan
 Karnataka, India, 560100
 http://aknandan.co.nr

 [[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] how to label customized y axis when using lattice parallel parameter common.scale=TRUE

2011-04-05 Thread Pengcheng Yang

Dear all,

When I use parallel function in lattice package, I want to label the 
y-axis with customized numbers. Like this:


parallel(~iris[1:4] | Species, iris,horiz=FALSE,common.scale=TRUE,
scales=list(y=list(at=c(0,2,3

But only Min label in the y-axis, nothing happened. Could anyone help me?

Thanks.
Regards,

Pengcheng Yang

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Value between which elements of a vector?

2011-04-05 Thread beatleb
Dear R-useRs,

I am looking for a why to perform the following:

specialweeks-c(0,2,5,12,18,19,20)
weeks-c(1:30)

Now I would like that for every week it is even between which elements of
vector special weeks it is.
For weeks after 20, the value NA or 20, or even 20-30is fine.

Thus for 
week 1: 0-2
week 2: 2-5
week 3: 2-5
week 4: 2-5
week 5: 5-12 
ect 

It is not relevant if those intervals are captured in a matrix, in a vector
or whatever. 

I hope that you can help me!

With best regards,

Brenda Grondman



--
View this message in context: 
http://r.789695.n4.nabble.com/Value-between-which-elements-of-a-vector-tp3427751p3427751.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] Time series example in Koop

2011-04-05 Thread Ravi Kulkarni
I am trying to reproduce the output of a time series example in Koop's book
Analysis of Financial Data. Koop does the example in Excel and I used the
ts function followed by the lm function. 
I am unable to get the exact coefficients that Koop gives - my coefficients
are slightly different.
After loading the data file and attaching the frame, my code reads:

 y = ts(m.cap)
 x = ts(oil.price)
 d = ts.union(y,x,x1=lag(x,-1),x2=lag(x,-2),x3=lag(x,-3),x4=lag(x,-4))
 mod1 = lm(y~x+x1+x2+x3+x4, data=d)
 summary(mod1)

Koop gives an intercept of 92001.51, while the code above gives 91173.32.
The other coefficients are also  slightly off.

This is the example in Table 8.3 of Koop. I also attach a plain text version
of the tab separated file badnews.txt.
http://r.789695.n4.nabble.com/file/n3427897/badnews.txt badnews.txt 

Any light on why I do not get Koop's coefficients is most welcome...

Ravi

--
View this message in context: 
http://r.789695.n4.nabble.com/Time-series-example-in-Koop-tp3427897p3427897.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] Confidence interval for the difference between proportions - method used in prop.test()

2011-04-05 Thread Stefanie Von Felten
Hello,

Does anyone know which method from Newcombe (1998)* is implemented in prop.test 
for comparing two proportions?
I would guess it is the method based on the Wilson score (for single 
proportion), with and without continuity correction  for prop.test(..., 
correct=FALSE) and prop.test(..., correct=TRUE). These methods would correspond 
to no. 10 and 11 tested in Newcombe, respectively. Can someone confirm this? If 
not, which other methods are implemented by prop.test?

* Newcombe R.G. (1998) Two-Sided Confidence Intervals for the Single 
Proportion: Comparison of Seven Methods.  Statistics in Medicine  *17*, 857-872.

There is also the function ci.pd() from the R-package Epi, which should 
implement method no. 10 from Newcombe. However, prop.test(..., correct=FALSE) 
and ci.pd do not give the same result if I do the following:

successes - c(21, 41)
total - c(345, 345)
prop.test(successes, total, correct=FALSE)
library(Epi)
ci.pd(matrix(c(successes, total-successes),ncol=2, byrow=TRUE))

Can someone explain why?

Best wishes
Stefanie von Felten


Stefanie von Felten, PhD
Statistician
Clinical Trial Unit, CTU
University Hospital Basel
Schanzenstrasse 55
CH-4031 Basel

Phone: ++41(0)61 556 54 98

[[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] lattice xscale.components: different ticks on top/bottom axis

2011-04-05 Thread Deepayan Sarkar
On Sat, Apr 2, 2011 at 1:29 AM,  boris.vasil...@forces.gc.ca wrote:

 On Fri, Mar 11, 2011 at 12:28 AM,
 boris.vasil...@forces.gc.ca wrote:
  Good afternoon,
 
  I am trying to create a plot where the bottom and top axes have the
  same scale but different tick marks.  I tried user-defined
  xscale.component function but it does not produce desired results.
  Can anybody suggest where my use of xscale.component
  function is incorrect?
 
  For example, the code below tries to create a plot where horizontal
  axes limits are c(0,10), top axis has ticks at odd integers, and
  bottom axis has ticks at even integers.
 
  library(lattice)
 
  df - data.frame(x=1:10,y=1:10)
 
  xscale.components.A - function(...,user.value=NULL) {
   # get default axes definition list; print user.value
   ans - xscale.components.default(...)
   print(user.value)
 
   # start with the same definition of bottom and top axes
   ans$top - ans$bottom
 
   # - bottom labels
   ans$bottom$labels$at - seq(0,10,by=2)
   ans$bottom$labels$labels - paste(B,seq(0,10,by=2),sep=-)
 
   # - top labels
   ans$top$labels$at - seq(1,9,by=2)
   ans$top$labels$labels - paste(T,seq(1,9,by=2),sep=-)
 
   # return axes definition list
   return(ans)
  }
 
  oltc - xyplot(y~x,data=df,
 
  scales=list(x=list(limits=c(0,10),at=0:10,alternating=3)),
                xscale.components=xscale.components.A,
                user.value=1)
  print(oltc)
 
  The code generates a figure with incorrectly placed bottom and top
  labels.  Bottom labels B-0, B-2, ... are at 0, 1, ... and top
  labels T-1, T-3, ... are at 0, 1, ...  When axis-function runs out
  of labels, it replaces labels with NA.
 
  It appears that lattice uses top$ticks$at to place labels and
  top$labels$labels for labels.  Is there a way to override this
  behaviour (other than to expand the labels$labels vector to be as
  long as ticks$at vector and set necessary elements to )?

 Well, top|bottom$ticks$at is used to place the ticks, and
 $labels$at is used to place the labels. They should typically
 be the same, but you have changed one and not the other.
 Everything seems to work if you set $ticks$at to the same
 values as $labels$at:


     ##  - bottom labels
 +   ans$bottom$ticks$at - seq(0,10,by=2)
     ans$bottom$labels$at - seq(0,10,by=2)
     ans$bottom$labels$labels - paste(B,seq(0,10,by=2),sep=-)

     ##  - top labels
 +   ans$top$ticks$at - seq(1,9,by=2)
     ans$top$labels$at - seq(1,9,by=2)
     ans$top$labels$labels - paste(T,seq(1,9,by=2),sep=-)


  Also, can user-parameter be passed into xscale.components()
  function? (For example, locations and labels of ticks on the top
  axis).  In the  code above, print(user.value) returns NULL even
  though in the xyplot() call user.value is 1.

 No. Unrecognized arguments are passed to the panel function
 only, not to any other function. However, you can always
 define an inline
 function:

 oltc - xyplot(y~x,data=df,
                scales=list(x=list(limits=c(0,10), at = 0:10,
                            alternating=3)),
                xscale.components = function(...)
                            xscale.components.A(..., user.value=1))

 Hope that helps (and sorry for the late reply).

 -Deepayan


 Deepyan,

 Thank you very much for your reply.  It makes things a bit clearer.

 It other words in the list prepared by xscale.components(), vectors
 top|bottom$ticks$at and top|bottom$labels$at must be the same.
 If only every second tick is to be labelled then every second label
 should be set explicitly to empty strings:

Now when you put it that way, the current behaviour does seem wrong (I
didn't read your original post carefully enough). I guess this was one
of the not-yet-implemented things mentioned in the Details section of
?xscale.components.default.

I have added support for different ticks$at and labels$at in the SVN
sources in r-forge. You can test it from there (your original code
works as expected). I won't make a new release on CRAN until after R
2.13 is released (we are almost in code freeze now).

-Deepayan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Value between which elements of a vector?

2011-04-05 Thread andrija djurovic
Hi:

try this and have a look at ?cut just to change the lables:

data.frame(
weeks=sprintf('%s %d','week',1:30),
specialweeks=cut(1:30,c(0,2,5,12,18,19,20),right = FALSE))

Andrija

On Tue, Apr 5, 2011 at 1:20 PM, beatleb rhelpfo...@gmail.com wrote:

 Dear R-useRs,

 I am looking for a why to perform the following:

 specialweeks-c(0,2,5,12,18,19,20)
 weeks-c(1:30)

 Now I would like that for every week it is even between which elements of
 vector special weeks it is.
 For weeks after 20, the value NA or 20, or even 20-30is fine.

 Thus for
 week 1: 0-2
 week 2: 2-5
 week 3: 2-5
 week 4: 2-5
 week 5: 5-12
 ect

 It is not relevant if those intervals are captured in a matrix, in a vector
 or whatever.

 I hope that you can help me!

 With best regards,

 Brenda Grondman



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Value-between-which-elements-of-a-vector-tp3427751p3427751.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.


Re: [R] how to label customized y axis when using lattice parallel parameter common.scale=TRUE

2011-04-05 Thread Deepayan Sarkar
On Tue, Apr 5, 2011 at 4:39 PM, Pengcheng Yang peng...@gmail.com wrote:
 Dear all,

 When I use parallel function in lattice package, I want to label the y-axis
 with customized numbers. Like this:

 parallel(~iris[1:4] | Species, iris,horiz=FALSE,common.scale=TRUE,
    scales=list(y=list(at=c(0,2,3

Parallel does not directly support that, and will insist on scaling
the data. However, you can control the scaling (using 'lower' and
'upper'), and override a couple of other arguments to get what you
want:

parallel(~iris[1:4] | Species, iris,
 xlim = extendrange(range(iris[1:4])),
 scales = list(x = list(at = NULL, labels = NULL)),
 lower = 0, upper = 1)

This is for horizontal.axis = TRUE, adjust accordingly for FALSE.

-Deepayan


 But only Min label in the y-axis, nothing happened. Could anyone help me?

 Thanks.
 Regards,

 Pengcheng Yang

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Time series example in Koop

2011-04-05 Thread Gabor Grothendieck
On Tue, Apr 5, 2011 at 8:35 AM, Ravi Kulkarni ravi.k...@gmail.com wrote:
 I am trying to reproduce the output of a time series example in Koop's book
 Analysis of Financial Data. Koop does the example in Excel and I used the
 ts function followed by the lm function.
 I am unable to get the exact coefficients that Koop gives - my coefficients
 are slightly different.
 After loading the data file and attaching the frame, my code reads:

 y = ts(m.cap)
 x = ts(oil.price)
 d = ts.union(y,x,x1=lag(x,-1),x2=lag(x,-2),x3=lag(x,-3),x4=lag(x,-4))
 mod1 = lm(y~x+x1+x2+x3+x4, data=d)
 summary(mod1)

 Koop gives an intercept of 92001.51, while the code above gives 91173.32.
 The other coefficients are also  slightly off.

 This is the example in Table 8.3 of Koop. I also attach a plain text version
 of the tab separated file badnews.txt.
 http://r.789695.n4.nabble.com/file/n3427897/badnews.txt badnews.txt

 Any light on why I do not get Koop's coefficients is most welcome...


It looks like he erroneously left out the first point.

 URL - http://r.789695.n4.nabble.com/file/n3427897/badnews.txt;
 BAD - read.table(URL, header = TRUE)
 library(dyn)
 dyn$lm(m.cap ~ lag(oil.price, -(0:4)), as.zoo(BAD))

Call:
lm(formula = dyn(m.cap ~ lag(oil.price, -(0:4))), data = as.zoo(BAD))

Coefficients:
(Intercept)  lag(oil.price, -(0:4))1  lag(oil.price, -(0:4))2
   91173.32  -131.99  -449.86
lag(oil.price, -(0:4))3  lag(oil.price, -(0:4))4  lag(oil.price, -(0:4))5
-422.52  -187.10   -27.77


 # without first point
 dyn$lm(m.cap ~ lag(oil.price, -(0:4)), tail(as.zoo(BAD), -1))

Call:
lm(formula = dyn(m.cap ~ lag(oil.price, -(0:4))), data = tail(as.zoo(BAD),
-1))

Coefficients:
(Intercept)  lag(oil.price, -(0:4))1  lag(oil.price, -(0:4))2
92001.5   -145.0   -462.1
lag(oil.price, -(0:4))3  lag(oil.price, -(0:4))4  lag(oil.price, -(0:4))5
 -424.5   -199.5-36.9




-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Confidence interval for the difference between proportions - method used in prop.test()

2011-04-05 Thread Joshua Wiley
Hi Stefanie,

Just to be clear, we are talking about differences in the third or
lower decimal place (at least with R version 2.13.0 alpha (2011-03-17
r54849), Epi_1.1.20).  This strikes me as small enough that both
functions may be implementing the same method, but maybe slightly
different ways of going about it?

If you are really concerned and need to know *exactly*, look at the
source code for both functions.  In case you did not know, if you type
the function name at the console with parentheses or any arguments,
just like:

 prop.test
 ci.pd

it will show the actual function code.  It looks to me like both of
them are implemented purely in R, and without even calling any other
complex functions (at least based on a quick glance through).  This
means if you have the Newscomb text, you should be able to sit down
and go through the code step by step comparing it.

Cheers,

Josh

FYI, you can use a matrix with prop.test, and then its transpose for ci.pd.
##
mymat - cbind(Successes = c(21, 41), Failures = c(345, 345) - c(21, 41))
require(Epi)
results - list(prop.test(mymat, correct=FALSE), ci.pd(t(mymat)))
results[[1]][[conf.int]] - results[[2]][6:7]

On Tue, Apr 5, 2011 at 3:38 AM, Stefanie Von Felten svonfel...@uhbs.ch wrote:
 Hello,

 Does anyone know which method from Newcombe (1998)* is implemented in 
 prop.test for comparing two proportions?
 I would guess it is the method based on the Wilson score (for single 
 proportion), with and without continuity correction  for prop.test(..., 
 correct=FALSE) and prop.test(..., correct=TRUE). These methods would 
 correspond to no. 10 and 11 tested in Newcombe, respectively. Can someone 
 confirm this? If not, which other methods are implemented by prop.test?

 * Newcombe R.G. (1998) Two-Sided Confidence Intervals for the Single 
 Proportion: Comparison of Seven Methods.  Statistics in Medicine  *17*, 
 857-872.

 There is also the function ci.pd() from the R-package Epi, which should 
 implement method no. 10 from Newcombe. However, prop.test(..., correct=FALSE) 
 and ci.pd do not give the same result if I do the following:

 successes - c(21, 41)
 total - c(345, 345)
 prop.test(successes, total, correct=FALSE)
 library(Epi)
 ci.pd(matrix(c(successes, total-successes),ncol=2, byrow=TRUE))

 Can someone explain why?

 Best wishes
 Stefanie von Felten


 Stefanie von Felten, PhD
 Statistician
 Clinical Trial Unit, CTU
 University Hospital Basel
 Schanzenstrasse 55
 CH-4031 Basel

 Phone: ++41(0)61 556 54 98

        [[alternative HTML version deleted]]

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




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


Re: [R] RODBC excel - need to preserve (or extract) numeric column names

2011-04-05 Thread David Winsemius


On Apr 5, 2011, at 4:53 AM, Enrico Schumann wrote:

At least for Excel 2003 on my computer (Win XP) I can persuade  
Excel to

treat cells like text by prepending a ' to the entry (eg, '1000). Then
sqlFetch/RODBC should import these cells as character. [But a number  
would

not be valid column name for a data.frame, and you may run into other
trouble. See ?make.names]



If the problem is that Excel is failing to treat cells as text, then  
you could also try selecting the cells, then using the Format/Cells  
panel to specify Text rather than General. But as I suggested  
before, I suspect the problem is you effort to defeat the usual  
checking for valid R names.


--
David.



regards,
enrico




-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] Im Auftrag von Folkes, Michael
Gesendet: Dienstag, 5. April 2011 00:05
An: r-help@r-project.org
Betreff: [R] RODBC excel - need to preserve (or extract)
numeric column names

I'm using RODBC to read an excel file (not mine!).  But I'm
struggling to find a way to preserve the column names that
have a numeric value.  sqlFetch() drops the value and calls
them f1, f2, f3,... (ie field number).  this is a different
approach from read.csv, which will append V prior to the
numeric column name.  sqlFetch isn't so helpful.

Is there a way to get the first line of data from the excel
file and place it in a vector?  Perhaps I can use that method
and rename the dataframe column names later?

thanks!
Michael

___
Michael Folkes
Salmon Stock Assessment
Canadian Dept. of Fisheries  Oceans
Pacific Biological Station
3190 Hammond Bay Rd.
Nanaimo, B.C., Canada
V9T-6N7
Ph (250) 756-7264 Fax (250) 756-7053
michael.fol...@dfo-mpo.gc.ca mailto:michael.fol...@dfo-mpo.gc.ca

[[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, reproducible code.


Re: [R] system() command in R

2011-04-05 Thread Jeff Newmiller
The ampersand is a good idea, but nohup is best avoided in scripts. Rather the 
server itself should handle the transition to daemon status to avoid ending up 
with many duplicate server processes running.
---
Jeff Newmiller The . . Go Live...
DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Mike Marchywka marchy...@hotmail.com wrote:

_
 Date: Tue, 5 Apr 2011 13:37:12 +0530  From: nandan.a...@gmail.com  To: 
 rasanpreet.k...@gmail.com  CC: r-help@r-project.org  Subject: Re: [R] 
 system() command in R   On 4 April 2011 16:54, rasanpreet kaur suri wrote: 
Hi all,   I have a local server insalled on my system and have to 
 start that from   within my R function. here is how I start it:   
   cmd-sh start-server.sh system(cmd, wait=FALSE) My 
 function has to start the server and proceed with further steps. The   
 server starts but the further steps of the program are not executed.The   
 cursor keeps waiting after the server is started. How r u executing 
 further steps after starting server, meant for server  from R ??i 
 tried removing the wait=FALSE, but it still keeps waiting. I also 
 tried putting the start-server in a separate function and my further   
 script in a separate function and then run them together, but it still   
 waits. The transitio
 n from
the start of server to next step is not   happening. Please help. I 
have been stuck on this for quite some time now. -- I hadn't done this 
in R but expect to do so soon. I just got done with some java code to do 
something similar and you can expect in any implementation these things will be 
system dependent. It often helps to have simple test cases to isolate the 
problem. Here I made a tst script called foo that takes a minute or so to 
exevute and generates some output. If I type system(./foo,wait=F) the prompt 
comes back right away but stdout seems to still go to my console and maybe 
stdin is not redicrected either and it could eat your input ( no idea, but this 
is probably not what you want). I did try this that could fix your problem, on 
debian anyway it seems to work, system(nohup ./foo ) you can man nohup for 
details.   Rasanpreet Kaur [[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.   --  
  Amar Kumar Nandan  Karnataka, India, 560100  http://aknandan.co.nr   
  [[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. 


[[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] Structural equation modeling in R(lavaan,sem)

2011-04-05 Thread yrosseel

On 04/04/2011 07:14 PM, jouba wrote:



Thanks you for your response
For lavaan package can i have more information about this example you have 
applied in the section 7
the meanings  of The variables (c1,c2,c3,c4, i ,s ,x1,x2)
I think i have need more information to learn  more about how  able to apply 
growth model  in my data (longitudianl data)


In the example, c1-c4 are time-varying covariates, i and s are the 
random intercept and slope respectively, and x1 and x2 are two exogenous 
covariates influencing the intercept and slope.


Please note: the lavaanIntroduction document is hardly useful to _learn_ 
about growth models (or any SEM model for that matter). It only explains 
how to fit them using the lavaan package. To learn about growth models, 
you may want to read any one of the books below:


Latent Curve Models: A Structural Equation Perspective (Wiley Series in 
Probability and Statistics) by Kenneth A. Bollen and Patrick J. Curran 
(Hardcover - Dec 23, 2005)


Latent Growth Curve Modeling (Quantitative Applications in the Social 
Sciences) by Dr. Kristopher J. Preacher, Aaron Lee Wichman, Robert 
Charles MacCallum and Dr. Nancy E. Briggs (Paperback - Jun 27, 2008)


An Introduction to Latent Variable Growth Curve Modeling: Concepts, 
Issues, and Applications (Quantitative Methodology) (Quantitative 
Methodology Series) by Terry E. Duncan, Susan C. Duncan and Lisa A. 
Strycker (Paperback - May 23, 2006)


Yves.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Confidence interval for the difference between proportions - method used in prop.test()

2011-04-05 Thread Joshua Wiley
Dear Steffi,

On Tue, Apr 5, 2011 at 7:26 AM, Stefanie Von Felten svonfel...@uhbs.ch wrote:
 Dear Josh,

 Thanks for your help!

 Does your answer mean, that you agree the two methods should do the same,
 and what I was guessing, despite the small differences?

That would be my guess, but I have not actually read the reference in
discussion.  Still, the documentation for prop.test uses the same
Newcombe reference as ci.pd, so if method 10 is the clear winner, it
seems reasonable that prop.test is an implementation of it.


 What I prefer about ci.pd is, that the help clearly says which method is
 implemented, which is not the case for prop.test. But I do not know who has
 programmed the function.

Then for reporting, use ci.pd, and say it is method 10 from Newcombe.
You can always check the results with prop.test() which is part of R
core so you can be pretty confident whatever it does, it does it
correctly (and will be updated if necessary with future releases of
R).

Sincerely,

Josh

 Best wishes
 Steffi


 Stefanie von Felten, PhD
 Statistician
 Clinical Trial Unit, CTU
 University Hospital Basel
 Schanzenstrasse 55
 CH-4031 Basel

 Phone: ++41(0)61 556 54 98
 Joshua Wiley jwiley.ps...@gmail.com 05.04.11 15.59 Uhr 
 Hi Stefanie,

 Just to be clear, we are talking about differences in the third or
 lower decimal place (at least with R version 2.13.0 alpha (2011-03-17
 r54849), Epi_1.1.20). This strikes me as small enough that both
 functions may be implementing the same method, but maybe slightly
 different ways of going about it?

 If you are really concerned and need to know *exactly*, look at the
 source code for both functions. In case you did not know, if you type
 the function name at the console with parentheses or any arguments,
 just like:

 prop.test
 ci.pd

 it will show the actual function code. It looks to me like both of
 them are implemented purely in R, and without even calling any other
 complex functions (at least based on a quick glance through). This
 means if you have the Newscomb text, you should be able to sit down
 and go through the code step by step comparing it.

 Cheers,

 Josh

 FYI, you can use a matrix with prop.test, and then its transpose for ci.pd.
 ##
 mymat - cbind(Successes = c(21, 41), Failures = c(345, 345) - c(21, 41))
 require(Epi)
 results - list(prop.test(mymat, correct=FALSE), ci.pd(t(mymat)))
 results[[1]][[conf.int]] - results[[2]][6:7]

 On Tue, Apr 5, 2011 at 3:38 AM, Stefanie Von Felten svonfel...@uhbs.ch
 wrote:
 Hello,

 Does anyone know which method from Newcombe (1998)* is implemented in
 prop.test for comparing two proportions?
 I would guess it is the method based on the Wilson score (for single
 proportion), with and without continuity correction for prop.test(...,
 correct=FALSE) and prop.test(..., correct=TRUE). These methods would
 correspond to no. 10 and 11 tested in Newcombe, respectively. Can someone
 confirm this? If not, which other methods are implemented by prop.test?

 * Newcombe R.G. (1998) Two-Sided Confidence Intervals for the Single
 Proportion: Comparison of Seven Methods. Statistics in Medicine *17*,
 857-872.

 There is also the function ci.pd() from the R-package Epi, which should
 implement method no. 10 from Newcombe. However, prop.test(...,
 correct=FALSE) and ci.pd do not give the same result if I do the following:

 successes - c(21, 41)
 total - c(345, 345)
 prop.test(successes, total, correct=FALSE)
 library(Epi)
 ci.pd(matrix(c(successes, total-successes),ncol=2, byrow=TRUE))

 Can someone explain why?

 Best wishes
 Stefanie von Felten


 Stefanie von Felten, PhD
 Statistician
 Clinical Trial Unit, CTU
 University Hospital Basel
 Schanzenstrasse 55
 CH-4031 Basel

 Phone: ++41(0)61 556 54 98

 [[alternative HTML version deleted]]

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




 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


Re: [R] Time series example in Koop

2011-04-05 Thread Mike Marchywka





 Date: Tue, 5 Apr 2011 07:35:04 -0500
 From: ravi.k...@gmail.com
 To: r-help@r-project.org
 Subject: [R] Time series example in Koop

 I am trying to reproduce the output of a time series example in Koop's book
 Analysis of Financial Data. Koop does the example in Excel and I used the
 ts function followed by the lm function.
 I am unable to get the exact coefficients that Koop gives - my coefficients
 are slightly different.


 After loading the data file and attaching the frame, my code reads:

  y = ts(m.cap)
  x = ts(oil.price)
  d = ts.union(y,x,x1=lag(x,-1),x2=lag(x,-2),x3=lag(x,-3),x4=lag(x,-4))
  mod1 = lm(y~x+x1+x2+x3+x4, data=d)
  summary(mod1)

 Koop gives an intercept of 92001.51, while the code above gives 91173.32.
 The other coefficients are also slightly off.

The differences here seem to be of order 1 percent. You could suspect
a number of things, including the published data file being published
to less precision than that used in the book numbers(also look at number
of points and see if any were added or dropped etc ). However, you may want
to judge these based on what they do to your error which they
presumably are both supposed to minimize but the calculation of which could
be subject to various roundoff errors etc. Unless minimization is done
analytically, it is of course subject to limitations of convergence or iteration
count. Plotting both fits over the data and looking at residuals may help too.
Depending on what you are really trying to do, you may want to change
your error calculation etc. 

Details of numerical results often depend on details of implementation.
This is why stats packages that are not open
source have limitations in applicability. With real models of course
things get even more confusing. 
( take a look at credit rating agencies results for example LOL).




 This is the example in Table 8.3 of Koop. I also attach a plain text version
 of the tab separated file badnews.txt.
 http://r.789695.n4.nabble.com/file/n3427897/badnews.txt badnews.txt

 Any light on why I do not get Koop's coefficients is most welcome...

 Ravi

  
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 to check data before putting it in a database

2011-04-05 Thread Ulisses.Camargo
The example scene:

I have a database with stats about each goal made by my soccer team. This
database (a data frame in R) is organized in lines (goals) with a set of
columns containing data about these goals (player name, tactic position,
etc). For now, this database will be called data.frame1.

What I need is to feed this data.frame1 with new information about my team
goals. I will call this new information data.frame2. This set of new goals
is organized in the same way as in data.frame1 (equal numbers of cols).

Where help is needed:

I need help in finding a way to check the player-name column in
data.frame2 before feeding data.frame1 with it. What I need is a way to
verify the name of the player on each line of data.frame2 with the names
of players that already exist on a col in data.frame1. Moreover, I need R
to make two main things:

First, the lines of “data.frame2” with player names that already exists in
“data.frame1” must be added to “data.frame1”.

Second: lines of “data.frame2” with player names that does not exist on
“data.frame1” must be listed in an output to be manually checked and
corrected. 
After this verification, corrected lines and new-player-names lines must be
incorporated in data.frame1. 

What I want is to guarantee that will be no lines with wrong player names in
my database. 
At the same time, my script must permit new information to be added (new
player names).
 
Is there somebody who could help me with this?

Thanks for your attention

Best wishes
Ulisses   

--
View this message in context: 
http://r.789695.n4.nabble.com/Help-to-check-data-before-putting-it-in-a-database-tp3428318p3428318.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] Support Counting

2011-04-05 Thread psombe
well im using the arules package and i'm trying to use the support command.
my data is read form a file using the read.transactions command and a line
of data looks something like this. there are aboutt 88000 rows and 16000
different items
 inspect(dset[3])
  items
1 {33, 
34, 
35} 
 inspect(dset[1])
  items
1 {0, 1,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2,  20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 3, 4,5, 6, 7,  8,  9}  

So in order to use support i have to make an object of class itemsets and
im kind of struggling with the new command.
I made an object of class itemsets by first creating a presence/absence
matrix and with something like 16000 items this is really sort of tedious. I
wonder if there is a better way.

//Currently im doing this

avec = array(dim=400) //dim is till the max number of the item im concerned
with
avec[1:400] = 0
avec[27] = 1
avec[63] = 1 //and do on for all the items i want

amat = matrix(data = avec,ncol = 400)
aset = as(amat,transactions) //coercing the matrix as a transactions class

then say my data is dat i can use

support(aset,dat)
[1] 0.001406470


There has to be a better way
Thanks once again

--
View this message in context: 
http://r.789695.n4.nabble.com/Support-Counting-tp3424730p3428062.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 label customized y axis when using lattice parallel parameter common.scale=TRUE

2011-04-05 Thread Pengcheng Yang

Thanks Deepayan, It works!

On 2011-4-5 21:42, Deepayan Sarkar wrote:

On Tue, Apr 5, 2011 at 4:39 PM, Pengcheng Yangpeng...@gmail.com  wrote:

Dear all,

When I use parallel function in lattice package, I want to label the y-axis
with customized numbers. Like this:

parallel(~iris[1:4] | Species, iris,horiz=FALSE,common.scale=TRUE,
scales=list(y=list(at=c(0,2,3

Parallel does not directly support that, and will insist on scaling
the data. However, you can control the scaling (using 'lower' and
'upper'), and override a couple of other arguments to get what you
want:

parallel(~iris[1:4] | Species, iris,
  xlim = extendrange(range(iris[1:4])),
  scales = list(x = list(at = NULL, labels = NULL)),
  lower = 0, upper = 1)

This is for horizontal.axis = TRUE, adjust accordingly for FALSE.

-Deepayan


But only Min label in the y-axis, nothing happened. Could anyone help me?

Thanks.
Regards,

Pengcheng Yang

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Antw: Re: Confidence interval for the difference between proportions - method used in prop.test()

2011-04-05 Thread Stefanie Von Felten
Dear Josh,

Thanks for your help!

Does your answer mean, that you agree the two methods should do the same, and 
what I was guessing, despite the small differences?

What I prefer about ci.pd is, that the help clearly says which method is 
implemented, which is not the case for prop.test. But I do not know who has 
programmed the function.

Best wishes
Steffi

Stefanie von Felten, PhD
Statistician
Clinical Trial Unit, CTU
University Hospital Basel
Schanzenstrasse 55
CH-4031 Basel

Phone: ++41(0)61 556 54 98
 Joshua Wiley  05.04.11 15.59 Uhr 
Hi Stefanie,

Just to be clear, we are talking about differences in the third or
lower decimal place (at least with R version 2.13.0 alpha (2011-03-17
r54849), Epi_1.1.20).  This strikes me as small enough that both
functions may be implementing the same method, but maybe slightly
different ways of going about it?

If you are really concerned and need to know *exactly*, look at the
source code for both functions.  In case you did not know, if you type
the function name at the console with parentheses or any arguments,
just like:

 prop.test
 ci.pd

it will show the actual function code.  It looks to me like both of
them are implemented purely in R, and without even calling any other
complex functions (at least based on a quick glance through).  This
means if you have the Newscomb text, you should be able to sit down
and go through the code step by step comparing it.

Cheers,

Josh

FYI, you can use a matrix with prop.test, and then its transpose for ci.pd.
##
mymat - cbind(Successes = c(21, 41), Failures = c(345, 345) - c(21, 41))
require(Epi)
results - list(prop.test(mymat, correct=FALSE), ci.pd(t(mymat)))
results[[1]][[conf.int]] - results[[2]][6:7]

On Tue, Apr 5, 2011 at 3:38 AM, Stefanie Von Felten  wrote:
 Hello,

 Does anyone know which method from Newcombe (1998)* is implemented in 
 prop.test for comparing two proportions?
 I would guess it is the method based on the Wilson score (for single 
 proportion), with and without continuity correction  for prop.test(..., 
 correct=FALSE) and prop.test(..., correct=TRUE). These methods would 
 correspond to no. 10 and 11 tested in Newcombe, respectively. Can someone 
 confirm this? If not, which other methods are implemented by prop.test?

 * Newcombe R.G. (1998) Two-Sided Confidence Intervals for the Single 
 Proportion: Comparison of Seven Methods.  Statistics in Medicine  *17*, 
 857-872.

 There is also the function ci.pd() from the R-package Epi, which should 
 implement method no. 10 from Newcombe. However, prop.test(..., correct=FALSE) 
 and ci.pd do not give the same result if I do the following:

 successes - c(21, 41)
 total - c(345, 345)
 prop.test(successes, total, correct=FALSE)
 library(Epi)
 ci.pd(matrix(c(successes, total-successes),ncol=2, byrow=TRUE))

 Can someone explain why?

 Best wishes
 Stefanie von Felten


 Stefanie von Felten, PhD
 Statistician
 Clinical Trial Unit, CTU
 University Hospital Basel
 Schanzenstrasse 55
 CH-4031 Basel

 Phone: ++41(0)61 556 54 98

[[alternative HTML version deleted]]

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




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/


[[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] Help to check data before putting it in a database

2011-04-05 Thread Joshua Wiley
Hi Ulisses,

Look at the functions ?match and ?rbind

If you do not want to do it by hand, you can make a little function as below.

HTH,

Josh

d1 - data.frame(goals = 4:1, players = LETTERS[1:4])
d2 - data.frame(goals = c(1, 3, 2, 5), players = LETTERS[3:6])

f - function(old, new, check) {
  index - new[, check] %in% old[, check]
  dat - rbind(old, new[index, ])
  tocheck - new[!index, ]
  list(merged = dat, tocheck = tocheck)
}

dmerged - f(d1, d2, players)
## check tocheck and once it is correct
dfinal - do.call(rbind, dmerged)

On Tue, Apr 5, 2011 at 8:06 AM, Ulisses.Camargo
moliterno.cama...@gmail.com wrote:
 The example scene:

 I have a database with stats about each goal made by my soccer team. This
 database (a data frame in R) is organized in lines (goals) with a set of
 columns containing data about these goals (player name, tactic position,
 etc). For now, this database will be called data.frame1.

 What I need is to feed this data.frame1 with new information about my team
 goals. I will call this new information data.frame2. This set of new goals
 is organized in the same way as in data.frame1 (equal numbers of cols).

 Where help is needed:

 I need help in finding a way to check the player-name column in
 data.frame2 before feeding data.frame1 with it. What I need is a way to
 verify the name of the player on each line of data.frame2 with the names
 of players that already exist on a col in data.frame1. Moreover, I need R
 to make two main things:

 First, the lines of “data.frame2” with player names that already exists in
 “data.frame1” must be added to “data.frame1”.

 Second: lines of “data.frame2” with player names that does not exist on
 “data.frame1” must be listed in an output to be manually checked and
 corrected.
 After this verification, corrected lines and new-player-names lines must be
 incorporated in data.frame1.

 What I want is to guarantee that will be no lines with wrong player names in
 my database.
 At the same time, my script must permit new information to be added (new
 player names).

 Is there somebody who could help me with this?

 Thanks for your attention

 Best wishes
 Ulisses

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Help-to-check-data-before-putting-it-in-a-database-tp3428318p3428318.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


Re: [R] Help to check data before putting it in a database

2011-04-05 Thread Jeff Newmiller
I would recommend using R to check your input and identify bad input and to 
only load data that passes validation. Then go back to some other tool for 
editing the data and save/reload/reverify the edited data. The merge command 
with the all.x argument and is.na() can be used, or the ! and %in% logical 
operators can be used, to find non-matching values.

If you are determined to modify the data in R, then you probably need the tk 
library, the use of which is not really a topic for this forum.
---
Jeff Newmiller The . . Go Live...
DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Ulisses.Camargo moliterno.cama...@gmail.com wrote:

The example scene: I have a database with stats about each goal made by my 
soccer team. This database (a data frame in R) is organized in lines (goals) 
with a set of columns containing data about these goals (player name, tactic 
position, etc). For now, this database will be called data.frame1. What I 
need is to feed this data.frame1 with new information about my team goals. I 
will call this new information data.frame2. This set of new goals is 
organized in the same way as in data.frame1 (equal numbers of cols). Where 
help is needed: I need help in finding a way to check the player-name column in 
data.frame2 before feeding data.frame1 with it. What I need is a way to 
verify the name of the player on each line of data.frame2 with the names of 
players that already exist on a col in data.frame1. Moreover, I need R to 
make two main things: First, the lines of “data.frame2” with player names 
that already exists in “data.frame1” must be added to “data.fram
 e1”.
Second: lines of “data.frame2” with player names that does not exist on 
“data.frame1” must be listed in an output to be manually checked and 
corrected. After this verification, corrected lines and new-player-names lines 
must be incorporated in data.frame1. What I want is to guarantee that will be 
no lines with wrong player names in my database. At the same time, my script 
must permit new information to be added (new player names). Is there somebody 
who could help me with this? Thanks for your attention Best wishes Ulisses -- 
View this message in context: 
http://r.789695.n4.nabble.com/Help-to-check-data-before-putting-it-in-a-database-tp3428318p3428318.html
 Sent from the R help mailing list archive at 
Nabble.com._
R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code. 


[[alternative HTML version deleted]]

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


Re: [R] Help to check data before putting it in a database

2011-04-05 Thread Ulisses.Camargo
Hello Josh,
It works. Thanks a lot!!
I have now the basic tools to advance!
Best!
Ulisses

2011/4/5 Joshua Wiley-2 [via R]
ml-node+3428356-844576439-227...@n4.nabble.com:
 Hi Ulisses,

 Look at the functions ?match and ?rbind

 If you do not want to do it by hand, you can make a little function as
 below.

 HTH,

 Josh

 d1 - data.frame(goals = 4:1, players = LETTERS[1:4])
 d2 - data.frame(goals = c(1, 3, 2, 5), players = LETTERS[3:6])

 f - function(old, new, check) {
   index - new[, check] %in% old[, check]
   dat - rbind(old, new[index, ])
   tocheck - new[!index, ]
   list(merged = dat, tocheck = tocheck)
 }

 dmerged - f(d1, d2, players)
 ## check tocheck and once it is correct
 dfinal - do.call(rbind, dmerged)

 On Tue, Apr 5, 2011 at 8:06 AM, Ulisses.Camargo
 [hidden email] wrote:
 The example scene:

 I have a database with stats about each goal made by my soccer team. This
 database (a data frame in R) is organized in lines (goals) with a set of
 columns containing data about these goals (player name, tactic position,
 etc). For now, this database will be called data.frame1.

 What I need is to feed this data.frame1 with new information about my
 team
 goals. I will call this new information data.frame2. This set of new
 goals
 is organized in the same way as in data.frame1 (equal numbers of cols).

 Where help is needed:

 I need help in finding a way to check the player-name column in
 data.frame2 before feeding data.frame1 with it. What I need is a way
 to
 verify the name of the player on each line of data.frame2 with the names
 of players that already exist on a col in data.frame1. Moreover, I need
 R
 to make two main things:

 First, the lines of “data.frame2” with player names that already exists 
 in
 “data.frame1” must be added to “data.frame1”.

 Second: lines of “data.frame2” with player names that does not exist on
 “data.frame1” must be listed in an output to be manually checked and
 corrected.
 After this verification, corrected lines and new-player-names lines must
 be
 incorporated in data.frame1.

 What I want is to guarantee that will be no lines with wrong player names
 in
 my database.
 At the same time, my script must permit new information to be added (new
 player names).

 Is there somebody who could help me with this?

 Thanks for your attention

 Best wishes
 Ulisses

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Help-to-check-data-before-putting-it-in-a-database-tp3428318p3428318.html
 Sent from the R help mailing list archive at Nabble.com.

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



 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/

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


 
 If you reply to this email, your message will be added to the discussion
 below:
 http://r.789695.n4.nabble.com/Help-to-check-data-before-putting-it-in-a-database-tp3428318p3428356.html
 To unsubscribe from Help to check data before putting it in a database,
 click here.



-- 
Ulisses Moliterno de Camargo
Instituto Nacional de Pesquisas da Amazônia


--
View this message in context: 
http://r.789695.n4.nabble.com/Help-to-check-data-before-putting-it-in-a-database-tp3428318p3428376.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

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


Re: [R] how to label customized y axis when using lattice parallel parameter common.scale=TRUE

2011-04-05 Thread Pengcheng Yang
I have readjust the script as follows to retain the complete information 
of original graph, the background vertical bar.



parallel(~iris[1:4] | Species, iris,horizon=FALSE,
 ylim = extendrange(range(iris[1:4])),
 scales = list(y = list(at = NULL, labels = NULL),x=list(rot=45)),
 lower = 0, upper = 1,
 panel=function(x,y,z,...){
   panel.abline(v=1:4,col=gray90)
   panel.parallel(x,y,z,...)
 })

On 2011-4-5 21:42, Deepayan Sarkar wrote:

On Tue, Apr 5, 2011 at 4:39 PM, Pengcheng Yangpeng...@gmail.com  wrote:

Dear all,

When I use parallel function in lattice package, I want to label the y-axis
with customized numbers. Like this:

parallel(~iris[1:4] | Species, iris,horiz=FALSE,common.scale=TRUE,
scales=list(y=list(at=c(0,2,3

Parallel does not directly support that, and will insist on scaling
the data. However, you can control the scaling (using 'lower' and
'upper'), and override a couple of other arguments to get what you
want:

parallel(~iris[1:4] | Species, iris,
  xlim = extendrange(range(iris[1:4])),
  scales = list(x = list(at = NULL, labels = NULL)),
  lower = 0, upper = 1)

This is for horizontal.axis = TRUE, adjust accordingly for FALSE.

-Deepayan


But only Min label in the y-axis, nothing happened. Could anyone help me?

Thanks.
Regards,

Pengcheng Yang

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] loop question

2011-04-05 Thread Thomas

Dear all,

I am trying to set up a list with 1:c objects each meant to capture the 
coefficients for one coefficient and 100 replications. I receive the 
following error message:


Error in betaboot[[p]] : subscript out of bounds.

My code is below. Where is my mistake?

Many thanks,

Thomas

_
betaboot-list(NULL)

for (i in 1:c) {
betaboot[[i]]-cbind()
}


num - 100 # this is the number of bootstraps

for (i in 1:num) {

[BOOTSTRAP]

  coef.temp - coef(model.temp, data=newdata)

  for (p in 1:c){
  betaboot[[p]] - cbind(betaboot[[p]], coef.temp[,p])
  }

  }

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] loop question

2011-04-05 Thread Joshua Wiley
Dear Thomas,

On Tue, Apr 5, 2011 at 8:33 AM, Thomas thomas.tri...@cantab.net wrote:
 Dear all,

 I am trying to set up a list with 1:c objects each meant to capture the
 coefficients for one coefficient and 100 replications. I receive the
 following error message:

 Error in betaboot[[p]] : subscript out of bounds.

 My code is below. Where is my mistake?

 Many thanks,

 Thomas

 _
 betaboot-list(NULL)

if you know the number of bootstraps (which you seem to later on), a
preferred way to instatiate the list would be:

betaboot - vector(mode = list, length = yourlength)


 for (i in 1:c) {

because c() is such an important function, I would strongly
encourage you not to use it also as a variable.

 betaboot[[i]]-cbind()

Don't use this to build an empty list.

 }


 num - 100 # this is the number of bootstraps

 for (i in 1:num) {

    [BOOTSTRAP]

  coef.temp - coef(model.temp, data=newdata)

  for (p in 1:c){
  betaboot[[p]] - cbind(betaboot[[p]], coef.temp[,p])

This should work assuming betaboot is instatiated properly.  That
said, it looks like you have a nested for loop and then just keep
cbind()ing each element of betaboot bigger and bigger.  You may get a
performance increase if you also instantiate each matrix/dataframe
inside betaboot.  Then the call would become something like:

betaboot[[i]][,p] - coef.temp[,p]

that is, you can use a chained series of extraction operators to get
to the appropriate column in the matrix/dataframe inside the
appropriate list element.  Then rather than constantly using cbind(),
you just place coef.temp[,p] where you want it.  The only requirement
is that you know the sizes of the matrices/dataframes going in so you
can create empty ones from the get go.

Cheers,

Josh

  }

  }

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

-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


[R] Gibbs sampling

2011-04-05 Thread Liliana Pacheco
HI R users, perhaps you can help me with this:

I am planning on using the Gibbs sampler for the correlation coefficient of
a bivariate normal. I have a posterior distribution for rho, besides that,
the conditional distribution for all the parameters of this posterior
distribution. The thing is that, since I have to get a sample, size 1
for rho, obtain a 95% confidence interval, and repeat this procedure 1000
times; and repeat this procedure for 50 scenaries, I'n thinking this is
going to take forever.

Is there a library for making this work faster? I've heard of gibbs.met, but
I don't know if it's going to work or even more, I didn't understand the
examples.

Thanks!

[[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] Precision of summary() when summarizing variables in a data frame

2011-04-05 Thread Daniel Malter
Hi, 

I summary() a variable with 409908 numeric observations. The variable is
part of a data.frame. The problem is that the min and max returned by
summary() do not equal the ones returned by min() and max(). Does anybody
know why that is? 

 min(data$vc)
[1] 15452
 max(data$vc)
[1] 316148
 summary(data$vc)
   Min. 1st Qu.  MedianMean 3rd Qu.Max. 
  15450   21670   40980   55500   63880  316100 


sessionInfo()
R version 2.11.1 (2010-05-31) 
x86_64-apple-darwin9.8.0 

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] sqldf_0.3-5   chron_2.3-39  gsubfn_0.5-5 
[4] proto_0.3-8   RSQLite.extfuns_0.0.1 RSQLite_0.9-4
[7] DBI_0.2-5 

Thanks much,
Daniel  

--
View this message in context: 
http://r.789695.n4.nabble.com/Precision-of-summary-when-summarizing-variables-in-a-data-frame-tp3428570p3428570.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] lorena

2011-04-05 Thread lorena delgadillo
 Dear
I would like to know how to use the Croston method in R, consaltarte if I
download a package?

personally work the series as a SARIMA

In the present instalment have many values zeros proposed the following
model, but I have many doubts with his predictions.

M3 = arima (d1, order = c (2,1,4), n. ahead = 4, seasonal = list (order = c
(2,1,4), period = 4))

where

D1 = diff (series)

Many thanks in advance
Dear
I would like to know how to use the Croston method in R, consaltarte if I
download a package?

personally work the series as a SARIMA

In the present instalment have many values zeros proposed the following
model, but I have many doubts with his predictions.

M3 = arima (d1, order = c (2,1,4), n. ahead = 4, seasonal = list (order = c
(2,1,4), period = 4))

where

D1 = diff (series)

Many thanks in advance
Dear
I would like to know how to use the Croston method in R, consaltarte if I
download a package?

personally work the series as a SARIMA

In the present instalment have many values zeros proposed the following
model, but I have many doubts with his predictions.

M3 = arima (d1, order = c (2,1,4), n. ahead = 4, seasonal = list (order = c
(2,1,4), period = 4))

where

D1 = diff (series)

Many thanks in advance
Dear
I would like to know how to use the Croston method in R, consaltarte if I
download a package?

personally work the series as a SARIMA

In the present instalment have many values zeros proposed the following
model, but I have many doubts with his predictions.

M3 = arima (d1, order = c (2,1,4), n. ahead = 4, seasonal = list (order = c
(2,1,4), period = 4))

where

D1 = diff (series)

Many thanks in advance
Dear
I would like to know how to use the Croston method in R, consaltarte if I
download a package?

personally work the series as a SARIMA

In the present instalment have many values zeros proposed the following
model, but I have many doubts with his predictions.

M3 = arima (d1, order = c (2,1,4), n. ahead = 4, seasonal = list (order = c
(2,1,4), period = 4))

where

D1 = diff (series)

Many thanks in advance
Dear
I would like to know how to use the Croston method in R, consaltarte if I
download a package?

personally work the series as a SARIMA

In the present instalment have many values zeros proposed the following
model, but I have many doubts with his predictions.

M3 = arima (d1, order = c (2,1,4), n. ahead = 4, seasonal = list (order = c
(2,1,4), period = 4))

where

D1 = diff (series)

Many thanks in advance
Dear
I would like to know how to use the Croston method in R, consaltarte if I
download a package?

personally work the series as a SARIMA

In the present instalment have many values zeros proposed the following
model, but I have many doubts with his predictions.

M3 = arima (d1, order = c (2,1,4), n. ahead = 4, seasonal = list (order = c
(2,1,4), period = 4))

where

D1 = diff (series)

Many thanks in advance
Dear
I would like to know how to use the Croston method in R, consaltarte if I
download a package?

Personally work the series as a SARIMA, this correct?

In the present instalment have many values zeros proposed the following
model, but I have many doubts with his predictions.
M3 = arima (d1, order = c (2,1,4), n. ahead = 4, seasonal = list (order = c
(2,1,4), period = 4))
where
D1 = diff (series)

Many thanks in advance
*
saludos cordiales,

LORENA DELGADILLO AGUIRRE*
Licenciada en Estadística PUCV
*www.lorenadelgadilloaguirre.blogspot.com*
*lod...@gmail.com*   *09-668.48.60*
ID  Serie
1.000.00
2.000.00
3.000.00
4.00152.10
5.00179.58
6.00195.474000
7.00197.937200
8.00216.097160
9.00223.071448
10.00   245.966874
11.00   252.880644
12.00   0.00
13.00   273.109027
14.00   281.577342
15.00   287.372776
16.00   280.555955
17.00   286.182042
18.00   293.301229
19.00   303.959187
20.00   303.197473
21.00   312.053897
22.00   0.00
23.00   322.755681
24.00   0.00
25.00   321.304233
26.00   329.709470
27.00   335.897999
28.00   0.00
29.00   329.701277
30.00   325.349956
31.00   338.850093
32.00   343.215070
33.00   0.00
34.00   0.00
35.00   334.615434
36.00   343.551063
37.00   337.402394
38.00   336.177021
39.00   340.881856
40.00   348.523187
41.00   349.106735
42.00   351.637707
43.00   353.120839
44.00   344.560442
45.00   0.00
46.00   0.00
47.00   0.00
48.00   0.00
49.00   345.231065
50.00   351.480541
51.00   342.707539
52.00   348.914086
53.00   354.102022
54.00   356.273026
55.00   345.428623
56.00   

Re: [R] Precision of summary() when summarizing variables in a data frame

2011-04-05 Thread jim holtman
They are probably the same.  It isjust that summary is printing out 4
significant digits.  Try:

options(digits = 20)



On Tue, Apr 5, 2011 at 12:38 PM, Daniel Malter dan...@umd.edu wrote:
 Hi,

 I summary() a variable with 409908 numeric observations. The variable is
 part of a data.frame. The problem is that the min and max returned by
 summary() do not equal the ones returned by min() and max(). Does anybody
 know why that is?

 min(data$vc)
 [1] 15452
 max(data$vc)
 [1] 316148
 summary(data$vc)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
  15450   21670   40980   55500   63880  316100


 sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-apple-darwin9.8.0

 locale:
 [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

 other attached packages:
 [1] sqldf_0.3-5           chron_2.3-39          gsubfn_0.5-5
 [4] proto_0.3-8           RSQLite.extfuns_0.0.1 RSQLite_0.9-4
 [7] DBI_0.2-5

 Thanks much,
 Daniel

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Precision-of-summary-when-summarizing-variables-in-a-data-frame-tp3428570p3428570.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Creating multiple vector/list names-novice

2011-04-05 Thread michalseneca
Thanks 

I already found out solution :) 

--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-multiple-vector-list-names-novice-tp3425616p3428617.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] Arrangement of Lattice Histograms - Top to bottom and then left to right?

2011-04-05 Thread Les
Hi List,
Using Lattice, I have created a plot of histograms showing Fork Length by
Year. The plot shows the histograms in 3 columns and 5 rows. Using the
as.table=T function I can get the years to start on top. However, what I
would like to do is have the first year start in the top left (column 1, row
1; as it is now) and add the subsequent histograms to the plot going down
the column and then over by row (example and current code is shown below).
Is this possible? I have spent a great deal of time searching, and have not
found any clues. Any help/ideas would be greatly appreciated.

For example, what is being done now:

1974 1975 1976 
1977 1978 1979 
1980 1981 1982

and what I am hoping for:

1974 1977 1980
1975 1978 1981
1976 1979 1982

Thank you kindly,
Les

data=read.csv(AllData.csv,sep=,,header=T)   
data$year=as.factor(data$year)  
ferg=data[data$wtrbody==Ferguson,c(1:12)]
library(lattice)

strip.background=trellis.par.get(strip.background)
trellis.par.set(strip.background = list(col = grey(7:1/8))) 

histogram(~fl|year, data=ferg, as.table=T, type=count,
col='dark grey',layout=c(3,5),lwd=2, lty=1, 
xlab=list(Fork Length (mm), cex=1.4,font=2),  
breaks=seq(from=300,to=900,by=25),  
ylab=list(Frequency,cex=1.4,font=2),  
scales=list(font=2,cex=1.1, tck=c(1,0), alternating=1,  
y=list(relation=free,tick.number=3)), 

par.strip.text=list(cex=1.2),font=2,
aspect=0.6)

--
View this message in context: 
http://r.789695.n4.nabble.com/Arrangement-of-Lattice-Histograms-Top-to-bottom-and-then-left-to-right-tp3428825p3428825.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] Precision of summary() when summarizing variables in a data frame

2011-04-05 Thread Erik Iverson



jim holtman wrote:

They are probably the same.  It isjust that summary is printing out 4
significant digits.  Try:

options(digits = 20)


FYI, the default summary method also has its own digits argument.





On Tue, Apr 5, 2011 at 12:38 PM, Daniel Malter dan...@umd.edu wrote:

Hi,

I summary() a variable with 409908 numeric observations. The variable is
part of a data.frame. The problem is that the min and max returned by
summary() do not equal the ones returned by min() and max(). Does anybody
know why that is?


min(data$vc)

[1] 15452

max(data$vc)

[1] 316148

summary(data$vc)

  Min. 1st Qu.  MedianMean 3rd Qu.Max.
 15450   21670   40980   55500   63880  316100


sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] sqldf_0.3-5   chron_2.3-39  gsubfn_0.5-5
[4] proto_0.3-8   RSQLite.extfuns_0.0.1 RSQLite_0.9-4
[7] DBI_0.2-5

Thanks much,
Daniel

--
View this message in context: 
http://r.789695.n4.nabble.com/Precision-of-summary-when-summarizing-variables-in-a-data-frame-tp3428570p3428570.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] Arrangement of Lattice Histograms - Top to bottom and then left to right?

2011-04-05 Thread Bert Gunter
Look for the index.cond argument at the bottom of the Help page for xyplot.
-- Bert

On Tue, Apr 5, 2011 at 11:37 AM, Les lnhar...@zoology.ubc.ca wrote:
 Hi List,
 Using Lattice, I have created a plot of histograms showing Fork Length by
 Year. The plot shows the histograms in 3 columns and 5 rows. Using the
 as.table=T function I can get the years to start on top. However, what I
 would like to do is have the first year start in the top left (column 1, row
 1; as it is now) and add the subsequent histograms to the plot going down
 the column and then over by row (example and current code is shown below).
 Is this possible? I have spent a great deal of time searching, and have not
 found any clues. Any help/ideas would be greatly appreciated.

 For example, what is being done now:

 1974 1975 1976
 1977 1978 1979
 1980 1981 1982

 and what I am hoping for:

 1974 1977 1980
 1975 1978 1981
 1976 1979 1982

 Thank you kindly,
 Les

 data=read.csv(AllData.csv,sep=,,header=T)
 data$year=as.factor(data$year)
 ferg=data[data$wtrbody==Ferguson,c(1:12)]
 library(lattice)

 strip.background=trellis.par.get(strip.background)
 trellis.par.set(strip.background = list(col = grey(7:1/8)))

 histogram(~fl|year, data=ferg, as.table=T, type=count,
        col='dark grey',layout=c(3,5),lwd=2, lty=1,
        xlab=list(Fork Length (mm), cex=1.4,font=2),
        breaks=seq(from=300,to=900,by=25),
        ylab=list(Frequency,cex=1.4,font=2),
        scales=list(font=2,cex=1.1, tck=c(1,0), alternating=1,
        y=list(relation=free,tick.number=3)),
        par.strip.text=list(cex=1.2),font=2,
        aspect=0.6)

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Arrangement-of-Lattice-Histograms-Top-to-bottom-and-then-left-to-right-tp3428825p3428825.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.




-- 
Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions.

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

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


Re: [R] Changing parameter in local fdr R code

2011-04-05 Thread Jim Silverton
I am using Efron's local fdr procedure. But, I want to change the null from
N(0,1) to N(0, 0.002). I can access the function but I have no idea what to
change. In other words, I want nulltype to be N(0,0.002) instead of N(0,1)
in his function. Anyone has any ideas. This is his code for the local fdr:

function (zz, bre = 120, df = 7, pct = 0, pct0 = 1/4, nulltype = 1,
type = 0, plot = 1, mult, mlests, main =  , sw = 0)
{
call = match.call()
if (length(bre)  1) {
lo - min(bre)
up - max(bre)
bre - length(bre)
}
else {
if (length(pct)  1) {
lo - pct[1]
up - pct[2]
}
else {
if (pct == 0) {
lo - min(zz)
up - max(zz)
}
if (pct  0) {
med = median(zz)
ra = med + (1 - pct) * (range(zz) - med)
lo = ra[1]
up = ra[2]
}
if (pct  0) {
v - quantile(zz, c(pct, 1 - pct))
lo - v[1]
up - v[2]
}
}
}
zzz - pmax(pmin(zz, up), lo)
breaks - seq(lo, up, length = bre)
zh - hist(zzz, breaks = breaks, plot = F)
x - (breaks[-1] + breaks[-length(breaks)])/2
yall - y - zh$counts
K - length(y)
N - length(zz)
if (pct  0) {
y[1] - min(y[1], 1)
y[K] - min(y[K], 1)
}
if (type == 0) {
X - cbind(1, ns(x, df = df))
f - glm(y ~ ns(x, df = df), poisson)$fit
}
else {
X - cbind(1, poly(x, df = df))
f - glm(y ~ poly(x, df = df), poisson)$fit
}
l - log(f)
Fl - cumsum(f)
Fr - cumsum(rev(f))
D - (y - f)/(f + 1)^0.5
D - sum(D[2:(K - 1)]^2)/(K - 2 - df)
if (D  1.5)
warning(paste(f(z) misfit = , round(D, 1), .  Rerun with
increased df,
sep = ))
if (nulltype == 3) {
fp0 = matrix(NA, 6, 4)
colnames(fp0) = c(delta, sigleft, p0, sigright)
}
else {
fp0 = matrix(NA, 6, 3)
colnames(fp0) = c(delta, sigma, p0)
}
rownames(fp0) = c(thest, theSD, mlest, mleSD, cmest,
cmeSD)
fp0[thest, 1:2] = c(0, 1)
fp0[theSD, 1:2] = 0
imax - seq(l)[l == max(l)][1]
xmax - x[imax]
if (length(pct0) == 1) {
pctup - 1 - pct0
pctlo - pct0
}
else {
pctlo - pct0[1]
pctup - pct0[2]
}
lo0 - quantile(zz, pctlo)
hi0 - quantile(zz, pctup)
nx - length(x)
i0 - (1:nx)[x  lo0  x  hi0]
x0 - x[i0]
y0 - l[i0]
if (nulltype == 3) {
X00 - cbind((x0 - xmax)^2, pmax(x0 - xmax, 0)^2)
}
else {
X00 - cbind(x0 - xmax, (x0 - xmax)^2)
}
lr - lm(y0 ~ X00)
co - lr$coef
if (nulltype == 3) {
cmerror = I(is.na(co[3]) | is.na(co[2]))
if (!cmerror)
cmerror = I(co[2] = 0 | co[2] + co[3] = 0)
}
else {
cmerror = is.na(co[3])
if (!cmerror)
cmerror = I(co[3] = 0)
}
if (cmerror) {
if (nulltype == 3)
stop(CM estimation failed.  Rerun with nulltype = 1 or 2.)
else if (nulltype == 2)
stop(CM estimation failed.  Rerun with nulltype = 1.)
else {
X0 - cbind(1, x - xmax, (x - xmax)^2)
warning(CM estimation failed, middle of histogram non-normal)
}
}
else {
if (nulltype == 3) {
X0 - cbind(1, (x - xmax)^2, pmax(x - xmax, 0)^2)
sigs - 1/sqrt(-2 * (c(co[2], co[2] + co[3])))
fp0[cmest, c(1, 2, 4)] - c(xmax, sigs)
}
else {
X0 - cbind(1, x - xmax, (x - xmax)^2)
xmaxx - -co[2]/(2 * co[3]) + xmax
sighat - 1/sqrt(-2 * co[3])
fp0[cmest, 1:2] - c(xmaxx, sighat)
}
l0 - as.vector(X0 %*% co)
f0 - exp(l0)
p0 - sum(f0)/sum(f)
f0 - f0/p0
fp0[cmest, 3] - p0
}
b = 4.3 * exp(-0.26 * log(N, 10))
if (missing(mlests)) {
med = median(zz)
sc = diff(quantile(zz)[c(2, 4)])/(2 * qnorm(0.75))
mlests = locmle(zz, xlim = c(med, b * sc))
if (N  5e+05) {
warning(length(zz)  500,000: For ML estimation, a wider
interval than optimal was used.  To use the optimal interval, rerun with
mlests = c(,
mlests[1], , , b * mlests[2], ).\n, sep = )
mlests = locmle(zz, xlim = c(med, sc))
}
}
if (!is.na(mlests[1])) {
if (N  5e+05)
b = 1
if (nulltype == 1) {
Cov.in = list(x = x, X = X, f = f, sw = sw)
ml.out = locmle(zz, xlim = c(mlests[1], b * mlests[2]),
d = mlests[1], s = mlests[2], Cov.in = Cov.in)
mlests = ml.out$mle
}
else mlests = locmle(zz, xlim = c(mlests[1], b * mlests[2]),
d = mlests[1], s = mlests[2])
fp0[mlest, 1:3] = mlests[1:3]
fp0[mleSD, 1:3] = mlests[4:6]
}
if (sum(is.na(fp0[c(3, 

Re: [R] detect filetype (as in unix 'file')

2011-04-05 Thread Jeroen Ooms
 No, but what is wrong with using system()?

The application is running in a very sandboxed environment and might
not have permission to execute 'file'.

 'file' is large and complex because it tries to be comprehensive (but it
 still does not know about some common systems, e.g. 64-bit Windows
 binaries).  There simply is no point in replicating that in R: which is why
 we chose rather to port 'file' to Windows and provide in in Rools.

Alright that makes sense, thanks.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Precision of summary() when summarizing variables in a data frame

2011-04-05 Thread Daniel Malter
Thanks all. No I wasn't aware of the fact that summary is rounding in this
case. 

Da.

--
View this message in context: 
http://r.789695.n4.nabble.com/Precision-of-summary-when-summarizing-variables-in-a-data-frame-tp3428570p3429022.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] Hazard ratio calculation and KM plot p-value:

2011-04-05 Thread Angel Russo
I have two questions:

1) Can anyone provide me with a reference regarding calculation of Hazard
ratio for two groups of data. How is it being manually calculated with an
example. Unlike median time ratio which is the ratio of median times in two
groups, at what time is the hazard ratio calculation done?

2) In kaplan-meier statistics of stratifying into two groups, a p-value is
often calculated (e.g. log-rank p-value). p-value is the test is how
significant the separation is between two groups compared to random. What is
random in kaplan-meier statistics. How is p-value calculated?

Thanks for everyone's time to read and hopefully respond as well.

[[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] Arrangement of Lattice Histograms - Top to bottom and then left to right?

2011-04-05 Thread Les
Thank you.
The help is much appreciated.
Les

--
View this message in context: 
http://r.789695.n4.nabble.com/Arrangement-of-Lattice-Histograms-Top-to-bottom-and-then-left-to-right-tp3428825p3429123.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] Structural equation modeling in R(lavaan,sem)

2011-04-05 Thread jouba

Thanks a lot 

Antra EL MOUSSELLY 


 


Date: Tue, 5 Apr 2011 09:49:08 -0500
From: ml-node+3428265-1156197921-225...@n4.nabble.com
To: antr...@hotmail.com
Subject: Re: Structural equation modeling in R(lavaan,sem)

On 04/04/2011 07:14 PM, jouba wrote: 
 
 
 Thanks you for your response 
 For lavaan package can i have more information about this example you have 
 applied in the section 7 
 the meanings  of The variables (c1,c2,c3,c4, i ,s ,x1,x2) 
 I think i have need more information to learn  more about how  able to apply 
 growth model  in my data (longitudianl data) 

In the example, c1-c4 are time-varying covariates, i and s are the 
random intercept and slope respectively, and x1 and x2 are two exogenous 
covariates influencing the intercept and slope. 

Please note: the lavaanIntroduction document is hardly useful to _learn_ 
about growth models (or any SEM model for that matter). It only explains 
how to fit them using the lavaan package. To learn about growth models, 
you may want to read any one of the books below: 

Latent Curve Models: A Structural Equation Perspective (Wiley Series in 
Probability and Statistics) by Kenneth A. Bollen and Patrick J. Curran 
(Hardcover - Dec 23, 2005) 

Latent Growth Curve Modeling (Quantitative Applications in the Social 
Sciences) by Dr. Kristopher J. Preacher, Aaron Lee Wichman, Robert 
Charles MacCallum and Dr. Nancy E. Briggs (Paperback - Jun 27, 2008) 

An Introduction to Latent Variable Growth Curve Modeling: Concepts, 
Issues, and Applications (Quantitative Methodology) (Quantitative 
Methodology Series) by Terry E. Duncan, Susan C. Duncan and Lisa A. 
Strycker (Paperback - May 23, 2006) 

Yves. 

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






If you reply to this email, your message will be added to the discussion 
below:http://r.789695.n4.nabble.com/Structural-equation-modeling-in-R-lavaan-sem-tp3409642p3428265.html
 
To unsubscribe from Structural equation modeling in R(lavaan,sem), click here.  
  

--
View this message in context: 
http://r.789695.n4.nabble.com/Structural-equation-modeling-in-R-lavaan-sem-tp3409642p3428911.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

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


[R] IFELSE function XXXX

2011-04-05 Thread Dan Abner
Hello everyone,

This IFELSE function call is not working properly. I do not receive an error
message, but the actions are not executed conditional as I was hoping. Any
assistance is appreciated.

set.seed(12345)
res1-rbinom(1,1,.1)
rdata3-transform(data.frame(res1),input1=rnorm(1,50,10))
data3
#inducing correlation between res1  input1
ifelse(data3$res1==1,data3$input1-data3$input1+10,data3$input1-data3$input1)
data3

Thank you,

Dan

[[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] simple save question

2011-04-05 Thread xueke

Hi,

When I run the survfit function, I want to get the restricted mean  
value and the standard error also. I found out using the print  
function to do so, as shown below,


 print(km.fit,print.rmean=TRUE)
Call: survfit(formula = Surv(diff, status) ~ 1, type = kaplan-meier)

   records  n.maxn.start events *rmean *se(rmean) median
   200.000200.000200.000129.000  0.145  0.237  1.158
   0.95LCL0.95UCL
 0.450  1.730
* restricted mean with upper limit =  2.97

The questions is, is there any way to extract these values from the  
print command?


Thanks a lot.

Xueke

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] IFELSE function XXXX

2011-04-05 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Dan Abner
 Sent: Tuesday, April 05, 2011 12:58 PM
 To: r-help@r-project.org
 Subject: [R] IFELSE function 
 
 Hello everyone,
 
 This IFELSE function call is not working properly. I do not 
 receive an error
 message, but the actions are not executed conditional as I 
 was hoping. Any
 assistance is appreciated.
 
 set.seed(12345)
 res1-rbinom(1,1,.1)
 rdata3-transform(data.frame(res1),input1=rnorm(1,50,10))
 data3
 #inducing correlation between res1  input1
 ifelse(data3$res1==1,data3$input1-data3$input1+10,data3$input
1-data3$input1)

Avoid assignments in arguments to function calls, especially
multiple assignments to the same object, except when you know
what you are doing and want to write obscure code.

Change the above line to
  data3$input1 - ifelse(data3$res1==1, data3$input1+10, data3input1)

There is nothing too special about ifelse here, you would get
similar results if you put assignment statements in other function
calls.  The assignment gets evaluated just as things like log(12)
or data3$input1+10 get evaulated when given as arguments.  E.g.,
   x - 1
   cat(x - 2:1, x - 6:3, x - 10:4, \n)
  2 1 6 5 4 3 10 9 8 7 6 5 4
   x
  [1] 10  9  8  7  6  5  4
Which version of x you end up with depends on which argument
the function evaluates last.
   f - function(arg1, arg2) arg2 + arg1
   f( x - 7, x - 101 )
  [1] 108
   x
  [1] 7

An example of obscure code involving multiple assignments
to one object is
  if (is.null(tms - x$terms)  is.null(tms - attr(x, terms))) {
 stop(Cannot find a list component or attribute called terms)
  }
  tms # x$terms if it exists, otherwise attr(x, terms)
Since the order of evaluation of the 2 arguments to  is well
defined (left then right, and the right won't be evaluated unless
the left if TRUE), this produces a trustworthy answer.  Most functions
don't promise any particular order of evaluation.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 


 data3
 
 Thank you,
 
 Dan
 
   [[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] grImport/ghostscript problems

2011-04-05 Thread Paul Murrell

Hi

On 5/04/2011 9:30 p.m., guillaume Le Ray wrote:

Hi Al,

I'm facing exactly the same problem as you are, have you manage to
fix it? If yes I eager to know the trick.


Al's problem turned out to be a bug in 'grImport', so one thing you can 
try is to install the latest version of 'grImport'.


If that still fails, you might be able to get more information about the 
problem by looking at the end of the XML file that is created by 
PostScriptTrace().  If ghostscript has hit trouble it's error messages 
will hopefully be at the end of that XML file.


Paul



Regards,

Guillaume

2011/3/27 Al Roarkhrbuil...@hotmail.com


Paul Murrellp.murrellat  auckland.ac.nz  writes:



Hi

On 28/03/2011 8:13 a.m., Al Roark wrote:


Hi All: I've been struggling for a while trying to get grImport
up and running.  I'm on a Windows 7 (home premium 64 bit)
machine running R-2.12.2 along with GPL Ghostscript 9.01. I've
set my Windows PATH variable to point to the Ghostscript \bin
and \lib directories, and I've created the R_GSCMD environment
variable pointing to gswin32c.exe. I don't have any experience
with Ghostscript, but with the setup described above I can view
the postscript file with the following command to the Windows
command prompt: gswin32c.exe D:\Sndbx\vasarely.ps However, I
can't get the PostScriptTrace() function to work on the same
file.  Submitting PostScriptTrace(D:/Sndbx/vasarely.ps) gives
me the error: Error in PostScriptTrace(D:/Sndbx/vasarely.ps)
:   status 127 in running command 'gswin32c.exe -q -dBATCH
-dNOPAUSE -sDEVICE=pswrite
-sOutputFile=C:\Users\Al\AppData\Local\Temp\RtmppPjDAf\file5db99cb



-sstdout=vasarely.ps.xml capturevasarely.ps' Your suggestions are

much appreciated. Cheers, Al [[alternative HTML version
deleted]]


You could try running the ghostscript command that is printed in
the error message at the Windows command prompt to see more info
about the problem (might need to remove the '-q' so that
ghostscript prints messages to the screen).

Paul



Thanks for your reply.

Perhaps this is a Ghostscript problem. When I run the Ghostscript
command, I'm met with the rather unhelpful error: 'GPL Ghostscript
9.01: Unrecoverable error, exit code 1 (occurs whether or not I
remove the -q)'.

Interestingly, if I remove the final argument (in this case,
capturevasarely.ps) the Ghostscript command executes, placing a
file (appears to be xml) in the temporary directory. However, I'm
not sure what to do with this result.

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



[[alternative HTML version deleted]]

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


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

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


Re: [R] lattice: how to center a subtitle?

2011-04-05 Thread David Scott

On 6/04/2011 12:47 a.m., Deepayan Sarkar wrote:

On Tue, Apr 5, 2011 at 6:12 AM, David Scottd.sc...@auckland.ac.nz  wrote:

[...]


I am not sure where I read it and I can't find it again, but my
understanding is that expressions using bquote with lattice need to be
enclosed in as.expression() to work. That is in contrast to what happens in
base graphics.

Here is a simple example.

a- 2
plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
require(lattice)
xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))
xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a

Which produces:


a- 2
plot(1:10, a*(1:10), main = bquote(alpha == .(a)))
require(lattice)

Loading required package: lattice

xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a)))

Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond = list(c(1L,  :
  object 'alpha' not found

xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a


Using expression() rather than as.expression() doesn't produce the desired
affect. Try it yourself.

As to why this is the case .


Let's see: ?xyplot says

   'main': Typically a character string or expression describing
   the main title to be placed on top of each page. [...]

So, lattice is fairly explicit, by R standards, in requiring 'main' to
be character or expression. On the other hand, ?title says

  The labels passed to 'title' can be character strings or language
  objects (names, calls or expressions), or [...]

so it additionally accepts names and calls.

Now, we have


a- 2
foo- bquote(alpha == .(a))



foo # Looks OK

alpha == 2

mode(foo) # But

[1] call

is.expression(foo) # not an expression

[1] FALSE


is.expression(expression(foo)) ## YES, but

[1] TRUE

expression(foo) ## not what we want

expression(foo)


is.expression(as.expression(foo))

[1] TRUE

as.expression(foo) ## This IS what we want

expression(alpha == 2)

So I submit that lattice is behaving exactly as suggested by its documentation.

Now you would naturally argue that this is hiding behind
technicalities, and if call objects work for plot(), it should work
for lattice as well. But watch this:


plot(1:10, main = foo) # works perfectly



arglist- list(1:10, main = foo)
arglist # Looks like what we want

[[1]]
  [1]  1  2  3  4  5  6  7  8  9 10

$main
alpha == 2


do.call(plot, arglist)

Error in as.graphicsAnnot(main) : object 'alpha' not found

...which I would say is unexpected behaviour, if not a bug.

The moral of the story is that unevaluated calls are dangerous objects
(try this one out for fun:

foo- bquote(q(.(x)), list(x = no))
do.call(plot, list(1:10, main = foo))

), and carrying them around is not a good idea.

Lattice does use the do.call paradigm quite a bit, and I think it
might be quite difficult to fix it up to handle non-expression
language objects (which will still not fix the type of problem shown
above).

-Deepayan


Thanks very much for this explanation Deepayan. Part of my intention in 
contributing to this thread was to have something explicit in the 
archives for future reference, and your reply is excellent in that regard.


And many thanks for your work on lattice.

David Scott

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

Director of Consulting, Department of Statistics

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


[R] solveRsocp in fPortfolio

2011-04-05 Thread Luis Felipe Parra
Hello I am trying to use solveRsocp to optimize a Portfolio maximizing
return. I was checking the code since I would like to solve it for a short
Portfolio and I found this:

# C - Cone Constraints:
C1 - rep(0, nAssets) # xCx
C2 - eqsumW[2, -1]   # sum(x)
C3 - rbind(diag(nAssets), -diag(nAssets) )   # x[i]0

# d - Cone Constraints:
d1 - targetRisk  # xCx = risk
d2 - eqsumW[2, 1]# sum(x) = 1
d3 - c(rep(0, nAssets), rep(-1, nAssets))# x[i]  0

I was wondering if the conditions C3 and d3 aren't forcing the portfolio to
be always a LongOnly portfolio? I tried modifying the code to take out
these conditions and got the following error:

Error en .socp.phase1(f, A, b, N, control) : Phase 1 failed, alpha=0

Does anybody knkow what might be going on? Is there any problem with this
solver for negative weights?

Thank you

Felipe Parra

[[alternative HTML version deleted]]

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


[R] Search arrays based on similar values

2011-04-05 Thread mjdubya
Hey folks,
I have two arrays: A (1X100) with non-ordered values ranging 1-14  
  B (2X14)  containing 14 decimal values.  
I would like to create a new array (1X100) that contains only the decimal
values from array B by associating the integers from A and B.  In other
words, for each value of A find the same integer value of B, select the
associated decimal value of B.  

A  B newarray
1   1  0.1 0.1
1   2  0.3 0.1
1   3  0.14   0.1
2   4  0.2 0.3
3   5  0.82   0.14
3   6  0.21   0.14
4.   .  0.2
7.   .   .
14  .   ..
4  14 0.03.
3. 
5. 
. .
. . 

Any suggestions are greatly appreciated!  

--
View this message in context: 
http://r.789695.n4.nabble.com/Search-arrays-based-on-similar-values-tp3429381p3429381.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] IFELSE function XXXX

2011-04-05 Thread Ben Bolker
William Dunlap wdunlap at tibco.com writes:

 Avoid assignments in arguments to function calls, especially
 multiple assignments to the same object, except when you know
 what you are doing and want to write obscure code.
 
 Change the above line to
   data3$input1 - ifelse(data3$res1==1, data3$input1+10, data3input1)
 

  data3 - transform(data3,input1=ifelse(res==1,input1+10,input1))

 might be even clearer

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Search arrays based on similar values

2011-04-05 Thread David Winsemius


On Apr 5, 2011, at 6:34 PM, mjdubya wrote:


Hey folks,
I have two arrays: A (1X100) with non-ordered values ranging 1-14
 B (2X14)  containing 14 decimal values.
I would like to create a new array (1X100) that contains only the  
decimal
values from array B by associating the integers from A and B.  In  
other
words, for each value of A find the same integer value of B, select  
the

associated decimal value of B.


Sounds like a job for merge(). Tested solutions offered when  
reproducible examples are provided.




A  B newarray
1   1  0.1 0.1
1   2  0.3 0.1
1   3  0.14   0.1
2   4  0.2 0.3
3   5  0.82   0.14
3   6  0.21   0.14
4.   .  0.2
7.   .   .
14  .   ..
4  14 0.03.
3.
5.
. .
. .


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] R gui on windows how to force to always show the last line of output

2011-04-05 Thread stan zimine
thank you, David, for your answer, which has a therapeutic effect.

Otherwise i was launching my prod code  from Emacs ESS  jas as Janice
suggested.


On Sat, Apr 2, 2011 at 2:27 PM, David Winsemius dwinsem...@comcast.net wrote:

 On Apr 2, 2011, at 4:21 AM, stan zimine wrote:

 Hi.
 Googled but did not found the answer for the following little issue.

 how to force R gui  on windows (maybe a specific setting)  to always
 show the last line of output in the window console.


 My program in R makes measurements every 5 mins in indefinite loop and
 prints  results in the console.

 The problem:  last messages are not visible,  The scrolling bar of the
 gui console  gets shorter. I.e.  you have to scroll for the last
 messages.

 Thanks if anybody knows the sol to this prob.

 You may want to add flush.console() to the 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] merging 2 frames while keeping all the entries from the reference frame

2011-04-05 Thread Dimitri Liakhovitski
Thanks a lot - these solutions are much more elegant than my own:

new.data-merge(mydata[mydata$group %in%
levels(mydata$group)[1],],reference,by=mydate,all.x=T,all.y=T)
new.data[[group]][is.na(new.data[[group]])]-levels(mydata$group)[1]
new.data[[values]][is.na(new.data[[values]])]-0

# Continue Merging - starting with Group2:
for(i in 2:nlevels(mydata$group)){  #i-2
temp-merge(mydata[mydata$group %in%
levels(mydata$group)[i],],reference,by=mydate,all.x=T,all.y=T)
temp[[group]][is.na(temp[[group]])]-levels(mydata$group)[i]
temp[[values]][is.na(temp[[values]])]-0
new.data-rbind(new.data,temp)
}

Dimitri

On Mon, Apr 4, 2011 at 3:07 PM, Henrique Dallazuanna www...@gmail.com wrote:
 Try this:

  merge(mydata, cbind(reference, group = rep(unique(mydata$group), each
 = nrow(reference))), all = TRUE)

 On Mon, Apr 4, 2011 at 2:24 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 To clarify just in case, here is the result I am trying to get:

 mydate  group   values
 12/29/2008      Group1  0.453466522
 1/5/2009        Group1  NA
 1/12/2009       Group1  0.416548943
 1/19/2009       Group1  2.066275155
 1/26/2009       Group1  2.037729638
 2/2/2009        Group1  -0.598040483
 2/9/2009        Group1  1.658999227
 2/16/2009       Group1  -0.869325211
 12/29/2008      Group2  NA
 1/5/2009        Group2  NA
 1/12/2009       Group2  NA
 1/19/2009       Group2  0.375284194
 1/26/2009       Group2  0.706785401
 2/2/2009        Group2  NA
 2/9/2009        Group2  2.104937151
 2/16/2009       Group2  2.880393978



 On Mon, Apr 4, 2011 at 1:09 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 Hello!
 I have my data frame mydata (below) and data frame reference -
 that contains all the dates I would like to be present in the final
 data frame.
 I am trying to merge them so that the the result data frame contains
 all 8 dates in both subgroups (i.e., Group1 should have 8 rows and
 Group2 too). But when I merge it it's not coming out this way. Any
 hint would be greatly appreciated!
 Dimitri

 mydata-data.frame(mydate=rep(seq(as.Date(2008-12-29), length = 8,
 by = week),2),
 group=c(rep(Group1,8),rep(Group2,8)),values=rnorm(16,1,1))
 (reference);(mydata)
 set.seed(1234)
 out-sample(1:16,5,replace=F)
 mydata-mydata[-out,]; dim(mydata)
 (mydata)

 # reference contains the dates I want to be present in the final data 
 frame:
 reference-data.frame(mydate=seq(as.Date(2008-12-29), length = 8, by
 = week))

 # Merging:
 new.data-merge(mydata,reference,by=mydate,all.x=T,all.y=T)
 new.data-new.data[order(new.data$group,new.data$mydate),]
 (new.data)
 # my new.data contains only 7 rows in Group 1 and 4 rows in Group 2


 --
 Dimitri Liakhovitski
 Ninah Consulting




 --
 Dimitri Liakhovitski
 Ninah Consulting
 www.ninah.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.




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




-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.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] A fortunes candidate?

2011-04-05 Thread Bert Gunter
A fortunes candidate?

On Tue, Apr 5, 2011 at 3:59 PM, David Winsemius dwinsem...@comcast.net wrote:

... snipped

 Tested solutions offered when reproducible examples are provided. 





-- 
Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions.

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

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


[R] Error in match.names(clabs, names(xi))

2011-04-05 Thread Quan Zhou
Hi Guys,
I have this part of a program:
library(survival)
Gastric - cbind.data.frame(Gp=c(rep(1,45),rep(0,45)),  ### 2nd gp 0
time=c(1,63,105,129,182,216,250,262,301,301,342,354,356,358,
380,383, 383,388,394,408,460,489,499,523,524,535,562,569,675,676,
748,778,786,797,955,968,1000,1245,1271,1420,1551,1694,2363,2754,2950,
17,42,44,48,60,72,74,95,103,108,122,144,167,170,183,185,193,195,197,
208,234,235,254,307,315,401,445,464,484,528,542,547,577,580,795,855,
1366,1577,2060,2412,2486,2796,2802,2934,2988), Dth=c(rep(1,43),
0,0, rep(1,39), rep(0,6)))
CoxG0 - coxph(Surv(time,Dth) ~ Gp, Gastric)
srvGastA - survfit(Surv(Gastric$time,Gastric$Dth)~1) ## 88 distinct times
#Gastric$time is all the time points either death or largest obervation
time.
#srvGastA$time is all the unique times
newGas - data.frame(start=0, stop=1, Dth=1, Ploidy=1, tim=0)
#newGas - r(0,1,1,1,0)
for (i in 2:90) {
timind - match(Gastric$time[i],srvGastA$time)
tmpmat - array(0, dim=c(timind,5))#build an array with dim('index',5)
tmpmat[,4] - rep(Gastric[i,1], timind)#fourth column, return i's group
tmpmat[timind,3] - Gastric$Dth[i]
tmpmat[,1] - if(timind1) c(0,srvGastA$time[1:(timind-1)]) else 0
tmpmat[,2] - srvGastA$time[1:timind]
newGas - rbind(newGas,tmpmat) }

I found when include the last line in the for loop. the error will jump
out. But I do not know how to fix it. I initialize newGas without names. it
does not work either
It would be great if anyone knows how to fix the problem. Thanks a lot.
BR
Quan

[[alternative HTML version deleted]]

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


Re: [R] A fortunes candidate?

2011-04-05 Thread John Kane
Sounds more like an advertisement  A bit like the old TV story Paladin, have 
gun, will travel. 

--- On Tue, 4/5/11, Bert Gunter gunter.ber...@gene.com wrote:

 From: Bert Gunter gunter.ber...@gene.com
 Subject: [R] A fortunes candidate?
 To: David Winsemius dwinsem...@comcast.net
 A fortunes candidate?
 
 On Tue, Apr 5, 2011 at 3:59 PM, David Winsemius dwinsem...@comcast.net
 wrote:
 
  Tested solutions offered when reproducible examples are
 provided. 


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error in match.names(clabs, names(xi))

2011-04-05 Thread David Winsemius


On Apr 5, 2011, at 8:28 PM, Quan Zhou wrote:


Hi Guys,
I have this part of a program:
library(survival)
Gastric - cbind.data.frame(Gp=c(rep(1,45),rep(0,45)),  ### 2nd gp 0
   time=c(1,63,105,129,182,216,250,262,301,301,342,354,356,358,
   380,383, 383,388,394,408,460,489,499,523,524,535,562,569,675,676,

748,778,786,797,955,968,1000,1245,1271,1420,1551,1694,2363,2754,2950,

17,42,44,48,60,72,74,95,103,108,122,144,167,170,183,185,193,195,197,

208,234,235,254,307,315,401,445,464,484,528,542,547,577,580,795,855,

   1366,1577,2060,2412,2486,2796,2802,2934,2988), Dth=c(rep(1,43),
   0,0, rep(1,39), rep(0,6)))
CoxG0 - coxph(Surv(time,Dth) ~ Gp, Gastric)
srvGastA - survfit(Surv(Gastric$time,Gastric$Dth)~1) ## 88 distinct  
times
#Gastric$time is all the time points either death or largest  
obervation

time.
#srvGastA$time is all the unique times
newGas - data.frame(start=0, stop=1, Dth=1, Ploidy=1, tim=0)
#newGas - r(0,1,1,1,0)
for (i in 2:90) {
   timind - match(Gastric$time[i],srvGastA$time)
   tmpmat - array(0, dim=c(timind,5))#build an array with  
dim('index',5)
   tmpmat[,4] - rep(Gastric[i,1], timind)#fourth column, return i's  
group

   tmpmat[timind,3] - Gastric$Dth[i]
   tmpmat[,1] - if(timind1) c(0,srvGastA$time[1:(timind-1)]) else 0
   tmpmat[,2] - srvGastA$time[1:timind]
   newGas - rbind(newGas,tmpmat) }


You haven't told us what you expect (or even what you are trying to  
do),  but if you add an assignment of colnames before the final  
rbind()-ing of a data.frame and a matrix you get some sort of result:


.
+tmpmat[,2] - srvGastA$time[1:timind] ; colnames(tmpmat) -  
names(newGas)

+newGas - rbind(newGas,tmpmat) }
 str(newGas)
'data.frame':   3988 obs. of  5 variables:
 $ start : num  0 0 1 17 42 44 48 60 0 1 ...
 $ stop  : num  1 1 17 42 44 48 60 63 1 17 ...
 $ Dth   : num  1 0 0 0 0 0 0 1 0 0 ...
 $ Ploidy: num  1 1 1 1 1 1 1 1 1 1 ...
 $ tim   : num  0 0 0 0 0 0 0 0 0 0 ...




I found when include the last line in the for loop. the error will  
jump
out. But I do not know how to fix it. I initialize newGas without  
names.


Good luck with trying to make a data.frame without column names.


it
does not work either
It would be great if anyone knows how to fix the problem. Thanks a  
lot.

BR
Quan



--
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] Pulling strings from a Flat file

2011-04-05 Thread Kalicin, Sarah
Hi,

I have a flat file that contains a bunch of strings that look like this. The 
file was originally in Unix and brought over into Windows:

E123456E234567E345678E456789E567891E678910E. . . .
Basically the string starts with E and is followed with 6 numbers. One 
string=E123456, length=7 characters. This file contains 10,000's of these 
strings. I want to separate them into one vector the length of the number of 
strings in the flat file, where each string is it's on unique value.

cc-c(7,7,7,7,7,7,7)
 aa- file(Master,r, raw=TRUE)
 readChar(aa, cc, useBytes = FALSE)
[1] E123456  \nE23456 7\nE3456 78\nE456 789\nE56 7891\nE6 78910\nE
 close(aa)
 unlink(Master)

The biggest issue is I am getting \n added into the string, which I am not sure 
where it is coming from, and splices the strings. Any suggestions on getting 
rid of the /n and create an infinite sequence of 7's for the string length for 
the cc vector? Is there a better way to do this?

Sarah



[[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] Pulling strings from a Flat file

2011-04-05 Thread David Winsemius


On Apr 5, 2011, at 7:48 PM, Kalicin, Sarah wrote:


Hi,

I have a flat file that contains a bunch of strings that look like  
this. The file was originally in Unix and brought over into Windows:


E123456E234567E345678E456789E567891E678910E. . . .
Basically the string starts with E and is followed with 6 numbers.  
One string=E123456, length=7 characters. This file contains 10,000's  
of these strings. I want to separate them into one vector the length  
of the number of strings in the flat file, where each string is it's  
on unique value.


cc-c(7,7,7,7,7,7,7)

aa- file(Master,r, raw=TRUE)
readChar(aa, cc, useBytes = FALSE)
[1] E123456  \nE23456 7\nE3456 78\nE456 789\nE56  
7891\nE6 78910\nE

close(aa)
unlink(Master)


 txt - E123456E234567E345678E456789E567891E678910E
# You could use readLines to bring in from the file
# and assign to a character vector for work in R.

 gsub((E[[:digit:]]{6}), \\1\n, txt)
[1] E123456\nE234567\nE345678\nE456789\nE567891\nE678910\nE
# Seems to be working properly

 ?scan

 scan(textConnection(gsub((E[[:digit:]]{6}), \\1\n, txt)),  
what=character)

Read 7 items
[1] E123456 E234567 E345678 E456789 E567891 E678910 E

You might be able to use read.table or variants.



The biggest issue is I am getting \n added into the string, which I  
am not sure where it is coming from, and splices the strings. Any  
suggestions on getting rid of the /n and create an infinite sequence  
of 7's for the string length for the cc vector? Is there a better  
way to do this?


Sarah



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] Arrangement of Lattice Histograms - Top to bottom and then left to right?

2011-04-05 Thread Deepayan Sarkar
On Wed, Apr 6, 2011 at 12:34 AM, Bert Gunter gunter.ber...@gene.com wrote:
 Look for the index.cond argument at the bottom of the Help page for xyplot.
 -- Bert

Also ?print.trellis and ?packet.panel.default for a more general
(non-example-specific) approach.

-Deepayan

 On Tue, Apr 5, 2011 at 11:37 AM, Les lnhar...@zoology.ubc.ca wrote:
 Hi List,
 Using Lattice, I have created a plot of histograms showing Fork Length by
 Year. The plot shows the histograms in 3 columns and 5 rows. Using the
 as.table=T function I can get the years to start on top. However, what I
 would like to do is have the first year start in the top left (column 1, row
 1; as it is now) and add the subsequent histograms to the plot going down
 the column and then over by row (example and current code is shown below).
 Is this possible? I have spent a great deal of time searching, and have not
 found any clues. Any help/ideas would be greatly appreciated.

 For example, what is being done now:

 1974 1975 1976
 1977 1978 1979
 1980 1981 1982

 and what I am hoping for:

 1974 1977 1980
 1975 1978 1981
 1976 1979 1982

 Thank you kindly,
 Les

 data=read.csv(AllData.csv,sep=,,header=T)
 data$year=as.factor(data$year)
 ferg=data[data$wtrbody==Ferguson,c(1:12)]
 library(lattice)

 strip.background=trellis.par.get(strip.background)
 trellis.par.set(strip.background = list(col = grey(7:1/8)))

 histogram(~fl|year, data=ferg, as.table=T, type=count,
        col='dark grey',layout=c(3,5),lwd=2, lty=1,
        xlab=list(Fork Length (mm), cex=1.4,font=2),
        breaks=seq(from=300,to=900,by=25),
        ylab=list(Frequency,cex=1.4,font=2),
        scales=list(font=2,cex=1.1, tck=c(1,0), alternating=1,
        y=list(relation=free,tick.number=3)),
        par.strip.text=list(cex=1.2),font=2,
        aspect=0.6)

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Arrangement-of-Lattice-Histograms-Top-to-bottom-and-then-left-to-right-tp3428825p3428825.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.




 --
 Men by nature long to get on to the ultimate truths, and will often
 be impatient with elementary studies or fight shy of them. If it were
 possible to reach the ultimate truths without the elementary studies
 usually prefixed to them, these would not be preparatory studies but
 superfluous diversions.

 -- Maimonides (1135-1204)

 Bert Gunter
 Genentech Nonclinical Biostatistics

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


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