Re: [R] odfWeave and xtable

2008-01-13 Thread 宋时歌
Hi Frank,

I use Hmisc and Design in my research a lot, the LaTeX facilities are
very handy. But I don't think they can work with OpenOffice document
format (ODF), or did I miss something?

Thanks.

Shige

On Jan 13, 2008 2:03 AM, Frank E Harrell Jr <[EMAIL PROTECTED]> wrote:
>
> ??? wrote:
> > Dear All,
> >
> > I am new to odfWeave and was wondering if there are something similar
> > to the xtable package that can automatically convert model
> > coefficients into LaTeX/ODT tables?  More generally, how do people who
> > use odfWeave transform model results into tables? The odfTable does
> > not seem to be able to do this (maybe I am wrong, and would appreciate
> > some demos). Thanks.
> >
> > Best,
> > Shige
>
> This is not related to tables, but see the latex methods in the Design
> package.  There are methods for using LaTeX to typeset various kinds of
> regression model fits.
>
> Frank
>
> --
> Frank E Harrell Jr   Professor and Chair   School of Medicine
>   Department of Biostatistics   Vanderbilt University
>

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


[R] Multiple correspondence analysis

2008-01-13 Thread Bernardo Rangel Tura
Hi R-people,

I try using mca (multiple correspondence analysis) in evocation data
(data base feminino2.csv attach in this mail).

Well in this database have 4 evocations for each 120 persons.

If I use this script:

base<-read.csv("feminino2.csv")

require(MASS)

plot(mca(base,abbrev=T),rows = F)

Work, but result in a ugly plot, so I try extract levels with low
frequency:


niveis<-unique(c(levels(base$p1),levels(base$p2),levels(base
$p3),levels(base$p4))) 

v<-table(factor(base$p1,levels=niveis))+ table(factor(base
$p2,levels=niveis))+table(factor(base$p3,levels=niveis))+ 

n2<-niveis[v>=5] #where 5 is cutoff frequency

evoc.df<-data.frame(factor(base$p1,levels=n2),factor(base
$p2,levels=n2),factor(base$p3,levels=n2),factor(base$p4,levels=n2))

names(evoc.df)<-c("p1","p2","p3","p4")

plot(mca(evoc.df,abbrev=T),rows = F)

Don't work and result in a error:

Error in svd(X) : infinite or missing values in 'x'

Where I worng? Anybody help me?

Thanks in advance


-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Bonne année 2008

2008-01-13 Thread Isabelle

 Si ce message ne s'affiche pas correctement [1]cliquez ici
[2]
  [logotype.gif] 
Toute l'équipe de [3]PUXOU.fr vous souhaite une bonne et heureuse année 2008
 Que cette nouvelle année soit pour vous l'année de toutes vos réussites ...
  [arrow_right.gif] [4]www.puxou.fr , 1er service internet de rencontres en
   ligne classé numéro 1 chez les plus de 40 ans

   Pour vous désinscrire :
   [5]http://www.smt-online.com/newsletters/subscription.php?list_id=8&op=leave
   &email_addr=r-help%40stat.math.ethz.ch

References

   1. http://www.puxou.com/
   2. http://www.puxou.com/
   3. http://www.puxou.com/
   4. http://www.puxou.com/
   5. 
http://www.smt-online.com/newsletters/subscription.php?list_id=8&op=leave&[EMAIL
 PROTECTED]
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] question regarding hypothesis testing in contingency tables

2008-01-13 Thread Bernardo Rangel Tura

On Thu, 2008-01-10 at 09:47 -0800, eugen pircalabelu wrote:
> Hi R-users!
> 
> I have the following example:
> a<-data.frame(cat=c(5,10,15), dog=c(5,10, 15), mouse=c(10,10,20))
> b<-data.frame(cat=c(15,10,5), dog=c(15, 10, 5), mouse=c(20,10,10))
> rownames(b)<-c("scared", "happy", "sad")
> rownames(a)<-c("scared", "happy", "sad")
> 
(...)
> Another thing that i want to see , is which cells differ one from another? Eg 
> is the 5 percent of scared dogs from sample a, 
> different from  15% of scared dogs form sample b? I would like something like 
> the "adjusted standardized reziduals" test from SPSS?
(...)
> Thank you and have a great day!

Hi Eugen!

The adjusted standardized residuals is available in package gmodels

require(gmodels)
?CrossTable


-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 equivalent of par(mfrow = )

2008-01-13 Thread Michael Kubovy
Dear R-helpers,

On Jan 12, 2008, at 5:17 PM, Deepayan Sarkar wrote:

> On 1/12/08, Michael Kubovy <[EMAIL PROTECTED]> wrote:
>> Dear r-helpers,
>>
>> Does anyone have a straightforward example of putting together three
>> unrelated (expect for a common y-axis) xyplot() figures in what would
>> be in base graphics a par(mfrow = c(1, 3)) arrangement?
>
> See the examples in ?print.trellis.

Thanks. Now how do I insure that the three y-axes are the same scale  
in the following?

states <- data.frame(state.x77,
  state.name = dimnames(state.x77)[[1]],
  state.region = state.region)
plot1 <- xyplot(Murder ~ Population, data = states,
xlab = grid::textGrob(expression(frac(abs(bold(c)), abs(bold(b,  
gp=gpar(fontsize=25)),
ylab = grid::textGrob(expression(paste(log, frac(italic(p) 
(italic(c)), italic(p)(italic(b), gp = gpar(fontsize = 25)),
)
plot2 <- xyplot(Murder ~ Population, data = states,
xlab = grid::textGrob(expression(gamma), gp = gpar(fontsize= 25)),
ylab = '',
)
plot3 <- xyplot(Murder ~ Population, data = states,
xlab =  
grid::textGrob(expression(frac(abs( bold(c) ),abs( bold(b) ))), gp =  
gpar(fontsize = 25)),
ylab = '',
)
print(plot1, position = c(0.0, 0, 0.33, 1), more = TRUE)
print(plot2, position = c(0.33, 0, 0.67, 1), more = TRUE)
print(plot3, position = c(0.67, 0, 1, 1))

_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
 McCormick RoadCharlottesville, VA 22903
Office:B011+1-434-982-4729
Lab:B019+1-434-982-4751
Fax:+1-434-982-4766
WWW:http://www.people.virginia.edu/~mk9y/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Merci de confirmer votre désinscription

2008-01-13 Thread Isabelle
Quelqu'un, certainement vous, a demandé votre désinscription de cette lettre 
d'info, merci de suivre les informations qui suivent.

Pour vous désinscrire, cliquez sur le lien suivant :
http://www.smt-online.com/newsletters/subscription.php?op=confirm_leave&email_addr=r-help%40stat.math.ethz.ch&hash=bef8404d3a031f66767902866e29ffe5&list_id=8

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


Re: [R] question about xreg of arima

2008-01-13 Thread tom soyer
Thanks Richard. I am just trying to understand exactly what is R's arima
doing, and I am having a hard time. It seems that xreg is necessary to force
arima to include the constant term, but it appears that exactly how this is
done is not documented. If a series is not differenced, e.g. AR(1), then
does one still need to include xreg? If I take an AR(1) series with known
coefficient and use arima to do the fit using arima, i.e., arima(x = ar1,
order = c(1, 0, 0)), the estimated coefficient is not as good as a simple lm
fit using a one period lag. I am wondering if this should be the expected
result? Then, I tried Robert Shumway's sarima, and it gave me a much better
coefficient compared to arima (but still a little bit worse than lm). I
don't understand why this is happening. I guess I am even more confused...



On 1/12/08, Richard Saba <[EMAIL PROTECTED]> wrote:
>
>  Tom
>
> A constant term is not included in the model if any differencing is
> specified. The xreg= parameter is used to add other explanatory variables to
> the model. In your case xreg=1:length(x) adds a vector of 1's to the model.
> Robert Shumway and David Stoffer's website for their  "Time Series Analysis
> an its Applications with R Examples" text has several very helpful documents
> posted on the site (http://www.stat.pitt.edu/stoffer/tsa2/index.html)
> specific to time series analysis. The R ISSUES document address your
> question.
>
>
>
> Richard
>
>
>
> >Hi,
>
> >I am trying to understand exactly what xreg does in arima. The
> documentation for xreg says:"xreg Optionally, a vector or matrix of external
> regressors, which must have >the same number of rows as x." What does this
> mean with regard to the action of xreg in arima?
>
>
>
>
>
> >Apparently somehow xreg made the following two arima fit equivalent in R:
>
>
> >arima(x, order=c(1,1,1), xreg=1:length(x))
>
> >is the same as
>
> > arima(diff(x), order=c(1,0,1))
>
> >While I understand the latter fit (I think), I am puzzled with regard to
> the former. Does anyone know what the former is doing to arima, and why it
> works as it does?
>
> >Thanks!
>
> --
>
> >Tom
>
>
>
> Richard Saba
>
> Department of Economics
>
> Auburn University
>
> Auburn, AL 36849  USA
>
> [EMAIL PROTECTED]
>
>
>
>
>



-- 
Tom

[[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] Retrieve only part of a matrix

2008-01-13 Thread My Coyne
Hi All,

I'm new with R; this is a basic question. I was given a matrix I of (nrow,
ncol), I would like to create another matrix A with some data in the matrix
I, say [1,4] (row 1, column 4) to [271,19000] (row 271, column 19000).  How
do I do this?  Please help.  Thank you very much.

 

--mc

 

 

 

 

 


[[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 equivalent of par(mfrow = )

2008-01-13 Thread jim holtman
You need to make sure all your xlab's are the same size.  Try:

states <- data.frame(state.x77,
 state.name = dimnames(state.x77)[[1]],
 state.region = state.region)
plot1 <- xyplot(Murder ~ Population, data = states,
   xlab = grid::textGrob(expression(frac(abs(bold(c)), abs(bold(b,
gp=gpar(fontsize=25)),
   ylab = grid::textGrob(expression(paste(log, frac(italic(p)
(italic(c)), italic(p)(italic(b), gp = gpar(fontsize = 25)),
)
plot2 <- xyplot(Murder ~ Population, data = states,
   xlab = grid::textGrob(expression(atop(gamma,"")), gp =
gpar(fontsize= 25)),
   ylab = '',
)
plot3 <- xyplot(Murder ~ Population, data = states,
   xlab =
grid::textGrob(expression(frac(abs( bold(c) ),abs( bold(b) ))), gp =
gpar(fontsize = 25)),
   ylab = '',
)
print(plot1, position = c(0.0, 0, 0.33, 1), more = TRUE)
print(plot2, position = c(0.33, 0, 0.67, 1), more = TRUE)
print(plot3, position = c(0.67, 0, 1, 1))



On Jan 13, 2008 7:40 AM, Michael Kubovy <[EMAIL PROTECTED]> wrote:
> Dear R-helpers,
>
> On Jan 12, 2008, at 5:17 PM, Deepayan Sarkar wrote:
>
> > On 1/12/08, Michael Kubovy <[EMAIL PROTECTED]> wrote:
> >> Dear r-helpers,
> >>
> >> Does anyone have a straightforward example of putting together three
> >> unrelated (expect for a common y-axis) xyplot() figures in what would
> >> be in base graphics a par(mfrow = c(1, 3)) arrangement?
> >
> > See the examples in ?print.trellis.
>
> Thanks. Now how do I insure that the three y-axes are the same scale
> in the following?
>
> states <- data.frame(state.x77,
>   state.name = dimnames(state.x77)[[1]],
>   state.region = state.region)
> plot1 <- xyplot(Murder ~ Population, data = states,
> xlab = grid::textGrob(expression(frac(abs(bold(c)), abs(bold(b,
> gp=gpar(fontsize=25)),
> ylab = grid::textGrob(expression(paste(log, frac(italic(p)
> (italic(c)), italic(p)(italic(b), gp = gpar(fontsize = 25)),
> )
> plot2 <- xyplot(Murder ~ Population, data = states,
> xlab = grid::textGrob(expression(gamma), gp = gpar(fontsize= 25)),
> ylab = '',
> )
> plot3 <- xyplot(Murder ~ Population, data = states,
> xlab =
> grid::textGrob(expression(frac(abs( bold(c) ),abs( bold(b) ))), gp =
> gpar(fontsize = 25)),
> ylab = '',
> )
> print(plot1, position = c(0.0, 0, 0.33, 1), more = TRUE)
> print(plot2, position = c(0.33, 0, 0.67, 1), more = TRUE)
> print(plot3, position = c(0.67, 0, 1, 1))
>
> _
> Professor Michael Kubovy
> University of Virginia
> Department of Psychology
> USPS: P.O.Box 400400Charlottesville, VA 22904-4400
> Parcels:Room 102Gilmer Hall
>  McCormick RoadCharlottesville, VA 22903
> Office:B011+1-434-982-4729
> Lab:B019+1-434-982-4751
> Fax:+1-434-982-4766
> WWW:http://www.people.virginia.edu/~mk9y/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Cincinnati, OH
+1 513 646 9390

What is the problem 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] odfWeave and xtable

2008-01-13 Thread 宋时歌
Thanks, Frank. The clarification as well as the referred resources are
extremely helpful.

Shige

On Jan 13, 2008 10:14 PM, Frank E Harrell Jr <[EMAIL PROTECTED]> wrote:
> 宋时歌 wrote:
> > Hi Frank,
> >
> > I use Hmisc and Design in my research a lot, the LaTeX facilities are
> > very handy. But I don't think they can work with OpenOffice document
> > format (ODF), or did I miss something?
> >
> > Thanks.
> >
> > Shige
>
> You're correct.  Conversion from LaTeX to OpenOffice or Word is
> addressed at http://biostat.mc.vanderbilt.edu/SweaveConvert.  I have had
> good success opening the output of tth in Firefox and copying and
> pasting into OpenOffice, as this operation preserves all table and other
> formatting.
>
> When I wrote about latex(model fit) earlier I was referring to obtaining
> the algebraic form of a fitted model, handling such things as restricted
> cubic splines and factoring out variables in interaction terms.  The
> latex methods in Design do not produce tables of coefficients and
> standard errors.
>
> Frank
>
> >
> > On Jan 13, 2008 2:03 AM, Frank E Harrell Jr <[EMAIL PROTECTED]> wrote:
> >> ??? wrote:
> >>> Dear All,
> >>>
> >>> I am new to odfWeave and was wondering if there are something similar
> >>> to the xtable package that can automatically convert model
> >>> coefficients into LaTeX/ODT tables?  More generally, how do people who
> >>> use odfWeave transform model results into tables? The odfTable does
> >>> not seem to be able to do this (maybe I am wrong, and would appreciate
> >>> some demos). Thanks.
> >>>
> >>> Best,
> >>> Shige
> >> This is not related to tables, but see the latex methods in the Design
> >> package.  There are methods for using LaTeX to typeset various kinds of
> >> regression model fits.
> >>
> >> Frank
> >>
> >> --
> >> Frank E Harrell Jr   Professor and Chair   School of Medicine
> >>   Department of Biostatistics   Vanderbilt University
> >>
> >
>
>
> --
>
> Frank E Harrell Jr   Professor and Chair   School of Medicine
>   Department of Biostatistics   Vanderbilt University
>
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Retrieve only part of a matrix

2008-01-13 Thread Henrique Dallazuanna
Try this:

A <- I[1:271, 4:19000]


On 13/01/2008, My Coyne <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I'm new with R; this is a basic question. I was given a matrix I of (nrow,
> ncol), I would like to create another matrix A with some data in the matrix
> I, say [1,4] (row 1, column 4) to [271,19000] (row 271, column 19000).  How
> do I do this?  Please help.  Thank you very much.
>
>
>
> --mc
>
>
>
>
>
>
>
>
>
>
>
>
> [[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] odfWeave and xtable

2008-01-13 Thread Frank E Harrell Jr
宋时歌 wrote:
> Hi Frank,
> 
> I use Hmisc and Design in my research a lot, the LaTeX facilities are
> very handy. But I don't think they can work with OpenOffice document
> format (ODF), or did I miss something?
> 
> Thanks.
> 
> Shige

You're correct.  Conversion from LaTeX to OpenOffice or Word is 
addressed at http://biostat.mc.vanderbilt.edu/SweaveConvert.  I have had 
good success opening the output of tth in Firefox and copying and 
pasting into OpenOffice, as this operation preserves all table and other 
formatting.

When I wrote about latex(model fit) earlier I was referring to obtaining 
the algebraic form of a fitted model, handling such things as restricted 
cubic splines and factoring out variables in interaction terms.  The 
latex methods in Design do not produce tables of coefficients and 
standard errors.

Frank

> 
> On Jan 13, 2008 2:03 AM, Frank E Harrell Jr <[EMAIL PROTECTED]> wrote:
>> ??? wrote:
>>> Dear All,
>>>
>>> I am new to odfWeave and was wondering if there are something similar
>>> to the xtable package that can automatically convert model
>>> coefficients into LaTeX/ODT tables?  More generally, how do people who
>>> use odfWeave transform model results into tables? The odfTable does
>>> not seem to be able to do this (maybe I am wrong, and would appreciate
>>> some demos). Thanks.
>>>
>>> Best,
>>> Shige
>> This is not related to tables, but see the latex methods in the Design
>> package.  There are methods for using LaTeX to typeset various kinds of
>> regression model fits.
>>
>> Frank
>>
>> --
>> Frank E Harrell Jr   Professor and Chair   School of Medicine
>>   Department of Biostatistics   Vanderbilt University
>>
> 


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

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


Re: [R] Newbie syntax question

2008-01-13 Thread Peter Dalgaard
jim holtman wrote:
> ?cor.test
>
> and the help page says:
>
> formula:   a formula of the form ~ u + v, where each of u and v are
> numeric variables giving the data values for one sample. The samples
> must be of the same length.
>   
Yes, but does that answer the question? Seems to me that Joe knows what 
it does, just not why.

The logic behind this sort of model formulas is slightly warped, but has 
been with us at least since S-PLUS's crosstabs(). R's xtabs() is quite 
similar. The basic idea is that you can describe a contingency table 
with n dimensions using

count ~  f1 + f2 +  + fn

and leave the count off if it would be the constant 1. The thing that I, 
at least, find a little warped is that "+" in model formulas usually 
prescribes an additive structure, which isn't really the case here. The 
":" operator was arguably a better choice, but, well, another choice was 
made, and has stuck. The final step is to say that correlation between 
two quantitative variables is similar enough to RxC tables for 
categorical variables to let you use the same syntax.  ~x+y does have 
the advantage of not implying a direction as y~x or x~y would do.
> On 1/12/08, Joe Trubisz <[EMAIL PROTECTED]> wrote:
>   
>> Hi...
>>
>> I'm trying to understand the following syntax:
>>
>> cor.test(~mortality + hardness,data=water,method="pearson")
>>
>> which is the same as:
>>
>> cor.test(water$mortality,water$hardness,data=water,method="pearson")
>>
>> Can anyone point me to the correct doc or explain to me how to
>> interpret "~mortality + hardness"?
>>
>> Thanks,
>> Joe
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>> 
>
>
>   


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

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


Re: [R] access to webpage code

2008-01-13 Thread Henrique Dallazuanna
Try this:

code <- readLines(site)


On 13/01/2008, John Lande <[EMAIL PROTECTED]> wrote:
> dear R user,
>
> I need a function that download the code of web page as html, to further
> parse it.
>
> something like
>
> >site="http://www.R-project.com";
> >code=function(site)
> >code
>
> !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> 
> 
> The R Project for Statistical Computing
> 
> 
> 
> 
>
> 
> 
> 
> 
> 
> 
> 
> The R Project for Statistical Computing
>
> Your browser seems not to support frames,
> here is the contents page of the R Project's
> website.
>
> 
> 
>
> is there any function that can perform similar task? thank you in advance.
>
> John
>
> [[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.


[R] access to webpage code

2008-01-13 Thread John Lande
dear R user,

I need a function that download the code of web page as html, to further
parse it.

something like

>site="http://www.R-project.com";
>code=function(site)
>code

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


The R Project for Statistical Computing












The R Project for Statistical Computing

Your browser seems not to support frames,
here is the contents page of the R Project's
website.




is there any function that can perform similar task? thank you in advance.

John

[[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] glm expand model to more values

2008-01-13 Thread Henric Nilsson (Public)
Jarek Jasiewicz wrote:
> Charles Annis, P.E. wrote:
>> Jarek:
>>
>> Although it is not universally agreed on, I believe the first step in any
>> data analysis is to PLOT YOUR DATA.
>>
>> dd <- data.frame(a=c(1, 2, 3, 4, 5, 6), b=c(3,  5,  6,  7,  9, 10))
>> plot(b ~ a, data=dd)
>> simple.model <- lm(b~a,data=dd)
>> abline(simple.model)
>>
>> Why to you think you need a cubic model to describe 6 observations?
>>
>> Your model is overparameterized - it has two more parameters than the number
>> of observations can reasonably justify, something that would be obvious from
>> your plot.
>>
>> The summary of the simple.linear model shows both the intercept and the
>> slope are statistically meaningful.  (That's what the asterisks mean.)
>>
>> Call:
>> lm(formula = b ~ a, data = dd)
>>
>> Residuals:
>>123456 
>> -0.23810  0.39048  0.01905 -0.35238  0.27619 -0.09524 
>>
>> Coefficients:
>> Estimate Std. Error t value Pr(>|t|)
>> (Intercept)  1.866670.30132   6.195  0.00345 ** 
>> a1.371430.07737  17.725 5.95e-05 ***
>> ---
>> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
>>
>> Residual standard error: 0.3237 on 4 degrees of freedom
>> Multiple R-Squared: 0.9874, Adjusted R-squared: 0.9843 
>> F-statistic: 314.2 on 1 and 4 DF,  p-value: 5.952e-05
>>
>> I think you should invest a small amount of your time, and an even smaller
>> amount of your money to purchase and read - cover-to-cover - one of the
>> several very good books on elementary statistics and R.  My recommendation
>> is _Introductory Statistics with R_ by Peter Dalgaard (Paperback - Jan 9,
>> 2004).  Amazon.com carries it.
>>
>> Best wishes.
>>
>>
>>
>> Charles Annis, P.E.
>>
>> [EMAIL PROTECTED]
>> phone: 561-352-9699
>> eFax:  614-455-3265
>> http://www.StatisticalEngineering.com
>>  
>>
>> -Original Message-
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
>> Behalf Of Jarek Jasiewicz
>> Sent: Saturday, January 12, 2008 2:06 PM
>> To: [EMAIL PROTECTED]
>> Cc: R-help@r-project.org
>> Subject: Re: [R] glm expand model to more values
>>
>> Charles Annis, P.E. wrote:
>>   
>>> How many parameters are you trying to estimate?  How many observations do
>>> you have?
>>>
>>> What is wrong is that half of your parameter estimates are statistically
>>> meaningless:
>>>
>>> dd <- data.frame(a=c(1, 2, 3, 4, 5, 6), b=c(3,  5,  6,  7,  9, 10))
>>>
>>> overparameterized.model <- glm(b~poly(a,3),data=dd)
>>>
>>> summary(overparameterized.model)
>>>
>>>
>>> Coefficients:
>>> Estimate Std. Error t value Pr(>|t|)
>>>
>>> (Intercept)   6.6667 0.1725  38.644 0.000669 ***
>>>
>>> poly(a, 3)1   5.7371 0.4226  13.576 0.005382 ** 
>>>
>>> poly(a, 3)2  -0.1091 0.4226  -0.258 0.820395
>>>
>>> poly(a, 3)3   0.2236 0.4226   0.529 0.649562  
>>>
>>>
>>>
>>>
>>> Charles Annis, P.E.
>>>
>>> [EMAIL PROTECTED]
>>> phone: 561-352-9699
>>> eFax:  614-455-3265
>>> http://www.StatisticalEngineering.com
>>>  
>>>
>>> -Original Message-
>>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>>> 
>> On
>>   
>>> Behalf Of Jarek Jasiewicz
>>> Sent: Saturday, January 12, 2008 11:50 AM
>>> To: R-help@r-project.org
>>> Subject: [R] glm expand model to more values
>>>
>>> Hi
>>>
>>> I have the problem with fitting curve to data with lm and glm. When I 
>>> use polynominal dependiency, fitted values from model are OK, but I 
>>> cannot  recive proper values when I use coefficents to caltulate this.  
>>> Let me present simple example:
>>>
>>> I have simple data.frame: (dd)
>>>  a: 1 2 3 4 5 6
>>>  b:  3  5  6  7  9 10
>>>
>>> I try to fit it to model:
>>>
>>> model=glm(b~poly(a,3),data=dd)
>>>  I have following data fitted to model (as I expected)
>>>  > fitted(model)
>>> 1 2 3 4 5 6
>>>  3.095238  4.738095  6.095238  7.33  8.619048 10.119048
>>>
>>> and coef(model)
>>> (Intercept) poly(a, 3)1 poly(a, 3)2 poly(a, 3)3
>>>   6.667   5.7370973  -0.1091089   0.2236068
>>>
>>> so when I try to expand the model to other data (simple extrapolation), 
>>> let say: s=seq(1:10,by=1)
>>>
>>> I do:
>>> extra=sapply(s,function(x) coef(model) %*% x^(0:3))
>>> and here is result:
>>> [1]  12.51826  19.49328  28.93336  42.18015  60.57528  85.46040 118.17714
>>>  [8] 160.06715 212.47207 276.73354
>>>
>>> the data form expanding coefs are completly differnd from fitted
>>>
>>> What's going wrong?
>>>
>>> Jarek
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> 
>> http://www.R-project.org/posting-guide.html
>>   
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>   
>>> 
>> sorry but I cannot understand. What does it means data are statistically 
>> meanningless?
>>
>> It is examle with very simple data which I use according to s

Re: [R] Retrieve only part of a matrix

2008-01-13 Thread John Kane
mymatrix <- oldmatrix[1:271,4:19000]

--- My Coyne <[EMAIL PROTECTED]> wrote:

> Hi All,
> 
> I'm new with R; this is a basic question. I was
> given a matrix I of (nrow,
> ncol), I would like to create another matrix A with
> some data in the matrix
> I, say [1,4] (row 1, column 4) to [271,19000] (row
> 271, column 19000).  How
> do I do this?  Please help.  Thank you very much.
> 
>  
> 
> --mc
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 
>   [[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] access to webpage code

2008-01-13 Thread Prof Brian Ripley
See

?download.file
?url

Omegahat package RCurl

You do realize that the 'code of web page' is just what you download?
E.g.  (working example)

readLines(url("http://www.r-project.org";))

On Sun, 13 Jan 2008, John Lande wrote:

> dear R user,
>
> I need a function that download the code of web page as html, to further
> parse it.
>
> something like
>
>> site="http://www.R-project.com";

Sic!  Not a valid address.

>> code=function(site)
>> code
>
> !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> 
> 
> The R Project for Statistical Computing
> 
> 
> 
> 
>
> 
> 
> 
> 
> 
> 
> 
> The R Project for Statistical Computing
>
> Your browser seems not to support frames,
> here is the contents page of the R Project's
> website.
>
> 
> 
>
> is there any function that can perform similar task? thank you in advance.
>
> John
>
>   [[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.
>

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

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


Re: [R] glm expand model to more values

2008-01-13 Thread Jarek Jasiewicz
Henric Nilsson (Public) wrote:
> Jarek Jasiewicz wrote:
>> Charles Annis, P.E. wrote:
>>> Jarek:
>>>
>>> Although it is not universally agreed on, I believe the first step 
>>> in any
>>> data analysis is to PLOT YOUR DATA.
>>>
>>> dd <- data.frame(a=c(1, 2, 3, 4, 5, 6), b=c(3,  5,  6,  7,  9, 10))
>>> plot(b ~ a, data=dd)
>>> simple.model <- lm(b~a,data=dd)
>>> abline(simple.model)
>>>
>>> Why to you think you need a cubic model to describe 6 observations?
>>>
>>> Your model is overparameterized - it has two more parameters than 
>>> the number
>>> of observations can reasonably justify, something that would be 
>>> obvious from
>>> your plot.
>>>
>>> The summary of the simple.linear model shows both the intercept and the
>>> slope are statistically meaningful.  (That's what the asterisks mean.)
>>>
>>> Call:
>>> lm(formula = b ~ a, data = dd)
>>>
>>> Residuals:
>>>123456 -0.23810  
>>> 0.39048  0.01905 -0.35238  0.27619 -0.09524
>>> Coefficients:
>>> Estimate Std. Error t value Pr(>|t|)(Intercept)  
>>> 1.866670.30132   6.195  0.00345 ** a1.37143
>>> 0.07737  17.725 5.95e-05 ***
>>> ---
>>> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
>>> Residual standard error: 0.3237 on 4 degrees of freedom
>>> Multiple R-Squared: 0.9874, Adjusted R-squared: 0.9843 
>>> F-statistic: 314.2 on 1 and 4 DF,  p-value: 5.952e-05
>>>
>>> I think you should invest a small amount of your time, and an even 
>>> smaller
>>> amount of your money to purchase and read - cover-to-cover - one of the
>>> several very good books on elementary statistics and R.  My 
>>> recommendation
>>> is _Introductory Statistics with R_ by Peter Dalgaard (Paperback - 
>>> Jan 9,
>>> 2004).  Amazon.com carries it.
>>>
>>> Best wishes.
>>>
>>>
>>>
>>> Charles Annis, P.E.
>>>
>>> [EMAIL PROTECTED]
>>> phone: 561-352-9699
>>> eFax:  614-455-3265
>>> http://www.StatisticalEngineering.com
>>>  
>>>
>>> -Original Message-
>>> From: [EMAIL PROTECTED] 
>>> [mailto:[EMAIL PROTECTED] On
>>> Behalf Of Jarek Jasiewicz
>>> Sent: Saturday, January 12, 2008 2:06 PM
>>> To: [EMAIL PROTECTED]
>>> Cc: R-help@r-project.org
>>> Subject: Re: [R] glm expand model to more values
>>>
>>> Charles Annis, P.E. wrote:
>>>  
 How many parameters are you trying to estimate?  How many 
 observations do
 you have?

 What is wrong is that half of your parameter estimates are 
 statistically
 meaningless:

 dd <- data.frame(a=c(1, 2, 3, 4, 5, 6), b=c(3,  5,  6,  7,  9, 10))

 overparameterized.model <- glm(b~poly(a,3),data=dd)

 summary(overparameterized.model)


 Coefficients:
 Estimate Std. Error t value Pr(>|t|)   
 (Intercept)   6.6667 0.1725  38.644 0.000669 ***

 poly(a, 3)1   5.7371 0.4226  13.576 0.005382 **
 poly(a, 3)2  -0.1091 0.4226  -0.258 0.820395   
 poly(a, 3)3   0.2236 0.4226   0.529 0.649562 



 Charles Annis, P.E.

 [EMAIL PROTECTED]
 phone: 561-352-9699
 eFax:  614-455-3265
 http://www.StatisticalEngineering.com
  

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED]
 
>>> On
>>>  
 Behalf Of Jarek Jasiewicz
 Sent: Saturday, January 12, 2008 11:50 AM
 To: R-help@r-project.org
 Subject: [R] glm expand model to more values

 Hi

 I have the problem with fitting curve to data with lm and glm. When 
 I use polynominal dependiency, fitted values from model are OK, but 
 I cannot  recive proper values when I use coefficents to caltulate 
 this.  Let me present simple example:

 I have simple data.frame: (dd)
  a: 1 2 3 4 5 6
  b:  3  5  6  7  9 10

 I try to fit it to model:

 model=glm(b~poly(a,3),data=dd)
  I have following data fitted to model (as I expected)
  > fitted(model)
 1 2 3 4 5 6
  3.095238  4.738095  6.095238  7.33  8.619048 10.119048

 and coef(model)
 (Intercept) poly(a, 3)1 poly(a, 3)2 poly(a, 3)3
   6.667   5.7370973  -0.1091089   0.2236068

 so when I try to expand the model to other data (simple 
 extrapolation), let say: s=seq(1:10,by=1)

 I do:
 extra=sapply(s,function(x) coef(model) %*% x^(0:3))
 and here is result:
 [1]  12.51826  19.49328  28.93336  42.18015  60.57528  85.46040 
 118.17714
  [8] 160.06715 212.47207 276.73354

 the data form expanding coefs are completly differnd from fitted

 What's going wrong?

 Jarek

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

[R] bug in mmlcr ?

2008-01-13 Thread Christophe Genolini
Hi the list.

Is there a bug in mmlcr package ?
The following code does not compile:

mmlcrTest <- function(dataW){
  dataL <- 
reshape(dataW,idvar="id",timevar="T",varying=list(paste("T",0:10,sep="")),direction="long",v.names="score")
 

  resultR <- mmlcr(outer= ~ 1 | id,
   components = list(list(formula = formul,class= 
"normlong")),   
   n.groups=3,
   data=dataL,
   max.iter=500
   )
  plot(resultR)
}
mmlcrTest(dataW)

The error is (translate from french):
"Error in inherits(x, "data.frame") : objet "dataL" not find"

It seems that mmlcr does not look for the data at the right place since 
it did find dataL if we set it a a global variable but it does not find 
it if we define it in a function.

Christophe

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Hmisc latex() does not want to work

2008-01-13 Thread John Kane
I seem to have a problem getting latex (Hmisc) to
work.
Any suggestions as to what I am doing wrong?

Thanks


library(Hmisc)
aa <- data.frame(aa=1:10, bb=rnorm(10, 5, 2),
cc=rnorm(10, 20, 4))
rr <- lm(cc~aa+bb, data=aa); rr
latex(rr)

> latex(rr)
'latex' is not recognized as an internal or external
command,
operable program or batch file.
Warning messages:
1: In cbind(cx, cxk) :
  number of rows of result is not a multiple of vector
length (arg 2)
2: In cbind(cx, cxk) :
  number of rows of result is not a multiple of vector
length (arg 2)
3: In cbind(cx, cxk) :
  number of rows of result is not a multiple of vector
length (arg 2)
4: In cbind(cx, cxk) :
  number of rows of result is not a multiple of vector
length (arg 2)
5: In is.na(xj) :
  is.na() applied to non-(list or vector) of type
'language'
6: In is.na(xj) :
  is.na() applied to non-(list or vector) of type
'language'
7: In cbind(cx, cxk) :
  number of rows of result is not a multiple of vector
length (arg 2)
8: In cbind(cx, cxk) :
  number of rows of result is not a multiple of vector
length (arg 2)
9: In cbind(cx, cxk) :
  number of rows of result is not a multiple of vector
length (arg 2)
10: In shell(cmd, wait = TRUE, intern = output) :
  'cmd' execution failed with error code 1


sessionInfo()
R version 2.6.1 (2007-11-26) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;LC_MONETARY=English_Canada.1252;LC_NUMERIC=C;LC_TIME=English_Canada.1252

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

other attached packages:
[1] gdata_2.3.1 Hmisc_3.4-3

loaded via a namespace (and not attached):
[1] cluster_1.11.9 grid_2.6.1 gtools_2.4.0  
lattice_0.17-2

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


Re: [R] Hmisc latex() does not want to work

2008-01-13 Thread Gabor Grothendieck
Try specifying the file= argument:

latex(rr, file = "")

On Jan 13, 2008 1:05 PM, John Kane <[EMAIL PROTECTED]> wrote:
> I seem to have a problem getting latex (Hmisc) to
> work.
> Any suggestions as to what I am doing wrong?
>
> Thanks
>
>
> library(Hmisc)
> aa <- data.frame(aa=1:10, bb=rnorm(10, 5, 2),
> cc=rnorm(10, 20, 4))
> rr <- lm(cc~aa+bb, data=aa); rr
> latex(rr)
>
> > latex(rr)
> 'latex' is not recognized as an internal or external
> command,
> operable program or batch file.
> Warning messages:
> 1: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of vector
> length (arg 2)
> 2: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of vector
> length (arg 2)
> 3: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of vector
> length (arg 2)
> 4: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of vector
> length (arg 2)
> 5: In is.na(xj) :
>  is.na() applied to non-(list or vector) of type
> 'language'
> 6: In is.na(xj) :
>  is.na() applied to non-(list or vector) of type
> 'language'
> 7: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of vector
> length (arg 2)
> 8: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of vector
> length (arg 2)
> 9: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of vector
> length (arg 2)
> 10: In shell(cmd, wait = TRUE, intern = output) :
>  'cmd' execution failed with error code 1
>
>
> sessionInfo()
> R version 2.6.1 (2007-11-26)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;LC_MONETARY=English_Canada.1252;LC_NUMERIC=C;LC_TIME=English_Canada.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets
> methods   base
>
> other attached packages:
> [1] gdata_2.3.1 Hmisc_3.4-3
>
> loaded via a namespace (and not attached):
> [1] cluster_1.11.9 grid_2.6.1 gtools_2.4.0
> lattice_0.17-2
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] For Loop performance

2008-01-13 Thread My Coyne
Hello,

 

Newbie question and hope you can help .

I have two vector V1 and V2, where length(V2) = length of (V1) * 2;
length(V1) ~ 16,000.

For each member in V1, I need to compare 2 element of V2 for equality

 

i.e. 

for (I in 1:length (V1)) {

 if ( v2[i] == v1[i] & v2[i+1]==v1[i] ){

  statement_1

  statement_2

  .

 }

}

 

This for-loop is too slow (it takes a good 5 minutes on my Windows machine)
to  finish processing the vector V1 of 16,000; I will need to process a lot
more than 16,000  (about 300*16,000).

 

Is there a better way to do looping with R?  Any help is greatly appreciate

 

--MyC.

 

 

 

 

 

 

 


[[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] For Loop performance

2008-01-13 Thread Uwe Ligges


My Coyne wrote:
> Hello,
> 
>  
> 
> Newbie question and hope you can help .
> 
> I have two vector V1 and V2, where length(V2) = length of (V1) * 2;
> length(V1) ~ 16,000.
> 
> For each member in V1, I need to compare 2 element of V2 for equality


If just the comparison is concerned, you can do it in vectorized form, 
but I am not sure of you want to comapre v1[i] with v2[i] and v2[i+1], 
otherwise it would not make sense that  length(V2) = length of (V1) * 2 ...

Say length(V1) is n, do you want to compare

v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4]
or
v1[1] with v2[1] and v2[n+1] and v1[2] with v2[2] and v2[n+2]

???

Uwe Ligges






>  
> 
> i.e. 
> 
> for (I in 1:length (V1)) {
> 
>  if ( v2[i] == v1[i] & v2[i+1]==v1[i] ){
> 
>   statement_1
> 
>   statement_2
> 
>   .
> 
>  }
> 
> }
> 
>  
> 
> This for-loop is too slow (it takes a good 5 minutes on my Windows machine)
> to  finish processing the vector V1 of 16,000; I will need to process a lot
> more than 16,000  (about 300*16,000).
> 
>  
> 
> Is there a better way to do looping with R?  Any help is greatly appreciate
> 
>  
> 
> --MyC.
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 
>   [[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] Hmisc latex() does not want to work

2008-01-13 Thread John Kane
Works just fine, thanks.   I'll blame the help as
being very slightly ambiguous.  

Of course another 2-3 minutes experimenting and I
should have gotten it. 

--- Gabor Grothendieck <[EMAIL PROTECTED]>
wrote:

> Try specifying the file= argument:
> 
> latex(rr, file = "")
> 
> On Jan 13, 2008 1:05 PM, John Kane
> <[EMAIL PROTECTED]> wrote:
> > I seem to have a problem getting latex (Hmisc) to
> > work.
> > Any suggestions as to what I am doing wrong?
> >
> > Thanks
> >
> >
> > library(Hmisc)
> > aa <- data.frame(aa=1:10, bb=rnorm(10, 5, 2),
> > cc=rnorm(10, 20, 4))
> > rr <- lm(cc~aa+bb, data=aa); rr
> > latex(rr)
> >
> > > latex(rr)
> > 'latex' is not recognized as an internal or
> external
> > command,
> > operable program or batch file.
> > Warning messages:
> > 1: In cbind(cx, cxk) :
> >  number of rows of result is not a multiple of
> vector
> > length (arg 2)
> > 2: In cbind(cx, cxk) :
> >  number of rows of result is not a multiple of
> vector
> > length (arg 2)
> > 3: In cbind(cx, cxk) :
> >  number of rows of result is not a multiple of
> vector
> > length (arg 2)
> > 4: In cbind(cx, cxk) :
> >  number of rows of result is not a multiple of
> vector
> > length (arg 2)
> > 5: In is.na(xj) :
> >  is.na() applied to non-(list or vector) of type
> > 'language'
> > 6: In is.na(xj) :
> >  is.na() applied to non-(list or vector) of type
> > 'language'
> > 7: In cbind(cx, cxk) :
> >  number of rows of result is not a multiple of
> vector
> > length (arg 2)
> > 8: In cbind(cx, cxk) :
> >  number of rows of result is not a multiple of
> vector
> > length (arg 2)
> > 9: In cbind(cx, cxk) :
> >  number of rows of result is not a multiple of
> vector
> > length (arg 2)
> > 10: In shell(cmd, wait = TRUE, intern = output) :
> >  'cmd' execution failed with error code 1
> >
> >
> > sessionInfo()
> > R version 2.6.1 (2007-11-26)
> > i386-pc-mingw32
> >
> > locale:
> >
>
LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;LC_MONETARY=English_Canada.1252;LC_NUMERIC=C;LC_TIME=English_Canada.1252
> >
> > attached base packages:
> > [1] stats graphics  grDevices utils
> datasets
> > methods   base
> >
> > other attached packages:
> > [1] gdata_2.3.1 Hmisc_3.4-3
> >
> > loaded via a namespace (and not attached):
> > [1] cluster_1.11.9 grid_2.6.1 gtools_2.4.0
> > lattice_0.17-2
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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] For Loop performance

2008-01-13 Thread mcoyne

WRT:  Say length(V1) is n, do you want to compare
> v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4]
> or
> v1[1] with v2[1] and v2[n+1] and v1[2] with v2[2] and v2[n+2]

v1[1] with (v2[1] and v2[2])
v1[2] with (v2[3] and v2[4])
v1[3] with (v2[5] and v2[6])

...
v1[n] with (v2[n+1] and v2[n+2])

I hope this is clear (I think I was wrong in the snippet of code earlier).
 Thanks in advance.

--MyC

>
>
> My Coyne wrote:
>> Hello,
>>
>>
>>
>> Newbie question and hope you can help .
>>
>> I have two vector V1 and V2, where length(V2) = length of (V1) * 2;
>> length(V1) ~ 16,000.
>>
>> For each member in V1, I need to compare 2 element of V2 for equality
>
>
> If just the comparison is concerned, you can do it in vectorized form,
> but I am not sure of you want to comapre v1[i] with v2[i] and v2[i+1],
> otherwise it would not make sense that  length(V2) = length of (V1) * 2
> ...
>
> Say length(V1) is n, do you want to compare
>
> v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4]
> or
> v1[1] with v2[1] and v2[n+1] and v1[2] with v2[2] and v2[n+2]
>
> ???
>
> Uwe Ligges
>
>
>
>
>
>
>>
>>
>> i.e.
>>
>> for (I in 1:length (V1)) {
>>
>>  if ( v2[i] == v1[i] & v2[i+1]==v1[i] ){
>>
>>   statement_1
>>
>>   statement_2
>>
>>   .
>>
>>  }
>>
>> }
>>
>>
>>
>> This for-loop is too slow (it takes a good 5 minutes on my Windows
>> machine)
>> to  finish processing the vector V1 of 16,000; I will need to process a
>> lot
>> more than 16,000  (about 300*16,000).
>>
>>
>>
>> Is there a better way to do looping with R?  Any help is greatly
>> appreciate
>>
>>
>>
>> --MyC.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>  [[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] For Loop performance

2008-01-13 Thread Uwe Ligges


[EMAIL PROTECTED] wrote:
> WRT:  Say length(V1) is n, do you want to compare
>> v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4]
>> or
>> v1[1] with v2[1] and v2[n+1] and v1[2] with v2[2] and v2[n+2]
> 
> v1[1] with (v2[1] and v2[2])
> v1[2] with (v2[3] and v2[4])
> v1[3] with (v2[5] and v2[6])
> 
> ...
> v1[n] with (v2[n+1] and v2[n+2])


So you end up with all comparisons by:

v2m <- matrix(v2, ncol=2, byrow=TRUE)
logical_result <- (v1 == v2m[,1]) & (v1 == v2m[,2])

Now you can (1) apply vectorized statements (e.g. using ifelse()) OR (if 
1 is impossible) (2):

for (I in which(logical_result)) {
statement_1
statement_2
}


Uwe Ligges


> I hope this is clear (I think I was wrong in the snippet of code earlier).
>  Thanks in advance.
> 
> --MyC
> 
>>
>> My Coyne wrote:
>>> Hello,
>>>
>>>
>>>
>>> Newbie question and hope you can help .
>>>
>>> I have two vector V1 and V2, where length(V2) = length of (V1) * 2;
>>> length(V1) ~ 16,000.
>>>
>>> For each member in V1, I need to compare 2 element of V2 for equality
>>
>> If just the comparison is concerned, you can do it in vectorized form,
>> but I am not sure of you want to comapre v1[i] with v2[i] and v2[i+1],
>> otherwise it would not make sense that  length(V2) = length of (V1) * 2
>> ...
>>
>> Say length(V1) is n, do you want to compare
>>
>> v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4]
>> or
>> v1[1] with v2[1] and v2[n+1] and v1[2] with v2[2] and v2[n+2]
>>
>> ???
>>
>> Uwe Ligges
>>
>>
>>
>>
>>
>>
>>>
>>> i.e.
>>>
>>> for (I in 1:length (V1)) {
>>>
>>>  if ( v2[i] == v1[i] & v2[i+1]==v1[i] ){
>>>
>>>   statement_1
>>>
>>>   statement_2
>>>
>>>   .
>>>
>>>  }
>>>
>>> }
>>>
>>>
>>>
>>> This for-loop is too slow (it takes a good 5 minutes on my Windows
>>> machine)
>>> to  finish processing the vector V1 of 16,000; I will need to process a
>>> lot
>>> more than 16,000  (about 300*16,000).
>>>
>>>
>>>
>>> Is there a better way to do looping with R?  Any help is greatly
>>> appreciate
>>>
>>>
>>>
>>> --MyC.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> [[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] Hmisc latex() does not want to work

2008-01-13 Thread Frank E Harrell Jr
John Kane wrote:
> Works just fine, thanks.   I'll blame the help as
> being very slightly ambiguous.  

 From the help file:

\section{Side Effects}{
creates various system files and runs various Linux/UNIX system
commands which are assumed to be in the system path.
}

\details{
   If running under Windows and using MikTeX, \code{latex} and \code{yap}
   must be in your system path, and \code{yap} is used to browse
   \code{.dvi} files created by \code{latex}.  You should install the
   \code{geometry} and \code{ctable} styles in MikTeX to make optimum use
   of \code{latex()}.

Frank


> 
> Of course another 2-3 minutes experimenting and I
> should have gotten it. 
> 
> --- Gabor Grothendieck <[EMAIL PROTECTED]>
> wrote:
> 
>> Try specifying the file= argument:
>>
>> latex(rr, file = "")
>>
>> On Jan 13, 2008 1:05 PM, John Kane
>> <[EMAIL PROTECTED]> wrote:
>>> I seem to have a problem getting latex (Hmisc) to
>>> work.
>>> Any suggestions as to what I am doing wrong?
>>>
>>> Thanks
>>>
>>>
>>> library(Hmisc)
>>> aa <- data.frame(aa=1:10, bb=rnorm(10, 5, 2),
>>> cc=rnorm(10, 20, 4))
>>> rr <- lm(cc~aa+bb, data=aa); rr
>>> latex(rr)
>>>
 latex(rr)
>>> 'latex' is not recognized as an internal or
>> external
>>> command,
>>> operable program or batch file.
>>> Warning messages:
>>> 1: In cbind(cx, cxk) :
>>>  number of rows of result is not a multiple of
>> vector
>>> length (arg 2)
>>> 2: In cbind(cx, cxk) :
>>>  number of rows of result is not a multiple of
>> vector
>>> length (arg 2)
>>> 3: In cbind(cx, cxk) :
>>>  number of rows of result is not a multiple of
>> vector
>>> length (arg 2)
>>> 4: In cbind(cx, cxk) :
>>>  number of rows of result is not a multiple of
>> vector
>>> length (arg 2)
>>> 5: In is.na(xj) :
>>>  is.na() applied to non-(list or vector) of type
>>> 'language'
>>> 6: In is.na(xj) :
>>>  is.na() applied to non-(list or vector) of type
>>> 'language'
>>> 7: In cbind(cx, cxk) :
>>>  number of rows of result is not a multiple of
>> vector
>>> length (arg 2)
>>> 8: In cbind(cx, cxk) :
>>>  number of rows of result is not a multiple of
>> vector
>>> length (arg 2)
>>> 9: In cbind(cx, cxk) :
>>>  number of rows of result is not a multiple of
>> vector
>>> length (arg 2)
>>> 10: In shell(cmd, wait = TRUE, intern = output) :
>>>  'cmd' execution failed with error code 1
>>>
>>>
>>> sessionInfo()
>>> R version 2.6.1 (2007-11-26)
>>> i386-pc-mingw32
>>>
>>> locale:
>>>
> LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;LC_MONETARY=English_Canada.1252;LC_NUMERIC=C;LC_TIME=English_Canada.1252
>>> attached base packages:
>>> [1] stats graphics  grDevices utils
>> datasets
>>> methods   base
>>>
>>> other attached packages:
>>> [1] gdata_2.3.1 Hmisc_3.4-3
>>>
>>> loaded via a namespace (and not attached):
>>> [1] cluster_1.11.9 grid_2.6.1 gtools_2.4.0
>>> lattice_0.17-2
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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] Hmisc latex() does not want to work

2008-01-13 Thread John Kane
Thank Frank,  

I simply seem to have misread part of the first
example
-- 
x <- matrix(1:6, nrow=2,
dimnames=list(c('a','b'),c('c','d','enLine 2')))
## Not run: 
latex(x)   # creates x.tex in working directory
w <- latex(x, file='/tmp/my.tex')
-
latex(x) gave an error 
latex(x, file="") works fine.


--- Frank E Harrell Jr <[EMAIL PROTECTED]>
wrote:

> John Kane wrote:
> > Works just fine, thanks.   I'll blame the help as
> > being very slightly ambiguous.  
> 
>  From the help file:
> 
> \section{Side Effects}{
> creates various system files and runs various
> Linux/UNIX system
> commands which are assumed to be in the system path.
> }
> 
> \details{
>If running under Windows and using MikTeX,
> \code{latex} and \code{yap}
>must be in your system path, and \code{yap} is
> used to browse
>\code{.dvi} files created by \code{latex}.  You
> should install the
>\code{geometry} and \code{ctable} styles in
> MikTeX to make optimum use
>of \code{latex()}.
> 
> Frank
> 
> 
> > 
> > Of course another 2-3 minutes experimenting and I
> > should have gotten it. 
> > 
> > --- Gabor Grothendieck <[EMAIL PROTECTED]>
> > wrote:
> > 
> >> Try specifying the file= argument:
> >>
> >> latex(rr, file = "")
> >>
> >> On Jan 13, 2008 1:05 PM, John Kane

> >>> I seem to have a problem getting latex (Hmisc)
> to
> >>> work.
> >>> Any suggestions as to what I am doing wrong?
> >>>
> >>> Thanks
> >>>
> >>>
> >>> library(Hmisc)
> >>> aa <- data.frame(aa=1:10, bb=rnorm(10, 5, 2),
> >>> cc=rnorm(10, 20, 4))
> >>> rr <- lm(cc~aa+bb, data=aa); rr
> >>> latex(rr)
> >>>
>  latex(rr)
> >>> 'latex' is not recognized as an internal or
> >> external
> >>> command,
> >>> operable program or batch file.
> >>> Warning messages:
> >>> 1: In cbind(cx, cxk) :
> >>>  number of rows of result is not a multiple of
> >> vector
> >>> length (arg 2)
> >>> 2: In cbind(cx, cxk) :
> >>>  number of rows of result is not a multiple of
> >> vector
> >>> length (arg 2)
> >>> 3: In cbind(cx, cxk) :
> >>>  number of rows of result is not a multiple of
> >> vector
> >>> length (arg 2)
> >>> 4: In cbind(cx, cxk) :
> >>>  number of rows of result is not a multiple of
> >> vector
> >>> length (arg 2)
> >>> 5: In is.na(xj) :
> >>>  is.na() applied to non-(list or vector) of type
> >>> 'language'
> >>> 6: In is.na(xj) :
> >>>  is.na() applied to non-(list or vector) of type
> >>> 'language'
> >>> 7: In cbind(cx, cxk) :
> >>>  number of rows of result is not a multiple of
> >> vector
> >>> length (arg 2)
> >>> 8: In cbind(cx, cxk) :
> >>>  number of rows of result is not a multiple of
> >> vector
> >>> length (arg 2)
> >>> 9: In cbind(cx, cxk) :
> >>>  number of rows of result is not a multiple of
> >> vector
> >>> length (arg 2)
> >>> 10: In shell(cmd, wait = TRUE, intern = output)
> :
> >>>  'cmd' execution failed with error code 1
> >>>
> >>>
> >>> sessionInfo()
> >>> R version 2.6.1 (2007-11-26)
> >>> i386-pc-mingw32
> >>>
> >>> locale:
> >>>
> >
>
LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;LC_MONETARY=English_Canada.1252;LC_NUMERIC=C;LC_TIME=English_Canada.1252
> >>> attached base packages:
> >>> [1] stats graphics  grDevices utils
> >> datasets
> >>> methods   base
> >>>
> >>> other attached packages:
> >>> [1] gdata_2.3.1 Hmisc_3.4-3
> >>>
> >>> loaded via a namespace (and not attached):
> >>> [1] cluster_1.11.9 grid_2.6.1 gtools_2.4.0
> >>> lattice_0.17-2
> >>>
> >>> __
> >>> R-help@r-project.org mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/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] Shapiro-Wilk

2008-01-13 Thread hoehne
What is the formula used in Shapiro-Wilk Statistic?

Thanks

Eduardo (São Paulo/ Brazil)

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


Re: [R] Shapiro-Wilk

2008-01-13 Thread Benilton Carvalho

first hit on google:
http://en.wikipedia.org/wiki/Shapiro-Wilk_test

=)
b

On Jan 13, 2008, at 4:01 PM, [EMAIL PROTECTED] wrote:


What is the formula used in Shapiro-Wilk Statistic?

Thanks

Eduardo (São Paulo/ Brazil)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Hmisc latex() does not want to work

2008-01-13 Thread Frank E Harrell Jr
John Kane wrote:
> Thank Frank,  
> 
> I simply seem to have misread part of the first
> example
> -- 
> x <- matrix(1:6, nrow=2,
> dimnames=list(c('a','b'),c('c','d','enLine 2')))
> ## Not run: 
> latex(x)   # creates x.tex in working directory
> w <- latex(x, file='/tmp/my.tex')
> -
> latex(x) gave an error 
> latex(x, file="") works fine.

Right, and if you install the latex and previewer executables, latex(x) 
will no longer give an error.

Frank

> 
> 
> --- Frank E Harrell Jr <[EMAIL PROTECTED]>
> wrote:
> 
>> John Kane wrote:
>>> Works just fine, thanks.   I'll blame the help as
>>> being very slightly ambiguous.  
>>  From the help file:
>>
>> \section{Side Effects}{
>> creates various system files and runs various
>> Linux/UNIX system
>> commands which are assumed to be in the system path.
>> }
>>
>> \details{
>>If running under Windows and using MikTeX,
>> \code{latex} and \code{yap}
>>must be in your system path, and \code{yap} is
>> used to browse
>>\code{.dvi} files created by \code{latex}.  You
>> should install the
>>\code{geometry} and \code{ctable} styles in
>> MikTeX to make optimum use
>>of \code{latex()}.
>>
>> Frank
>>
>>
>>> Of course another 2-3 minutes experimenting and I
>>> should have gotten it. 
>>>
>>> --- Gabor Grothendieck <[EMAIL PROTECTED]>
>>> wrote:
>>>
 Try specifying the file= argument:

 latex(rr, file = "")

 On Jan 13, 2008 1:05 PM, John Kane
 <[EMAIL PROTECTED]> wrote:
> I seem to have a problem getting latex (Hmisc)
>> to
> work.
> Any suggestions as to what I am doing wrong?
>
> Thanks
>
>
> library(Hmisc)
> aa <- data.frame(aa=1:10, bb=rnorm(10, 5, 2),
> cc=rnorm(10, 20, 4))
> rr <- lm(cc~aa+bb, data=aa); rr
> latex(rr)
>
>> latex(rr)
> 'latex' is not recognized as an internal or
 external
> command,
> operable program or batch file.
> Warning messages:
> 1: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of
 vector
> length (arg 2)
> 2: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of
 vector
> length (arg 2)
> 3: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of
 vector
> length (arg 2)
> 4: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of
 vector
> length (arg 2)
> 5: In is.na(xj) :
>  is.na() applied to non-(list or vector) of type
> 'language'
> 6: In is.na(xj) :
>  is.na() applied to non-(list or vector) of type
> 'language'
> 7: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of
 vector
> length (arg 2)
> 8: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of
 vector
> length (arg 2)
> 9: In cbind(cx, cxk) :
>  number of rows of result is not a multiple of
 vector
> length (arg 2)
> 10: In shell(cmd, wait = TRUE, intern = output)
>> :
>  'cmd' execution failed with error code 1
>
>
> sessionInfo()
> R version 2.6.1 (2007-11-26)
> i386-pc-mingw32
>
> locale:
>
> LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;LC_MONETARY=English_Canada.1252;LC_NUMERIC=C;LC_TIME=English_Canada.1252
> attached base packages:
> [1] stats graphics  grDevices utils
 datasets
> methods   base
>
> other attached packages:
> [1] gdata_2.3.1 Hmisc_3.4-3
>
> loaded via a namespace (and not attached):
> [1] cluster_1.11.9 grid_2.6.1 gtools_2.4.0
> lattice_0.17-2
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
 reproducible code.
> 
> 
> 
>   Ask a question on any topic and get answers from real people. Go to 
> Yahoo! Answers and share what you know at http://ca.answers.yahoo.com
> 


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

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


Re: [R] For Loop performance

2008-01-13 Thread mcoyne
Hi Uwe,

Thank you so much for your help.  It works great with your
suggestion/help.  WOW, what a difference!
--MyC

>
>
> [EMAIL PROTECTED] wrote:
>> WRT:  Say length(V1) is n, do you want to compare
>>> v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4]
>>> or
>>> v1[1] with v2[1] and v2[n+1] and v1[2] with v2[2] and v2[n+2]
>>
>> v1[1] with (v2[1] and v2[2])
>> v1[2] with (v2[3] and v2[4])
>> v1[3] with (v2[5] and v2[6])
>> 
>> ...
>> v1[n] with (v2[n+1] and v2[n+2])
>
>
> So you end up with all comparisons by:
>
> v2m <- matrix(v2, ncol=2, byrow=TRUE)
> logical_result <- (v1 == v2m[,1]) & (v1 == v2m[,2])
>
> Now you can (1) apply vectorized statements (e.g. using ifelse()) OR (if
> 1 is impossible) (2):
>
> for (I in which(logical_result)) {
> statement_1
> statement_2
> }
>
>
> Uwe Ligges
>
>
>> I hope this is clear (I think I was wrong in the snippet of code
>> earlier).
>>  Thanks in advance.
>>
>> --MyC
>>
>>>
>>> My Coyne wrote:
 Hello,



 Newbie question and hope you can help .

 I have two vector V1 and V2, where length(V2) = length of (V1) * 2;
 length(V1) ~ 16,000.

 For each member in V1, I need to compare 2 element of V2 for equality
>>>
>>> If just the comparison is concerned, you can do it in vectorized form,
>>> but I am not sure of you want to comapre v1[i] with v2[i] and v2[i+1],
>>> otherwise it would not make sense that  length(V2) = length of (V1) * 2
>>> ...
>>>
>>> Say length(V1) is n, do you want to compare
>>>
>>> v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4]
>>> or
>>> v1[1] with v2[1] and v2[n+1] and v1[2] with v2[2] and v2[n+2]
>>>
>>> ???
>>>
>>> Uwe Ligges
>>>
>>>
>>>
>>>
>>>
>>>

 i.e.

 for (I in 1:length (V1)) {

  if ( v2[i] == v1[i] & v2[i+1]==v1[i] ){

   statement_1

   statement_2

   .

  }

 }



 This for-loop is too slow (it takes a good 5 minutes on my Windows
 machine)
 to  finish processing the vector V1 of 16,000; I will need to process
 a
 lot
 more than 16,000  (about 300*16,000).



 Is there a better way to do looping with R?  Any help is greatly
 appreciate



 --MyC.
















[[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] Lattice equivalent of par(mfrow = )

2008-01-13 Thread Deepayan Sarkar
On 1/13/08, Michael Kubovy <[EMAIL PROTECTED]> wrote:
> Dear R-helpers,
>
> On Jan 12, 2008, at 5:17 PM, Deepayan Sarkar wrote:
>
> > On 1/12/08, Michael Kubovy <[EMAIL PROTECTED]> wrote:
> >> Dear r-helpers,
> >>
> >> Does anyone have a straightforward example of putting together three
> >> unrelated (expect for a common y-axis) xyplot() figures in what would
> >> be in base graphics a par(mfrow = c(1, 3)) arrangement?
> >
> > See the examples in ?print.trellis.
>
> Thanks. Now how do I insure that the three y-axes are the same scale
> in the following?

There might be a better approach than this; could you post an example
that more closely resembles your real problem?

-Deepayan

>
> states <- data.frame(state.x77,
>   state.name = dimnames(state.x77)[[1]],
>   state.region = state.region)
> plot1 <- xyplot(Murder ~ Population, data = states,
> xlab = grid::textGrob(expression(frac(abs(bold(c)), abs(bold(b,
> gp=gpar(fontsize=25)),
> ylab = grid::textGrob(expression(paste(log, frac(italic(p)
> (italic(c)), italic(p)(italic(b), gp = gpar(fontsize = 25)),
> )
> plot2 <- xyplot(Murder ~ Population, data = states,
> xlab = grid::textGrob(expression(gamma), gp = gpar(fontsize= 25)),
> ylab = '',
> )
> plot3 <- xyplot(Murder ~ Population, data = states,
> xlab =
> grid::textGrob(expression(frac(abs( bold(c) ),abs( bold(b) ))), gp =
> gpar(fontsize = 25)),
> ylab = '',
> )
> print(plot1, position = c(0.0, 0, 0.33, 1), more = TRUE)
> print(plot2, position = c(0.33, 0, 0.67, 1), more = TRUE)
> print(plot3, position = c(0.67, 0, 1, 1))
>
> _
> Professor Michael Kubovy
> University of Virginia
> Department of Psychology
> USPS: P.O.Box 400400Charlottesville, VA 22904-4400
> Parcels:Room 102Gilmer Hall
>  McCormick RoadCharlottesville, VA 22903
> Office:B011+1-434-982-4729
> Lab:B019+1-434-982-4751
> Fax:+1-434-982-4766
> WWW:http://www.people.virginia.edu/~mk9y/
>
>
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Nasser Abbasi
hi;

When I first started looking at R code, I thought that the <- notation for 
assignment made the code less readable (and I still do).  Then I found that 
now one can use "=" in place of "<-" for assignment (I understand this 
started since version 1.4). Anyway, I think using "=" makes the code much 
more readable.

I was wondering, would it be safe if I replace all the occurrences of "<-" 
by "=" in any function of R? Or do you think this will break things?

I like to look at a pretty code, and I just can't stand looking at those 
"<-" any more :)

I am using latest version of R on windoz platform.

thanks
Nasser

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


Re: [R] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Gabor Grothendieck
No.

> f <- function(a = 3, b = 4) a-b
> f(b = 10)
[1] -7
> f(b <- 10)
[1] 6

but if you only replace it in the context:

x <- ...

then it should be ok.

On Jan 13, 2008 5:41 PM, Nasser Abbasi <[EMAIL PROTECTED]> wrote:
> hi;
>
> When I first started looking at R code, I thought that the <- notation for
> assignment made the code less readable (and I still do).  Then I found that
> now one can use "=" in place of "<-" for assignment (I understand this
> started since version 1.4). Anyway, I think using "=" makes the code much
> more readable.
>
> I was wondering, would it be safe if I replace all the occurrences of "<-"
> by "=" in any function of R? Or do you think this will break things?
>
> I like to look at a pretty code, and I just can't stand looking at those
> "<-" any more :)
>
> I am using latest version of R on windoz platform.
>
> thanks
> Nasser
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] Trying to write Merge for more data.frames - Error in match.names(clabs, names(xi))

2008-01-13 Thread Jiří Voller
Dear list members,
I would like to merge multiple dataframes and seems that this task is going
to be required quite often, so I decided to write a simple (pseudo)recursive
merge.
I started with the case when dataframes are merged by rows (0). But there is
a problem when a dataframe to be merged in the step n has some items that
are not in previous ones. Then I get "Error in match.names(clabs, names(xi))
:   names do not match previous names".
Please help. Thank you Jiri Voller

MergeByRownames<-function(x,a,all.x=T,all.y=T){
stopifnot(is.list(x))

x<-lapply(x,as.data.frame,row.names = NULL)
 ## if (any(unlist(lapply(x,
function(x){is.null(rownames(x))}{stop("Missing
names.")}
   # doesnt work x<-lapply(x,as.data.frame,row.names = NULL)
assignes names (1:n)

for (i in 1:length(x)){
if(i==1){
merged<-x[[i]]
}else{
if(i==2){
 merged<-merge(merged,x[[i]],by.x=0,by.y=0,all.x=all.x,
all.y=all.y,sort=F)
} else {
 merged<-merge(merged,x[[i]],by.x="Row.names",by.y=0,
all.x=all.x,all.y=all.y,sort=F)
  }
 }
}
return(merged)
}

MergeByRownames(test) gives "Error in match.names(clabs, names(xi)) :
names do not match previous names".
Interestingly MergeByRownames.rec(list(test$A,test$A,test$A,test$X)) gives
the same error, while MergeByRownames.rec(list(test$A,test$A,test$X)) works
fine. I cannot see anything fishy on the data frame that is used to merge
with final test$X.

test<-structure(list(A = structure(c("a", "b", "c", "d", "e", "f",
"g", "h", "i", "j"), .Names = c("A", "B", "C", "D", "E", "F",
"G", "H", "I", "J")), B = structure(c("a", "b", "c", "d", "e"
), .Names = c("A", "B", "C", "D", "E")), C = structure(c("e",
"f", "g", "h", "i", "j"), .Names = c("E", "F", "G", "H", "I",
"J")), D = structure(c("b", "c", "d", "e", "f"), .Names = c("B",
"C", "D", "E", "F")), X = structure(c("a", "b", "c", "d", "e",
"f", "g", "h", "i", "j", "k", "l", "m"), .Names = c("A", "B",
"C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"))), .Names = c("A",
"B", "C", "D", "X"))

[[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] Trying to write Merge for more data.frames - Error in match.names(clabs, names(xi))

2008-01-13 Thread Gabor Grothendieck
Note that the zoo package has a multiway merge for zoo class time
series:

> library(zoo)
as.matrix(do.call(merge, lapply(test, function(x) zoo(unname(x), names(x)
  A   B   C   D   X
A "a" "a" NA  NA  "a"
B "b" "b" NA  "b" "b"
C "c" "c" NA  "c" "c"
D "d" "d" NA  "d" "d"
E "e" "e" "e" "e" "e"
F "f" NA  "f" "f" "f"
G "g" NA  "g" NA  "g"
H "h" NA  "h" NA  "h"
I "i" NA  "i" NA  "i"
J "j" NA  "j" NA  "j"
K NA  NA  NA  NA  "k"
L NA  NA  NA  NA  "l"
M NA  NA  NA  NA  "m"


On Jan 13, 2008 6:47 PM, Jiří Voller <[EMAIL PROTECTED]> wrote:
> Dear list members,
> I would like to merge multiple dataframes and seems that this task is going
> to be required quite often, so I decided to write a simple (pseudo)recursive
> merge.
> I started with the case when dataframes are merged by rows (0). But there is
> a problem when a dataframe to be merged in the step n has some items that
> are not in previous ones. Then I get "Error in match.names(clabs, names(xi))
> :   names do not match previous names".
> Please help. Thank you Jiri Voller
>
> MergeByRownames<-function(x,a,all.x=T,all.y=T){
>stopifnot(is.list(x))
>
>x<-lapply(x,as.data.frame,row.names = NULL)
> ## if (any(unlist(lapply(x,
> function(x){is.null(rownames(x))}{stop("Missing
> names.")}
>   # doesnt work x<-lapply(x,as.data.frame,row.names = NULL)
> assignes names (1:n)
>
>for (i in 1:length(x)){
>if(i==1){
>merged<-x[[i]]
>}else{
>if(i==2){
> merged<-merge(merged,x[[i]],by.x=0,by.y=0,all.x=all.x,
> all.y=all.y,sort=F)
>} else {
> merged<-merge(merged,x[[i]],by.x="Row.names",by.y=0,
> all.x=all.x,all.y=all.y,sort=F)
>  }
> }
>}
> return(merged)
> }
>
> MergeByRownames(test) gives "Error in match.names(clabs, names(xi)) :
> names do not match previous names".
> Interestingly MergeByRownames.rec(list(test$A,test$A,test$A,test$X)) gives
> the same error, while MergeByRownames.rec(list(test$A,test$A,test$X)) works
> fine. I cannot see anything fishy on the data frame that is used to merge
> with final test$X.
>
> test<-structure(list(A = structure(c("a", "b", "c", "d", "e", "f",
> "g", "h", "i", "j"), .Names = c("A", "B", "C", "D", "E", "F",
> "G", "H", "I", "J")), B = structure(c("a", "b", "c", "d", "e"
> ), .Names = c("A", "B", "C", "D", "E")), C = structure(c("e",
> "f", "g", "h", "i", "j"), .Names = c("E", "F", "G", "H", "I",
> "J")), D = structure(c("b", "c", "d", "e", "f"), .Names = c("B",
> "C", "D", "E", "F")), X = structure(c("a", "b", "c", "d", "e",
> "f", "g", "h", "i", "j", "k", "l", "m"), .Names = c("A", "B",
> "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"))), .Names = c("A",
> "B", "C", "D", "X"))
>
>[[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] Hmisc latex() does not want to work

2008-01-13 Thread Richard M. Heiberger


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of John Kane
Sent: Sunday, January 13, 2008 03:56 PM

## Not run: 
latex(x)   # creates x.tex in working directory
w <- latex(x, file='/tmp/my.tex')
-

I think there is an unclarity in the documentation.  The documentation
is correct and everything that Frank and Gabor wrote
is also correct.  The issue is side-effects, which I think need a bit more
explanation.  I would revise the first example above to read:


latex(x)   ## 1. creates x.tex in working directory and 
   ##
   ## 2. The result of the command is an object of class "latex"
   ##which is automatically printed by the latex print method.
   ##The latex print method prepends and appends latex headers
and
   ##calls the latex program in the PATH.  If the latex program
is
   ##not in the PATH, you will get error messages from the
operating
   ##system.

Since you didn't have latex in the PATH, you got an error from the print
method.  The x.tex file was probably correctly generated and might still be
sitting
in your default getwd() directory.

The second example,
w <- latex(x, file='/tmp/my.tex')
doesn't give an error message because the result of the latex() command is
saved in the object w and not automatically printed.


Rich

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


Re: [R] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Richard M. Heiberger
Most R users believe that there is a clear distinction between " <- " and
"=".
Gabor's example is a wonderful illustration of that distinction.
Most users recommend " <- " for assignment for greater clarity and
readability.
The important characteristic for readability is the space on both sides of
the
assignment arrow.  Without spacing for human legibility anything will look
bad.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Gabor Grothendieck
Sent: Sunday, January 13, 2008 05:50 PM
To: Nasser Abbasi
Cc: [EMAIL PROTECTED]
Subject: Re: [R] is it safe to replace every "<-" by "=" in R code?

No.

> f <- function(a = 3, b = 4) a-b
> f(b = 10)
[1] -7
> f(b <- 10)
[1] 6

but if you only replace it in the context:

x <- ...

then it should be ok.

On Jan 13, 2008 5:41 PM, Nasser Abbasi <[EMAIL PROTECTED]> wrote:
> hi;
>
> When I first started looking at R code, I thought that the <- notation for
> assignment made the code less readable (and I still do).  Then I found
that
> now one can use "=" in place of "<-" for assignment (I understand this
> started since version 1.4). Anyway, I think using "=" makes the code much
> more readable.
>
> I was wondering, would it be safe if I replace all the occurrences of "<-"
> by "=" in any function of R? Or do you think this will break things?
>
> I like to look at a pretty code, and I just can't stand looking at those
> "<-" any more :)
>
> I am using latest version of R on windoz platform.
>
> thanks
> Nasser
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

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


Re: [R] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Jonathan Baron
I think it is worth pointing out that, if you use ESS with (X)emacs,
" <- " (with spaces) is produced when you type "_".  It requires only two
keystrokes (shift and -), and the spaces are done for you. The = sign
requires three because you need to type the spaces on each side.

Jon

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

2008-01-13 Thread Day, Roger S.
Running Version 2.6.0  GUI 1.21.
Generally, I enjoy working with the OSX GUI,
which has some very pleasant features.
Kudos to the developers!
 
There is a nice history panel which slides out of the
Console window.  The buttons on the panel work as expected.
I am puzzled by the behavior of history() and savehistory()
run from the Console window.  I would think that these functions
would view and save the same set of commands as those seen in
the history panel, but they don't.
Can someone explain why, and how to fix it?
 
Perhaps relevant:   I generally have performed a setwd() , or started R
by launching
a "Rdata" file.
 
Thanks.
 
Roger Day 
University of Pittsburgh Departments of Biomedical Informatics and
Biostatistics 
University of Pittsburgh Cancer Institute 
University of Pittsburgh Molecular Medicine Institute
** 
Room 310, Suite 301 
Cancer Pavilion (CNPAV)
5150 Centre Ave. 
Pittsburgh, PA 15232 
e-mail:  [EMAIL PROTECTED] 
cell phone 412-609-3918
assistant:
Lucy Cafeo:   (412) 623-2952
*** 
 

 
 

[[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] Hmisc latex() does not want to work

2008-01-13 Thread Frank E Harrell Jr
Richard M. Heiberger wrote:
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of John Kane
> Sent: Sunday, January 13, 2008 03:56 PM
> 
> ## Not run: 
> latex(x)   # creates x.tex in working directory
> w <- latex(x, file='/tmp/my.tex')
> -
> 
> I think there is an unclarity in the documentation.  The documentation
> is correct and everything that Frank and Gabor wrote
> is also correct.  The issue is side-effects, which I think need a bit more
> explanation.  I would revise the first example above to read:
> 
> 
> latex(x)   ## 1. creates x.tex in working directory and 
>##
>## 2. The result of the command is an object of class "latex"
>##which is automatically printed by the latex print method.
>##The latex print method prepends and appends latex headers
> and
>##calls the latex program in the PATH.  If the latex program
> is
>##not in the PATH, you will get error messages from the
> operating
>##system.
> 
> Since you didn't have latex in the PATH, you got an error from the print
> method.  The x.tex file was probably correctly generated and might still be
> sitting
> in your default getwd() directory.
> 
> The second example,
> w <- latex(x, file='/tmp/my.tex')
> doesn't give an error message because the result of the latex() command is
> saved in the object w and not automatically printed.
> 
> 
> Rich

Good - added that in the examples section for the next release of Hmisc.
Thanks Rich
Frank

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 way to interrupt a stuck R session on OSX

2008-01-13 Thread Day, Roger S.
Discovered by accident:
 
If your R session has become unresponsive to escape presses etcetera,
you can try this.
Open a terminal window, run the command
 
ps -ax | grep R.app
 
Note the process ID number in the first column.  Say it's 1234.
Then run
 
kill -4 1234
 
The key is that the signal you are sending to R.app is "4". 
 
The Console will now ask you how you want to exit.
This at a minimum gives you a chance to save any window content,
since it's a nicely threaded application.
Once (of 2 times) I could also cancel out of the dialog and resume the
session.
 
Roger Day 
University of Pittsburgh Departments of Biomedical Informatics and
Biostatistics 
University of Pittsburgh Cancer Institute 
University of Pittsburgh Molecular Medicine Institute
** 
Room 310, Suite 301 
Cancer Pavilion (CNPAV)
5150 Centre Ave. 
Pittsburgh, PA 15232 
e-mail:  [EMAIL PROTECTED] 
cell phone 412-609-3918
assistant:
Lucy Cafeo:   (412) 623-2952
*** 
 

 
 

[[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] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread S Ellison
.. and don't forget that 6 -> x works but 6 = x won't ...

>>> "Gabor Grothendieck" <[EMAIL PROTECTED]> 01/13/08 10:50 PM >>>
No.

> f <- function(a = 3, b = 4) a-b
> f(b = 10)
[1] -7
> f(b <- 10)
[1] 6

but if you only replace it in the context:

x <- ...

then it should be ok.

On Jan 13, 2008 5:41 PM, Nasser Abbasi <[EMAIL PROTECTED]> wrote:
> hi;
>
> When I first started looking at R code, I thought that the <- notation
for
> assignment made the code less readable (and I still do).  Then I found
that
> now one can use "=" in place of "<-" for assignment (I understand this
> started since version 1.4). Anyway, I think using "=" makes the code
much
> more readable.
>
> I was wondering, would it be safe if I replace all the occurrences of
"<-"
> by "=" in any function of R? Or do you think this will break things?
>
> I like to look at a pretty code, and I just can't stand looking at
those
> "<-" any more :)
>
> I am using latest version of R on windoz platform.
>
> thanks
> Nasser
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

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


Re: [R] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Charilaos Skiadas
And of course let's not forget that a particularly twisted individual  
could overwrite "=":

 > `=` <- function(x,y) print(x+y)
 > 3 = 4
[1] 7
 > 3 <- 4
Error in 3 <- 4 : invalid (do_set) left-hand side to assignment


I also was for a while mystified by the <- assignment, and preferred  
= instead, but have since grown out of it, and now find <- more clear  
(especially since it makes the separation between function arguments  
and assignments clear).

I now have a problem whenever I switch to another programming  
language 

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Jan 13, 2008, at 10:25 PM, S Ellison wrote:

> .. and don't forget that 6 -> x works but 6 = x won't ...
>
 "Gabor Grothendieck" <[EMAIL PROTECTED]> 01/13/08 10:50 PM  
 >>>
> No.
>
>> f <- function(a = 3, b = 4) a-b
>> f(b = 10)
> [1] -7
>> f(b <- 10)
> [1] 6
>
> but if you only replace it in the context:
>
> x <- ...
>
> then it should be ok.
>
> On Jan 13, 2008 5:41 PM, Nasser Abbasi <[EMAIL PROTECTED]> wrote:
>> hi;
>>
>> When I first started looking at R code, I thought that the <-  
>> notation
> for
>> assignment made the code less readable (and I still do).  Then I  
>> found
> that
>> now one can use "=" in place of "<-" for assignment (I understand  
>> this
>> started since version 1.4). Anyway, I think using "=" makes the code
> much
>> more readable.
>>
>> I was wondering, would it be safe if I replace all the occurrences of
> "<-"
>> by "=" in any function of R? Or do you think this will break things?
>>
>> I like to look at a pretty code, and I just can't stand looking at
> those
>> "<-" any more :)
>>
>> I am using latest version of R on windoz platform.
>>
>> thanks
>> Nasser
>>

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

2008-01-13 Thread Gad Abraham
Hi,

In 2.6.0 arima() used to return an object with attribute `x' which is 
the observed time series, but this has been dropped from 2.6.1.

This breaks the forecast function in package forecast.

There's no mention of it in the changelog for 2.6.1.

Is this a bug or a feature?

Thanks,
Gad

-- 
Gad Abraham
Department of Mathematics and Statistics
The University of Melbourne
Parkville 3010, Victoria, Australia
email: [EMAIL PROTECTED]
web: http://www.ms.unimelb.edu.au/~gabraham

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Re: [R] arima changes from 2.6.0

2008-01-13 Thread Duncan Murdoch
Gad Abraham wrote:
> Hi,
>
> In 2.6.0 arima() used to return an object with attribute `x' which is 
> the observed time series, but this has been dropped from 2.6.1.
>
> This breaks the forecast function in package forecast.
>
> There's no mention of it in the changelog for 2.6.1.
>
> Is this a bug or a feature?
I don't see it there.  Can you show the code you were using to get it?

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] arima changes from 2.6.0

2008-01-13 Thread Gad Abraham
Duncan Murdoch wrote:
> Gad Abraham wrote:
>> Hi,
>>
>> In 2.6.0 arima() used to return an object with attribute `x' which is 
>> the observed time series, but this has been dropped from 2.6.1.
>>
>> This breaks the forecast function in package forecast.
>>
>> There's no mention of it in the changelog for 2.6.1.
>>
>> Is this a bug or a feature?
> I don't see it there.  Can you show the code you were using to get it?
> 

Sorry, my mistake:

The 2.6.0 version was using a previous version of the forecast package 
that has its own arima() function, masking the one from stats. The 
forecast::arima version has `x', but stats::arima doesn't, hence the 
confusion. This has been changed in the new version of forecast.

Thanks,
Gad

-- 
Gad Abraham
Department of Mathematics and Statistics
The University of Melbourne
Parkville 3010, Victoria, Australia
email: [EMAIL PROTECTED]
web: http://www.ms.unimelb.edu.au/~gabraham

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 way to interrupt a stuck R session on OSX

2008-01-13 Thread Josh Tolley
On Jan 13, 2008 8:02 PM, Day, Roger S. <[EMAIL PROTECTED]> wrote:
> Discovered by accident:
>
> If your R session has become unresponsive to escape presses etcetera,
> you can try this.
> Open a terminal window, run the command
>
> ps -ax | grep R.app
>
> Note the process ID number in the first column.  Say it's 1234.
> Then run
>
> kill -4 1234
>
> The key is that the signal you are sending to R.app is "4".
>
> The Console will now ask you how you want to exit.
> This at a minimum gives you a chance to save any window content,
> since it's a nicely threaded application.
> Once (of 2 times) I could also cancel out of the dialog and resume the
> session.

What signal is signal 4 on your OS (or more specifically, what signal
is it that R responds to in this manner)? If I understand correctly,
different OS's supporting kill(1) vary in the interpretation of
numerically specified signals, though I can only report this as
hearsay, and not provide specific examples. Nevertheless, folks in my
little circle tend to use kill -SIGTERM, kill -SIGQUIT, etc. rather
than numeric signal specifiers just in case kill(1) behaves
differently than they expect.

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


[R] Critical values of r

2008-01-13 Thread Sanglamt

I've spent several hours trying to track the answer down myself and failed
miserably so a simple question for everyone that will no doubt have a
painfully obvious answer.

What's the command to calculate the critical value of r using a two tailed
test with a given alpha and degrees of freedom? I.e., alpha=0.05, df=18,
two-tailed test, with the result being 0.4438
-- 
View this message in context: 
http://www.nabble.com/Critical-values-of-r-tp14795700p14795700.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] a way to interrupt a stuck R session on OSX

2008-01-13 Thread Prof Brian Ripley
On Sun, 13 Jan 2008, Josh Tolley wrote:

> On Jan 13, 2008 8:02 PM, Day, Roger S. <[EMAIL PROTECTED]> wrote:
>> Discovered by accident:
>>
>> If your R session has become unresponsive to escape presses etcetera,
>> you can try this.
>> Open a terminal window, run the command
>>
>> ps -ax | grep R.app
>>
>> Note the process ID number in the first column.  Say it's 1234.
>> Then run
>>
>> kill -4 1234
>>
>> The key is that the signal you are sending to R.app is "4".
>>
>> The Console will now ask you how you want to exit.
>> This at a minimum gives you a chance to save any window content,
>> since it's a nicely threaded application.
>> Once (of 2 times) I could also cancel out of the dialog and resume the
>> session.
>
> What signal is signal 4 on your OS (or more specifically, what signal
> is it that R responds to in this manner)? If I understand correctly,
> different OS's supporting kill(1) vary in the interpretation of
> numerically specified signals, though I can only report this as
> hearsay, and not provide specific examples. Nevertheless, folks in my
> little circle tend to use kill -SIGTERM, kill -SIGQUIT, etc. rather
> than numeric signal specifiers just in case kill(1) behaves
> differently than they expect.

Agreed (but some signal numbers are pretty much standard, e.g. 1,2,3). 
Signal 4 is SIGILL on MacOS X, and I believe the R signal handler (not due 
to R.app's authors) is responsible: the behaviour quoted holds for any 
Unix-alike R.

If you want to save the work and terminate on any Unix-alike, send SIGUSR1 
or SIGUSR2.  See ?Signals.  SIGUSR1 can be 30, 10 or 16 even on Linux, 
depending on the architecture.

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

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


Re: [R] Critical values of r

2008-01-13 Thread C.H.
Not particularly R related, but r related.

For pearson correlation, the test statistics is based on t distribution.

ts = r * sqrt ((n-2)/(1-r^2))
with n-2 degree of freedom.

I think you can solve this question, maybe a little bit of googling.



On Jan 14, 2008 1:39 PM, Sanglamt <[EMAIL PROTECTED]> wrote:
>
> I've spent several hours trying to track the answer down myself and failed
> miserably so a simple question for everyone that will no doubt have a
> painfully obvious answer.
>
> What's the command to calculate the critical value of r using a two tailed
> test with a given alpha and degrees of freedom? I.e., alpha=0.05, df=18,
> two-tailed test, with the result being 0.4438
> --
> View this message in context: 
> http://www.nabble.com/Critical-values-of-r-tp14795700p14795700.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.
>



-- 
CH Chan
Research Assistant - KWH
http://www.macgrass.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] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Mark Wardle
On 13/01/2008, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> No.
>
> > f <- function(a = 3, b = 4) a-b
> > f(b = 10)
> [1] -7
> > f(b <- 10)
> [1] 6
>

I had to go and read (and re-read) the R manual on lexical scope to
try and understand this since this example highlights a previously
neglected "chasm" in my knowledge base!

Why does that give the result it does?

I can see that
f(b <- 10) is equivalent to   f(assign("b"), 10))

I can't work out whether that is interpreted within the parent
environment or the function's own environment at the time of call. Why
does R give the answer it does? This can't be a scope issue?  I would
have expected either -1 or -7!

Am I being completely dim?

-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

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

2008-01-13 Thread Geoff Russell
Dear useRs,

The following plots only print 2 of the 4 labels under the bars, is there
a way please to force all 4 labels to print?

par(mfrow=c(1,2),mar=c(2,7,3,1))
dat<-data.frame("AgeGroup"=c("2-15","16-20","21-25","26-39"),
"Aorta"=c(20,8,30,60),
"Coronary"=c(7,30,55,65))
barplot(dat$Aorta,ylim=c(0,100),names=as.vector(dat$AgeGroup),ylab=c("Prevalence
(%)"))
title(main=list("Aorta",font=0))
barplot(dat$Coro,names=as.vector(dat$Age),ylim=c(0,100))
title(main=list("Coronary Artery",font=0))


Many thanks,
Geoff Russell

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


Re: [R] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Peter Danenberg
Quoth Mark Wardle on Prickle-Prickle, Chaos 14, 3174:
> I can see that f(b <- 10) is equivalent to f(assign("b"), 10))

f(assign("b", 10))?

My undestanding is that assign applies to the parental environment;
but the return value of assign, namely 10, is passed to f as the local
variable a.

The default value b = 4 then overrides the parental environment since
it is unspecified in the call to f.

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


Re: [R] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Mark Wardle
On 14/01/2008, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> Its not related to scoping. f(b = 10) passes 10 as argument b
> but f(b <- 10) assigns to variable b (which has nothing to do with
> argument b) and then passes the result of the b<-10 expression (which is
> 10) to f.  Since no argument was specified it uses positional
> matching and the first position is argument a.  Thus its the same
> as f(10).  Note that f(b<-10) isthe same as f( (b <- 10) ) which may
> make it clearer.

Of course! Straightforward!

Many thanks,

Mark

-- 
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK

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


Re: [R] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Prof Brian Ripley
On Mon, 14 Jan 2008, Mark Wardle wrote:

> On 13/01/2008, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
>> No.
>>
>>> f <- function(a = 3, b = 4) a-b
>>> f(b = 10)
>> [1] -7
>>> f(b <- 10)
>> [1] 6
>>
>
> I had to go and read (and re-read) the R manual on lexical scope to

lexical scope does not come into this; S behaves the same way.

> try and understand this since this example highlights a previously
> neglected "chasm" in my knowledge base!
>
> Why does that give the result it does?
>
> I can see that
> f(b <- 10) is equivalent to   f(assign("b"), 10))

Actually, to f(assign("b", 10)), and this matches the first argument, so 
that call is like (but see below)

assign("b", 10); f(b)

> I can't work out whether that is interpreted within the parent
> environment or the function's own environment at the time of call. Why
> does R give the answer it does? This can't be a scope issue?  I would
> have expected either -1 or -7!
>
> Am I being completely dim?

Probably you don't know the rules:

Actual function arguments are evaluated in the calling (one sense of 
'parent', e.g. sys.parent) environments, *if* they are evaluated at all. 
(It is the latter than makes this sort of construction inadvisable.) 
However, default arguments are evaluated in the evaluation frame of the 
function (that is, as if they appeared in the body of the function).

So

> f <- function(a, b) NULL
> f(b <- 10)
NULL
> b
Error: object "b" not found

is correct, but most people don't know that.  Since the behaviour depends 
on f() which can be changed at a later date, I suggest that this 
construction should be avoided.


As for " <- " vs " = ": observation suggests that you will annoy fewest 
people if you use " <- ", *with the surrounding spaces*.  People who find 
" <- " annoying need to get over this, as that is what is used throughout 
the R code base and in the vast majority of packages -- and reading R code 
to understand the methods you use is an important skill.

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

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


Re: [R] is it safe to replace every "<-" by "=" in R code?

2008-01-13 Thread Gabor Grothendieck
Its not related to scoping. f(b = 10) passes 10 as argument b
but f(b <- 10) assigns to variable b (which has nothing to do with
argument b) and then passes the result of the b<-10 expression (which is
10) to f.  Since no argument was specified it uses positional
matching and the first position is argument a.  Thus its the same
as f(10).  Note that f(b<-10) isthe same as f( (b <- 10) ) which may
make it clearer.

On Jan 14, 2008 2:12 AM, Mark Wardle <[EMAIL PROTECTED]> wrote:
> On 13/01/2008, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> > No.
> >
> > > f <- function(a = 3, b = 4) a-b
> > > f(b = 10)
> > [1] -7
> > > f(b <- 10)
> > [1] 6
> >
>
> I had to go and read (and re-read) the R manual on lexical scope to
> try and understand this since this example highlights a previously
> neglected "chasm" in my knowledge base!
>
> Why does that give the result it does?
>
> I can see that
> f(b <- 10) is equivalent to   f(assign("b"), 10))
>
> I can't work out whether that is interpreted within the parent
> environment or the function's own environment at the time of call. Why
> does R give the answer it does? This can't be a scope issue?  I would
> have expected either -1 or -7!
>
> Am I being completely dim?
>
> --
> Dr. Mark Wardle
> Specialist registrar, Neurology
> Cardiff, UK
>

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

2008-01-13 Thread Daniel Stepputtis
Dear list,

I am using R 2.6 on a Windows XP machine.

I divided my device window and tried to set the backgroundcolor for each plot 
region/figure region separately. This seems not possible?? A simple example:

# create random numbers
a <- rnorm(100)
# divide device window
par(mfrow=c(1,2))
# set the backgroundcolour to "red"
# this always affect the total device
par(bg="red")
#two plots should be plotted
plot(a)
hist(a)


I have tried to call "bg" within the high-level-graphic function 
(plot(bg="red")). Whereas there was no error-message, this has no effect on the 
background of this singe plot.

I found a meaningfull answer I have found here:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/21384.html
but I was wondering, whether there is a more easy and explicit way to do it 
directly for a given plot in a multiplot environment.
Are there possibilities to do it specifically for the complete figure region or 
solely for the complete plot region?

Thank you for your help
Daniel

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