Re: [R] Problem with svyvar in survey package

2011-11-03 Thread amitava
Thank you Sir.Now it is giving results correctly.

--Amitava

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-svyvar-in-survey-package-tp3932818p3984390.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Help in ranef Function

2011-11-03 Thread arunkumar1111
Hi 

I'm getting the intercepts of  the Random effects as 0. Please help me to
understand why this is coming Zero

This is my R code

Data- read.csv(C:/FE and RE.csv)
Formula=Y~X2+X3+X4 + (1|State) + (0+X5|State)
fit=lmer(formula=Formula,data=Data)
ranef(fit).

My sample Data

State   YearY   X2  X3  X4  X5  X6
S2  196027.8397.5   42.250.778.365.8
S1  196029.9413.3   38.152  79.266.9
S2  196129.8439.2   40.354  79.267.8
S1  196130.8459.7   39.555.379.269.6
S2  196231.2492.9   37.354.777.468.7
S1  196233.3528.6   38.163.780.273.6
S2  196335.6560.3   39.369.880.476.3
S1  196336.4624.6   37.865.983.977.2
S2  196436.7666.4   38.464.585.578.1
S1  196438.4717.8   40.170  93.784.7
S2  196540.4768.2   38.673.2106.1   93.3
S1  196540.3843.3   39.867.8104.8   89.7
S2  196641.8911.6   39.779.1114 100.7
S1  196640.4931.1   52.195.4124.1   113.5
S2  196740.71021.5  48.994.2127.6   115.3
S1  196740.11165.9  58.3123.5   142.9   136.7
S2  196842.71349.6  57.9129.9   143.6   139.2
S1  196844.11449.4  56.5117.6   139.2   132
S2  196946.71575.5  63.7130.9   165.5   132.1
S1  196950.61759.1  61.6129.8   203.3   154.4
S2  197050.11994.2  58.9128 219.6   174.9
S1  197051.72258.1  66.4141 221.6   180.8
S2  197152.92478.7  70.4168.2   232.6   189.4




--
View this message in context: 
http://r.789695.n4.nabble.com/Help-in-ranef-Function-tp3984436p3984436.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] problem with merging two matrices

2011-11-03 Thread flokke
Dear all, 
I hope you can forgive me my stupid questions, but I am a very new R user (;

So, this is my question:

I have two matrices, 
those are:

matrix1 - matrix(cbind(vector1, vector2), 1,2, dimnames = list(c(values), 
   c(T value,
p value)))

matrix2 - matrix(dcbind,2,6,dimnames = list(c(x, y),
  c(Min, 1st qu., Median, Mean, 3rd
qu., Max)))

Now, I would like to merge them, but I want to receive the following result:

 Min 1st qu. Median Mean 3rd qu. Max
  x   3  34  44  4
  y   3   3   3  3 3 3 

   t value p value
value   3   3

so both vectors should stand above each other... 
when I use merge() I dont get this result, also not with cbind or rbind. 
I neither can make a a data frame of the two matrices. 
I think that I should use the function array with dim(6,2,2), but I dont
know how that is exactly working
(I couldn make it working)

I would be very glad if you could let me know how to solve this problem. 

Cheers, 
maria



--
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-merging-two-matrices-tp3983136p3983136.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Creating barplot using time as X

2011-11-03 Thread PEL
Hello all,

my data looks like this:

phaseno / activity  / beg / end / phasetime

1 / L / 2010-06-03 19:15:24 / 2010-06-03 21:18:14 / 7370
2 / D / 2010-06-03 21:18:15 / 2010-06-03 21:19:55 / 100
3 / W / 2010-06-03 21:19:56 / 2010-06-03 21:22:47 / 171
4 / D / 2010-06-03 21:22:48 / 2010-06-03 21:23:47 / 59
5 / W / 2010-06-03 21:23:48 / 2010-06-03 21:23:53 / 5
6 / D / 2010-06-03 21:23:54 / 2010-06-03 21:26:18 / 144
7 / W / 2010-06-03 21:26:19 / 2010-06-03 21:32:10 / 351
8 / D / 2010-06-03 21:32:11 / 2010-06-03 21:32:11 / 0
9 / W / 2010-06-03 21:32:12 / 2010-06-03 21:32:12 / 0
10 / D / 2010-06-03 21:32:13 / 2010-06-03 21:32:29 / 16

Please note that phasetime is in seconds and is only a difftime() of beg
and end.

I want to create a stacked bar chart that gives me the percentage of time
spent doing every activity (L,D or W) for every 24h period. 
Example: Day 1: 20% =L; 40% = W ; 40% = D.  In a graph obviously.

What I was thinking was dividing my dataframe into several smaller
dataframes spanning 24h. I tried with by() but I doubt this is the correct
function. If possible, I would also like to separate a row the phasetime of
a row if it overlaps two 24 periods. 


I joined part of my data where *header=TRUE and sep=\t*
http://r.789695.n4.nabble.com/file/n3981961/example.txt example.txt 

Thank you very much for your time
PEL

--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-barplot-using-time-as-X-tp3981961p3981961.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] MD5 checksum, mirror Zuerich

2011-11-03 Thread Stefan Bienert
Hi there,

I just downloaded the newest version of R for Mac from the mirror in Zuerich… 
checksums do not match.

bye,

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


[R] Extract Data from Yahoo Finance

2011-11-03 Thread Deb Midya
Hi R –users,
 
I am using R-2.14.0 on Windows XP.
 
May I request you to assist me for the following please.
 
I like to extract all the fields (example: a : Ask, b : Bid, ……, w : 52-week 
Range, x: Stock Exchange)  for certain period of time, say, 1 October 2011 to 
31 October 2011.
 
Is there any R-Package(s)  any R- script please?
 
Once again, thank you very much for the time you have given.
 
Regards,
 
Deb

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


[R] How much data can R process?

2011-11-03 Thread Nicholay Anne Caumeran
Would like to know how much data can R process - number of rows and columns?
[[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] Question about Calculation of Cross Product

2011-11-03 Thread 阮铮
The function of crossprod in R puzzled me.
I would like to calculate the cross product of two vectors. According to my 
text book, it defines like this:
a = (ax, ay, az)
b = (bx, by, bz)
then, the cross product of a and b is:
a X b = (ay*bz-az*by, az*bx-ax*bz, ax*by-ay*bz)
It can also write in a determinant format.


But the crossprod or tcrossprod function in R appeared not calculate the cross 
product. Suppose I enter this:
 a = c(1, 2, 3)
 b = c(2, 3, 4)
 ab = crossprod(a, b)
 ab
 [,1]
[1,]   20
 ab = tcrossprod(a, b)
 ab
 [,1] [,2] [,3]
[1,]234
[2,]468
[3,]69   12


Does any know how to calculate cross product in R. Or I have to write the 
function myself?
[[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] text orientation in persp

2011-11-03 Thread Andrew Gormley
I am doing a 3D plot using persp {graphics} but cannot figure out how to change 
the text direction on the z-axis. The default is for it to read down. Also, I 
cannot figure out how to change the position of the text itself.
Many thanks
Andrew


Please consider the environment before printing this email
Warning: This electronic message together with any attachments is confidential. 
If you receive it in error: (i) you must not read, use, disclose, copy or 
retain it; (ii) please contact the sender immediately by reply email and then 
delete the emails.
The views expressed in this email may not be those of Landcare Research New 
Zealand Limited. http://www.landcareresearch.co.nz

[[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] Problem with R CMD check and the inconsolata font business.

2011-11-03 Thread Rolf Turner


I have just installed R version 2.14.0 and tried to re-build and 
re-check some

of the packages that I maintain.

I'm getting a warning (in the process of running R CMD check on my deldir
package):


* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
! Font T1/fi4/m/n/10=ec-inconsolata at 10.0pt not loadable: Metric 
(TFM) file n

ot found.
to be read again
   relax
l.19 ...lf Turner }\email{r.tur...@auckland.ac.nz}
! \textfont 0 is undefined (character h).
\Url@FormatString ...\Url@String \UrlRight \m@th $

l.26 ...\AsIs{}\url{http://www.math.unb.ca/~rolf/}
  \AsIs{}
! \textfont 0 is undefined (character t).
\Url@FormatString ...\Url@String \UrlRight \m@th $

l.26 ...\AsIs{}\url{http://www.math.unb.ca/~rolf/}
  \AsIs{}
! \textfont 0 is undefined (character t).

.. etc., etc., etc., ad (almost) infinitum.

So there's some problem with a font file not being loadable.

Can anyone tell me what the expletive deleted I should ***do***
about this?  I managed to install the inconsolata package from CTAN.
At least I think I managed; I downloaded the *.zip file and then unzipped
it in /usr/share/texmf/tex/latex.  And ran texhash.  This stopped R CMD
check from complaining that the inconsolata package could not be found,
but then led to the further complaint described above.

So how do I make the required font loadable?  What files do I need?
Where do I get them?  And where should I put them once I've got them?

I would be grateful for any assistance that can be rendered.

(I know it's just a warning, but I *hate* to ignore warnings!)

cheers,

Rolf Turner

P. S.  I'm running Ubuntu; session info, in case it's of any relevance is:

sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] misc_0.0-15

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


Re: [R] nproc parameter in efpFunctional

2011-11-03 Thread bonda
Thank you. I've understood, that it should be k (number of parameters)
separate Brownian bridges. 
Is it possible, to get such separated/disaggregated processes also in
function efp()? (one can take gefp(..., family=gaussian), or construct by
myself residuals(lm.model)*X, but still interesting). And on the contrary,
how can I get an aggregated Brownian bridge path for all parameters
together, similar to efp()$process? It is made in plot.gefp, but only for
graphical visualization...
Thank you in advance!
Julia

--
View this message in context: 
http://r.789695.n4.nabble.com/nproc-parameter-in-efpFunctional-tp3972419p3984605.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] MD5 checksum, mirror Zuerich

2011-11-03 Thread peter dalgaard

On Nov 3, 2011, at 00:56 , Stefan Bienert wrote:

 Hi there,
 
 I just downloaded the newest version of R for Mac from the mirror in Zuerich… 
 checksums do not match.


They do for me. Perhaps you caught it in the middle of an update. Please retry.

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

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


[R] non-parametric sample size calculation

2011-11-03 Thread David A.

Hi,

I am trying to estimate the sample size needed for the comparison of two groups 
on a certain measurement, given some previous data at hand. I find that the 
data collected does not follow a normal distribution, so I would like to use a 
non-parametric option for sample size calculation.

I found the pwr package but I don't think it has this option and on the 
internet found that http://www.epibiostat.ucsf.edu/biostat/sampsize.html says 
only PASS allows non-parametric sample size calculations (although the webpage 
is not updated).

Any help would be greatly appreciated

Thanks,

Dave
  
[[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] palettes for the color-blind

2011-11-03 Thread Ken Knoblauch
Max Kuhn mxkuhn at gmail.com writes:

 
 Yes, I was aware of the different type and their respective 
prevalences.
 
 The dichromat package helped me find what I needed.
 
 Thanks,
 
 Max
 
 On Wed, Nov 2, 2011 at 6:38 PM, Thomas Lumley 
tlumley at uw.edu wrote:
  On Thu, Nov 3, 2011 at 11:04 AM, Carl Witthoft 
carl at witthoft.com wrote:
 
  Before you pick out a palette:  you are aware that their are several
  different types of color-blindness, aren't you?
 
  Yes, but to first approximation there are only two, and they have
  broadly similar, though not identical impact on choice of color
  palettes.  The dichromat package knows about them, and so does
  Professor Brewer.
 
  More people will be unable to read your graphs due to some kind of
  gross visual impairment (cataracts, uncorrected focusing problems,
  macular degeneration, etc) than will have tritanopia or 
monochromacy.
 
    -thomas
 

Sorry to come into this late, but I was travelling.

As indicated, the dichromat package will give you an excellent first
order approximation as to what works or doesn't for the 3 types
of congenital dichromacies, As indicated by THomas, the two most
prevalent varieties, protanopia and deuteranopia, result in similar
confusion axes and the third, tritanopia, is relatively rare, except
in eye disease.  That said, the most prevalent color deficiencies
are not the dichromacies but the anomalous trichromacies.  These
will not necessarily lead to losses in chromatic discrimination but
just shifts (i.e., one might see as orange or green what 
a normal trichromat sees as yellow).  About 20 years ago, I was
involved in an attempt to develop guidelines (or rules of thumb,
at least) for display design for color deficient observers, that did
not require any deep understanding of colorimetry.  The distillation
of this effort can be found here, for what it is worth;:

http://www.lighthouse.org/accessibility/design/
accessible-print-design/effective-color-contrast

The most important point, I think, was to make sure that there
was a sufficient luminance contrast difference, so that in the
absence of the capacity to make a chromatic discrimination,
the differences would still be detectable.  
The principles necessary for optimizing color choices in a 
scatterplot will certainly be more complex, however.
In this light (no pun intended), I would draw your attention
to the seminal work of Berniece Rogowitz at IBM:

http://www.research.ibm.com/people/l/lloydt/
color/color.HTM

http://www.research.ibm.com/dx/proceedings/
pravda/truevis.htm

who was (is) quite concerned with this issue, as well,
as the excellent article by Zeileis, Hornik and Murrell

http://statmath.wu.ac.at/~zeileis/papers/
Zeileis+Hornik+Murrell-2009.pdf

HTH,

Ken

-- 
Ken Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html

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


Re: [R] How much data can R process?

2011-11-03 Thread Rolf Turner

On 03/11/11 15:59, Nicholay Anne Caumeran wrote:

Would like to know how much data can R process - number of rows and columns?


How long is a piece of string?

cheers,

Rolf Turner

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


Re: [R] nproc parameter in efpFunctional

2011-11-03 Thread Achim Zeileis

On Thu, 3 Nov 2011, bonda wrote:


Thank you. I've understood, that it should be k (number of parameters)
separate Brownian bridges.


Well, if you use a process based on OLS residuals, you have always a 
one-dimensional process even though your model has k parameters. Hence, 
the two parameters are really conceptually different..



Is it possible, to get such separated/disaggregated processes also in
function efp()? (one can take gefp(..., family=gaussian), or construct by
myself residuals(lm.model)*X, but still interesting).


Some processes that efp() computes are always 1-dimensional (namely those 
based on residuals) while some are k-dimensional (namely the 
estimates-based processes) and some are (k+1)-dimensional (the score-based 
processes).


gefp() generalizes this concept and lets you construct the fluctuation 
processes fairly flexibly.


And on the contrary, how can I get an aggregated Brownian bridge path 
for all parameters together, similar to efp()$process? It is made in 
plot.gefp, but only for graphical visualization...


For gefp objects all aggregation is done by the efpFunctional employed.

But this is really described in a fair amount of detail in the 
accompanying papers. Specifically, for gefp/efpFunctional in the 2006 CSDA 
paper.



Thank you in advance!
Julia

--
View this message in context: 
http://r.789695.n4.nabble.com/nproc-parameter-in-efpFunctional-tp3972419p3984605.html
Sent from the R help mailing list archive at Nabble.com.

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



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


Re: [R] array manipulation

2011-11-03 Thread Patrick Burns

You seem to be looking for 'aperm'.

There is a chapter in 'S Poetry' (available
on http://www.burns-stat.com) that talks
about working with higher dimensional
arrays.  I don't think any changes need
to be made for R.

On 02/11/2011 16:16, Simone Salvadei wrote:

Hello,
I'm at the very beginning of the learning process of this language.
Sorry in advance for the (possible but plausible) stupidity of my question.

I would like to find a way to permute the DIMENSIONS of an array.
Something that sounds like the function permute() in matlab.

Given an array C of dimensions c x d x T , for instance, the command

permute(C, [2 1 3])

would provide (in Matlab) an array very similar to C, but this time each
one of the T matrices c x d has changed into its transposed.
Any alternatives to the following (and primitive) 'for' cycle?

*# (previously defined) phi=array with dimensions c(c,d,T)*
*
*
*temp=array(0,dim=c(c,d,T))*
* for(i in 1:T)*
* {*
* temp[,,i]=t(phi[,,i])*
* }*
* phi=temp*
*
*

Thank you very much!
S



--
Patrick Burns
pbu...@pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

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


Re: [R] How much data can R process?

2011-11-03 Thread Jim Lemon

On 11/03/2011 08:20 PM, Rolf Turner wrote:

On 03/11/11 15:59, Nicholay Anne Caumeran wrote:

Would like to know how much data can R process - number of rows and
columns?


How long is a piece of string?


Around 10e-35 meters.

Jim

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


[R] RGoogleTrends error in getGTrends

2011-11-03 Thread Tal Galili
Hi all,

I've just installed RGoogleTrends Version:0.2-1 (after compiling it for
windows).
And when running the most basic command I get the following error:

ans = getGTrends(coupon)
Error in curlPerform(url = url, curl = curl, .opts = .opts) :
  embedded nul in string: 'fffeY'
In addition: Warning message:
RS-DBI driver warning: (closing pending result sets before closing this
connection)


Am I missing something, or is this due to some change in Rgoogletrends
website?

p.s: any chance there is a Rgoogleinsights alternative? (for
http://www.google.com/insights/search/) I wasn't able to find any.


Thanks in advance,
Tal


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

[[alternative HTML version deleted]]

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


Re: [R] mysterious warning message regarding bytecode...

2011-11-03 Thread Uwe Ligges



On 02.11.2011 23:51, Justin Haynes wrote:

While running a long script which source()s other scripts I get the
following warning:

Warning message:
In t(object$S[[1]]) : bytecode version mismatch; using eval


Are you using byte compiled code from some package or is the source code 
byte compiled at runtime? If the former, I guess the packages was 
installed under another version of R than the version of R you are using.


Anyway, nothing to reproduce here nor a suficient description what you 
really did.


Best,
Uwe Ligges






I cannot replicate it if I run the sourced files line by line though...

What is that error?  And do I care about it?  It doesn't seem to
affect my output as far as I can tell.


Thanks!
Justin



sessionInfo()

R version 2.13.2 (2011-09-30)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
LC_PAPER=en_US.UTF-8   LC_NAME=C
  [9] LC_ADDRESS=C   LC_TELEPHONE=C
LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
  [1] mgcv_1.7-9stringr_0.5   RPostgreSQL_0.2-0 biglm_0.8
   DBI_0.2-5 doMC_1.2.3multicore_0.1-7
  [8] foreach_1.3.2 codetools_0.2-8   iterators_1.0.5
cairoDevice_2.19  pixmap_0.4-11 gridExtra_0.8.5   splancs_2.01-29
[15] sp_0.9-91 ellipse_0.3-5 ggplot2_0.8.9
proto_0.3-9.2 reshape_0.8.4 plyr_1.6  MASS_7.3-14

loaded via a namespace (and not attached):
[1] compiler_2.13.2 digest_0.5.1lattice_0.19-33 Matrix_1.0-1nlme_3.1-102

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


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


Re: [R] problem with merging two matrices

2011-11-03 Thread Sarah Goslee
Hi,

On Wednesday, November 2, 2011, flokke flo...@live.de wrote:
 Dear all,
 I hope you can forgive me my stupid questions, but I am a very new R user
(;

 So, this is my question:

 I have two matrices,
 those are:

 matrix1 - matrix(cbind(vector1, vector2), 1,2, dimnames =
list(c(values),
   c(T value,
 p value)))

 matrix2 - matrix(dcbind,2,6,dimnames = list(c(x, y),
  c(Min, 1st qu., Median, Mean,
3rd
 qu., Max)))

 Now, I would like to merge them, but I want to receive the following
result:

 Min 1st qu. Median Mean 3rd qu. Max
  x   3  34  44  4
  y   3   3   3  3 3 3

   t value p value
 value   3   3

 so both vectors should stand above each other...
 when I use merge() I dont get this result, also not with cbind or rbind.
 I neither can make a a data frame of the two matrices.
 I think that I should use the function array with dim(6,2,2), but I dont
 know how that is exactly working
 (I couldn make it working)

What are you trying to do, really? You have a matrix with one row and two
columns, and a matrix with two rows and six columns. Those just don't fit
together.

If you're. trying to work wit them in a different form, you'll. need to
give more detail. If you're just trying to display them, then print them
sequentially.

Otherwise, I'm perplexed.

Sarah

 I would be very glad if you could let me know how to solve this problem.

 Cheers,
 maria

 View this message in context:
http://r.789695.n4.nabble.com/problem-with-merging-two-matrices-tp3983136p3983136.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.


-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

[[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] Error: serialization is too large to store in a raw vector

2011-11-03 Thread Martin Morgan

On 11/02/2011 03:37 PM, Alaios wrote:

Dear all,
I have quite large code (with lapply and mclapply)
and I am getting the following error.

Error: serialization is too large to store in a raw vector

Is it possible to ask from R to extend the Error messages with more details?
I would like to see where this problem exists.


This is likely from the return value of mclapply's FUN: 
parallel:::sendMaster tries to serialize it, and fails.


  serialize(integer(.Machine$integer.max / 4), NULL, TRUE)

do further data reduction before trying to return the results (probably 
a parallel 'best practices' anyway). Neither traceback() nor 
options(error=recover) deal gracefully with mclapply errors like this.


Hope that helps,

Martin



B.R
Alex
[[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.



--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793

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

2011-11-03 Thread Stephen Sefick
#This is probably due to my incomplete understanding of grep, but the 
below code has been working for some time to
#search for .R with anything in front of it and return a list of scripts 
to source.  Likely, the syntax for the

#grep statement has been wrong all along.

scripts2source - (c(/home/ssefick/R_scripts/Convert_package.R, 
/home/ssefick/R_scripts/Convert_R_CODE,

/home/ssefick/R_scripts/CV.R, /home/ssefick/R_scripts/cvs.out.R,
/home/ssefick/R_scripts/database_connect, 
/home/ssefick/R_scripts/database_connect_package.R,

/home/ssefick/R_scripts/exit_db.R, /home/ssefick/R_scripts/exit.R,
/home/ssefick/R_scripts/hourly_zoo.R, 
/home/ssefick/R_scripts/model_diag.R,
/home/ssefick/R_scripts/not_numeric.R, 
/home/ssefick/R_scripts/num_ecol_package.R,
/home/ssefick/R_scripts/NumEcolR_scripts, 
/home/ssefick/R_scripts/old_scripts_DELETE_AFTER_DECEMBER,
/home/ssefick/R_scripts/only_numeric_dataframe.R, 
/home/ssefick/R_scripts/only_numeric.R,
/home/ssefick/R_scripts/PCA.ve.R, 
/home/ssefick/R_scripts/poster_ggplot2_theme.R,
/home/ssefick/R_scripts/pressure_transducer_package.R, 
/home/ssefick/R_scripts/Pressure_Transducer_R_CODE,
/home/ssefick/R_scripts/publication_ggplot2_theme.R, 
/home/ssefick/R_scripts/r2test.R,
/home/ssefick/R_scripts/recession_constant_package.R, 
/home/ssefick/R_scripts/recession_constant_R_CODE,
/home/ssefick/R_scripts/serdp_name_split.R, 
/home/ssefick/R_scripts/setup_R.R,

/home/ssefick/R_scripts/USGS.R))

scripts2source[grep(*.R, scripts2source)]

#here is my problem;  I would like these to be removed.
scripts2source[c(2,5,13,14,20,24)]

#Thanks for all of your help in advance
#kindest regards,

#Stephen Sefick

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


Re: [R] How much data can R process?

2011-11-03 Thread Michael Dewey

At 02:59 03/11/2011, Nicholay Anne Caumeran wrote:

Would like to know how much data can R process - number of rows and columns?


Nicholay,

You are going to have to give us a lot more information before anyone 
can even attempt to answer this. Assuming you have tried to analyse 
your data and failed for some reason you might want to look at the 
High Performance Computing task view on CRAN and examine the section 
entitled large memory and out of memory data.



[[alternative HTML version deleted]]


Michael Dewey
i...@aghmed.fsnet.co.uk
http://www.aghmed.fsnet.co.uk/home.html

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


Re: [R] grep fixed (?) in 2.14

2011-11-03 Thread Sarah Goslee
Hi,

. and * both mean something different in regular expressions than in
command-line wildcards. You need:

grep(.*\\.R$, scripts2source)

which parses to
.- any character
*- any number of times
\\.  - an actual . escaped as R requires
R  - the R denoting a script
$  - at the end of the string

 grep(.*\\.R$, scripts2source)
 [1]  1  3  4  6  7  8  9 10 11 12 15 16 17 18 19 21 22 23 25 26 27

Sarah

On Thu, Nov 3, 2011 at 8:54 AM, Stephen Sefick sas0...@auburn.edu wrote:
 #This is probably due to my incomplete understanding of grep, but the below
 code has been working for some time to
 #search for .R with anything in front of it and return a list of scripts to
 source.  Likely, the syntax for the
 #grep statement has been wrong all along.

 scripts2source - (c(/home/ssefick/R_scripts/Convert_package.R,
 /home/ssefick/R_scripts/Convert_R_CODE,
 /home/ssefick/R_scripts/CV.R, /home/ssefick/R_scripts/cvs.out.R,
 /home/ssefick/R_scripts/database_connect,
 /home/ssefick/R_scripts/database_connect_package.R,
 /home/ssefick/R_scripts/exit_db.R, /home/ssefick/R_scripts/exit.R,
 /home/ssefick/R_scripts/hourly_zoo.R,
 /home/ssefick/R_scripts/model_diag.R,
 /home/ssefick/R_scripts/not_numeric.R,
 /home/ssefick/R_scripts/num_ecol_package.R,
 /home/ssefick/R_scripts/NumEcolR_scripts,
 /home/ssefick/R_scripts/old_scripts_DELETE_AFTER_DECEMBER,
 /home/ssefick/R_scripts/only_numeric_dataframe.R,
 /home/ssefick/R_scripts/only_numeric.R,
 /home/ssefick/R_scripts/PCA.ve.R,
 /home/ssefick/R_scripts/poster_ggplot2_theme.R,
 /home/ssefick/R_scripts/pressure_transducer_package.R,
 /home/ssefick/R_scripts/Pressure_Transducer_R_CODE,
 /home/ssefick/R_scripts/publication_ggplot2_theme.R,
 /home/ssefick/R_scripts/r2test.R,
 /home/ssefick/R_scripts/recession_constant_package.R,
 /home/ssefick/R_scripts/recession_constant_R_CODE,
 /home/ssefick/R_scripts/serdp_name_split.R,
 /home/ssefick/R_scripts/setup_R.R,
 /home/ssefick/R_scripts/USGS.R))

 scripts2source[grep(*.R, scripts2source)]

 #here is my problem;  I would like these to be removed.
 scripts2source[c(2,5,13,14,20,24)]

 #Thanks for all of your help in advance
 #kindest regards,

 #Stephen Sefick

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

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


Re: [R] grep fixed (?) in 2.14

2011-11-03 Thread jim holtman
your syntax is wrong, you need:

 scripts2source[grep(*\\.R$, scripts2source)]

Notice the '\\.' to escape the special meaning of '.', and the $ to
anchor to the end of the line.


On Thu, Nov 3, 2011 at 8:54 AM, Stephen Sefick sas0...@auburn.edu wrote:
 #This is probably due to my incomplete understanding of grep, but the below
 code has been working for some time to
 #search for .R with anything in front of it and return a list of scripts to
 source.  Likely, the syntax for the
 #grep statement has been wrong all along.

 scripts2source - (c(/home/ssefick/R_scripts/Convert_package.R,
 /home/ssefick/R_scripts/Convert_R_CODE,
 /home/ssefick/R_scripts/CV.R, /home/ssefick/R_scripts/cvs.out.R,
 /home/ssefick/R_scripts/database_connect,
 /home/ssefick/R_scripts/database_connect_package.R,
 /home/ssefick/R_scripts/exit_db.R, /home/ssefick/R_scripts/exit.R,
 /home/ssefick/R_scripts/hourly_zoo.R,
 /home/ssefick/R_scripts/model_diag.R,
 /home/ssefick/R_scripts/not_numeric.R,
 /home/ssefick/R_scripts/num_ecol_package.R,
 /home/ssefick/R_scripts/NumEcolR_scripts,
 /home/ssefick/R_scripts/old_scripts_DELETE_AFTER_DECEMBER,
 /home/ssefick/R_scripts/only_numeric_dataframe.R,
 /home/ssefick/R_scripts/only_numeric.R,
 /home/ssefick/R_scripts/PCA.ve.R,
 /home/ssefick/R_scripts/poster_ggplot2_theme.R,
 /home/ssefick/R_scripts/pressure_transducer_package.R,
 /home/ssefick/R_scripts/Pressure_Transducer_R_CODE,
 /home/ssefick/R_scripts/publication_ggplot2_theme.R,
 /home/ssefick/R_scripts/r2test.R,
 /home/ssefick/R_scripts/recession_constant_package.R,
 /home/ssefick/R_scripts/recession_constant_R_CODE,
 /home/ssefick/R_scripts/serdp_name_split.R,
 /home/ssefick/R_scripts/setup_R.R,
 /home/ssefick/R_scripts/USGS.R))

 scripts2source[grep(*.R, scripts2source)]

 #here is my problem;  I would like these to be removed.
 scripts2source[c(2,5,13,14,20,24)]

 #Thanks for all of your help in advance
 #kindest regards,

 #Stephen Sefick

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




-- 
Jim Holtman
Data Munger Guru

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

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


Re: [R] Question about Calculation of Cross Product

2011-11-03 Thread R. Michael Weylandt
Try

library(pracma)
? cross

Michael Weylandt

On Thu, Nov 3, 2011 at 1:17 AM, 阮铮 rz1...@foxmail.com wrote:
 The function of crossprod in R puzzled me.
 I would like to calculate the cross product of two vectors. According to my 
 text book, it defines like this:
 a = (ax, ay, az)
 b = (bx, by, bz)
 then, the cross product of a and b is:
 a X b = (ay*bz-az*by, az*bx-ax*bz, ax*by-ay*bz)
 It can also write in a determinant format.


 But the crossprod or tcrossprod function in R appeared not calculate the 
 cross product. Suppose I enter this:
 a = c(1, 2, 3)
 b = c(2, 3, 4)
 ab = crossprod(a, b)
 ab
     [,1]
 [1,]   20
 ab = tcrossprod(a, b)
 ab
     [,1] [,2] [,3]
 [1,]    2    3    4
 [2,]    4    6    8
 [3,]    6    9   12


 Does any know how to calculate cross product in R. Or I have to write the 
 function myself?
        [[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] Extract Data from Yahoo Finance

2011-11-03 Thread R. Michael Weylandt
The quantmod package can probably do what you are asking, but it's a
little hard to be certain since you provide neither a list of all the
fields you are actually talking about nor a link to the page with the
fields in question.

Michael

On Thu, Nov 3, 2011 at 12:02 AM, Deb Midya debmi...@yahoo.com wrote:
 Hi R –users,

 I am using R-2.14.0 on Windows XP.

 May I request you to assist me for the following please.

 I like to extract all the fields (example: a : Ask, b : Bid, ……, w : 52-week 
 Range, x: Stock Exchange)  for certain period of time, say, 1 October 2011 to 
 31 October 2011.

 Is there any R-Package(s)  any R- script please?

 Once again, thank you very much for the time you have given.

 Regards,

 Deb

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 plots and missing x-axis labels on second page

2011-11-03 Thread Bert Gunter
I believe that the explanation is:

Axes, including tick labels, appear only on the edges of the trellis
array, which in your case would be at the bottom of the 4th row. However,
on the second page there is no 4th row, and lattice is not smart enough to
put them instead at the bottom of the second.

See the scales argument of xyplot, especially the alternating
component, for how you can gain finer control to deal with your situation.

Note: I would appreciate correction if I'm wrong about this.

-- Bert

On Wed, Nov 2, 2011 at 5:23 PM, Evans, David G (DFG) david.ev...@alaska.gov
 wrote:

 using




-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

[[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] Select columns of a data.frame by name OR index in a function

2011-11-03 Thread Thaler, Thorn, LAUSANNE, Applied Mathematics
Dear all,

Sometimes I have the situation where a function takes a data.frame and
an additional argument describing come columns. For greater flexibility
I want to allow for either column names or column indices. What I
usually do then is something like the following:

-8-
f - function(datf, cols) {
  nc - seq_along(datf)
  cn - colnames(datf)
  colOK - (cols %in% nc) | (cols %in% cn)
  if (!all(colOK)) {
badc - paste(sQuote(cols[!colOK]), collapse = , )
msg - sprintf(ngettext(sum(!colOK),
%s is not a valid column selector,
%s are not valid column selectors),
   badc)
stop(msg)
  }
  which((nc %in% cols) | (cn %in% cols)) # with this set of indices I
would work in the rest of the code
}

dd - data.frame(a=1, b=1, c=1)
f(dd, 2:3) # [1] 2 3
f(dd, 1:4)  # Error in f(dd, 1:4) : '4' is not a valid column selector
f(dd, a) # [1] 1
f(dd, c(a, d, e)) # Error in f(dd, c(a, d, e)) : 'd', 'e'
are not valid column selectors
-8-

So my question is, whether there are smarter/better/easier/more R-like
ways of doing that?

Any input appreciated.


KR,

-Thorn

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


Re: [R] grep fixed (?) in 2.14

2011-11-03 Thread Stephen Sefick
That did the trick.  I have read about regular expressions often, and 
sometimes I get them right and sometimes I don't.  Is there a good 
reference resource that anyone could suggest?  Thanks for all of the help.


Stephen Sefick



On 11/03/2011 08:03 AM, jim holtman wrote:

your syntax is wrong, you need:

  scripts2source[grep(*\\.R$, scripts2source)]

Notice the '\\.' to escape the special meaning of '.', and the $ to
anchor to the end of the line.


On Thu, Nov 3, 2011 at 8:54 AM, Stephen Seficksas0...@auburn.edu  wrote:

#This is probably due to my incomplete understanding of grep, but the below
code has been working for some time to
#search for .R with anything in front of it and return a list of scripts to
source.  Likely, the syntax for the
#grep statement has been wrong all along.

scripts2source- (c(/home/ssefick/R_scripts/Convert_package.R,
/home/ssefick/R_scripts/Convert_R_CODE,
/home/ssefick/R_scripts/CV.R, /home/ssefick/R_scripts/cvs.out.R,
/home/ssefick/R_scripts/database_connect,
/home/ssefick/R_scripts/database_connect_package.R,
/home/ssefick/R_scripts/exit_db.R, /home/ssefick/R_scripts/exit.R,
/home/ssefick/R_scripts/hourly_zoo.R,
/home/ssefick/R_scripts/model_diag.R,
/home/ssefick/R_scripts/not_numeric.R,
/home/ssefick/R_scripts/num_ecol_package.R,
/home/ssefick/R_scripts/NumEcolR_scripts,
/home/ssefick/R_scripts/old_scripts_DELETE_AFTER_DECEMBER,
/home/ssefick/R_scripts/only_numeric_dataframe.R,
/home/ssefick/R_scripts/only_numeric.R,
/home/ssefick/R_scripts/PCA.ve.R,
/home/ssefick/R_scripts/poster_ggplot2_theme.R,
/home/ssefick/R_scripts/pressure_transducer_package.R,
/home/ssefick/R_scripts/Pressure_Transducer_R_CODE,
/home/ssefick/R_scripts/publication_ggplot2_theme.R,
/home/ssefick/R_scripts/r2test.R,
/home/ssefick/R_scripts/recession_constant_package.R,
/home/ssefick/R_scripts/recession_constant_R_CODE,
/home/ssefick/R_scripts/serdp_name_split.R,
/home/ssefick/R_scripts/setup_R.R,
/home/ssefick/R_scripts/USGS.R))

scripts2source[grep(*.R, scripts2source)]

#here is my problem;  I would like these to be removed.
scripts2source[c(2,5,13,14,20,24)]

#Thanks for all of your help in advance
#kindest regards,

#Stephen Sefick

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

2011-11-03 Thread Marc Schwartz
On Nov 3, 2011, at 3:47 AM, David A. wrote:

 
 Hi,
 
 I am trying to estimate the sample size needed for the comparison of two 
 groups on a certain measurement, given some previous data at hand. I find 
 that the data collected does not follow a normal distribution, so I would 
 like to use a non-parametric option for sample size calculation.
 
 I found the pwr package but I don't think it has this option and on the 
 internet found that http://www.epibiostat.ucsf.edu/biostat/sampsize.html says 
 only PASS allows non-parametric sample size calculations (although the 
 webpage is not updated).
 
 Any help would be greatly appreciated
 
 Thanks,
 
 Dave


The first question is how non normal are your data? If you used some formal 
test for normality and the p value was =0.05, I would suggest that you search 
the R-Help archives for a plethora of discussions on testing for normality. You 
will find that such tests should largely not be used in deference to the 
question Are the data normal enough?. If they are or can be transformed 
reasonably, use standard functions for calculating power and sample size, such 
as power.t.test().

If you need to use a non-parametric test, you might want to review this page by 
Jerry Dallal:

  http://www.jerrydallal.com/LHSP/npar.htm

which has some general guidelines for calculating sample size predicated upon 
using standard parametric tests and then adjusting the sample size using the 
ARE (asymptotic relative efficiency) based upon the non-parametric intended.

HTH,

Marc Schwartz

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


Re: [R] HOW TO REMOVE MTEXT FROM PLOT, plotting changing populations with titles in loop

2011-11-03 Thread Uwe Ligges



On 02.11.2011 20:29, Sarah Goslee wrote:

It's not perfect, but you could use:

mtext(paste(this is iteration , i, sep=), col=white)

to overwrite it, or polygon() to draw a white rectangle over the text each time.


The question is if it is not better to do the whole plot again and just 
add the one text in the end. At least if you want to plot into  non 
screen device: You end up with ll those layers of text in the output 
that makes it larger and additionally slows down the rendering of the 
whole plot.


Uwe Ligges





Sarah

On Wed, Nov 2, 2011 at 3:15 PM, prinzOfNorwaytorgrim...@gmail.com  wrote:

is there a way to hide/undraw mtext (or lines etc.) in a loop like

plot(runif(10))
iterCol- rainbowPalette(10)

for(i in 1:10){

mtext(paste(this is iteration , i, sep=))
points(runif(10),col=iterCol[i])
Sys.sleep(1)

## UNDRAW/HIDE the text so that it does not mess up the plot in the next
iteration

}





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


Re: [R] Creating barplot using time as X

2011-11-03 Thread Richard M. Heiberger
This should get you started.

 PEL - read.table(http://r.789695.n4.nabble.com/file/n3981961/example.txt;,
header=TRUE, sep=\t)
 PELtable - with(PEL, tapply(phasetime, data.frame(activity,
as.Date(beg)), sum))
 PELtable
as.Date.beg.
activity 2010-06-03 2010-06-04 2010-06-05 2010-06-06 2010-06-07
   D   3407  14405  17704  16740   7096
   L   7370  43544  35898  30401 NA
   W   5976  26611  30294  36807  14466
 PELtable[2,5] - 0
 as.data.frame.table(PELtable)
   activity as.Date.beg.  Freq
1 D   2010-06-03  3407
2 L   2010-06-03  7370
3 W   2010-06-03  5976
4 D   2010-06-04 14405
5 L   2010-06-04 43544
6 W   2010-06-04 26611
7 D   2010-06-05 17704
8 L   2010-06-05 35898
9 W   2010-06-05 30294
10D   2010-06-06 16740
11L   2010-06-06 30401
12W   2010-06-06 36807
13D   2010-06-07  7096
14L   2010-06-07 0
15W   2010-06-07 14466
 barchart(Freq ~ as.Date.beg. , groups=activity,
data=as.data.frame.table(PELtable),
+  stack=TRUE, auto.key=list(reverse=TRUE))


You might wish to be more precise in your definition of a 24-hour time
period.  I used calendar date here.
Rich
On Wed, Nov 2, 2011 at 3:24 PM, PEL pierre-etienne.lessar...@ulaval.cawrote:

 Hello all,

 my data looks like this:

 phaseno / activity  / beg / end / phasetime

 1 / L / 2010-06-03 19:15:24 / 2010-06-03 21:18:14 / 7370
 2 / D / 2010-06-03 21:18:15 / 2010-06-03 21:19:55 / 100
 3 / W / 2010-06-03 21:19:56 / 2010-06-03 21:22:47 / 171
 4 / D / 2010-06-03 21:22:48 / 2010-06-03 21:23:47 / 59
 5 / W / 2010-06-03 21:23:48 / 2010-06-03 21:23:53 / 5
 6 / D / 2010-06-03 21:23:54 / 2010-06-03 21:26:18 / 144
 7 / W / 2010-06-03 21:26:19 / 2010-06-03 21:32:10 / 351
 8 / D / 2010-06-03 21:32:11 / 2010-06-03 21:32:11 / 0
 9 / W / 2010-06-03 21:32:12 / 2010-06-03 21:32:12 / 0
 10 / D / 2010-06-03 21:32:13 / 2010-06-03 21:32:29 / 16

 Please note that phasetime is in seconds and is only a difftime() of beg
 and end.

 I want to create a stacked bar chart that gives me the percentage of time
 spent doing every activity (L,D or W) for every 24h period.
 Example: Day 1: 20% =L; 40% = W ; 40% = D.  In a graph obviously.

 What I was thinking was dividing my dataframe into several smaller
 dataframes spanning 24h. I tried with by() but I doubt this is the correct
 function. If possible, I would also like to separate a row the phasetime of
 a row if it overlaps two 24 periods.


 I joined part of my data where *header=TRUE and sep=\t*
 http://r.789695.n4.nabble.com/file/n3981961/example.txt example.txt

 Thank you very much for your time
 PEL

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Creating-barplot-using-time-as-X-tp3981961p3981961.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


[R] variable transformation for lm

2011-11-03 Thread Johannes Radinger
Hello,

I am doing a simple regression using lm(Y~X).
As my response and my predictor seemed to be skewed
and I can't meet the model assumptions. Therefore
I need to transform my variables.

I wanted to ask what is the preferred way to find out
if predictor and/or response needs to be transformed
and if yes how (log-transform?).

I found a procedure in A modern approach to Regressoin
in R (Sheather, 2009): There they suggest an approach
with the function bctrans from alr3...but it seems that it
is deprecated. So what is the best way (box-cox test) find the best
transformation for predictor and response simultaneously?
AFAIK boxcox from MASS is used only used for transformation
of the predictor?

Thank you very much
Johannes

--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Take variables in data.frame and create list of matrices

2011-11-03 Thread AC Del Re
Hi,

I have this sample data below and would like to create a list of matricies.

setseed(1254)
id - c(1,1,1,1 ,2,2,2)
o - as.factor(c(1:4, 1, 3, 4))
r - rep(.5, 7)
v - rnorm(7)
s - rnorm(7)

dat -data.frame(id, o, r, v, s)
dat

# dat
# id o   r  v  s
# 1  1 0.5  0.7024631  2.0813672
# 1  2 0.5 -0.5541955  0.1095156
# 1  3 0.5 -1.0418167  0.4164930
# 1  4 0.5  1.9973868 -2.0402058
# 2  1 0.5  1.3957243 -0.2548652
# 2  3 0.5 -0.6571325  0.6946570
# 2  4 0.5  1.3998202  0.4601017

Is there an easy way (or convenient function) to convert this into a list
where each unique 'id' has
its own 4x4 matrix (based on the maximum number of factor levels in 'o')in
the list?
Each matrix would have v in the diagonal and r*s*s in the off-diagonal
(e.g.,
.5*2.0814*.1095 = 0.1139), where
r is constant (.5) and s varies based on the wthin 'id' factor level of
'o'.
The output would look something like this (except values in all cells):

[[id 1]]

 'o'-levels  [,1][,2]   [,3]  [,4]

 [1,]  .702  .1139 r*s1*s3  ...

 [2,]  .1139 .702  r*s2*s3  ...

 [3,]  r*s3*s1.... 702

 [4,] .702


[[id 2]]

 'o'-levels  [,1]  [,2]   [,3]   [,4]

 [1,]  .702   NA  r*s1*s3  ...

 [2,]  NA   .702  NA ...

 [3,]  r*s3*s1   NA  .702

 [4,]   ....702


any assistance is much appreciated.

Thank you,

AC

[[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] Sample size calculations for one sided binomial exact test

2011-11-03 Thread Marc Schwartz
From: https://stat.ethz.ch/pipermail/r-help/2011-November/294329.html

 I'm trying to compute sample size requirements for a binomial exact test.
  we want to show that the proportion is at least 90% assuming that it is
 95%, with 80% power so any asymptotic approximations are out of the
 questions.  I was planning on using binom.test to perform the simple test
 against a prespecified value, but cannot find any functions for computing
 sample size.  do any exist?
 
 Thanks,
 Andrew



Hi,

I don't have the original e-mail, so this reply will be out of the thread in 
the archive.

I am not aware of anything pre-existing in R for this application, but stand to 
be corrected on that point. 

There are at least two non-R related options:

1. The G*Power program which is available from:

  http://www.psycho.uni-duesseldorf.de/abteilungen/aap/gpower3/


2. There is a paper by A'Hern which contains sample size tables here:

  Sample size tables for exact single-stage phase II designs
  R.P. A'Hern
  STATISTICS IN MEDICINE Statist. Med. 2001; 20:859–866
  http://stat.ethz.ch/education/semesters/as2011/bio/ahernSampleSize.pdf


The author used the BINOMDIST function in Excel to derive the tables. 
Notwithstanding criticisms of Excel, these tables, based upon a small test 
sample, agree with the G*Power program, as well as my own computations using R 
code below. He also uses normal approximations for sample sizes 300, given the 
limitations found in the BINOMDIST function.


Here is my R code for deriving the critical value and sample size for a one 
sided exact binomial test, given an alpha, a null proportion, an alternate 
proportion and the desired power:


# The possible sample size vector N needs to be selected in such a fashion
# that it covers the possible range of values that include the true
# minima. My example here does with a finite range and makes the 
# plot easier to visualize.
N - 100:200

Alpha - 0.05
Pow - 0.8
p0 - 0.90
p1 - 0.95

# Required number of events, given a vector of sample sizes (N)
# to be considered at the null proportion, for the given Alpha
CritVal - qbinom(p = 1 - Alpha, size = N, prob = p0)

# Get Beta (Type II error) for each N at the alternate hypothesis
# proportion
Beta - pbinom(CritVal, N, p1)

# Get the Power
Power - 1 - Beta

# Find the smallest sample size yielding at least the required power
SampSize - min(which(Power  Pow))

# Get and print the required number of events to reject the null
# given the sample size required
(Res - paste(CritVal[SampSize] + 1, out of, N[SampSize]))


# Plot it all 
plot(N, Power, type = b, las = 1)

title(paste(One Sided Sample Size and Critical Value for H0 =, p0, 
versus HA = , p1, \n,
For Power = , Pow),
  cex.main = 0.95)

points(N[SampSize], Power[SampSize], col = red, pch = 19)

text(N[SampSize], Power[SampSize], col = red,
 label = Res, pos = 3)

abline(h = Pow, lty = dashed)




One thing to note here (see the plot) is the non-monotonic function describing 
the power at each of the values of the sample size. This is due to the discrete 
nature of the binomial distribution. It also generally means that you are 
powering the sample size calculation for an alpha at something lower than the 
value indicated. The G*Power program provides both the actual alpha and power, 
given the input values. So there is a need to search the vector of sample sizes 
where the power is greater than that desired, to obtain the smallest sample 
size required to satisfy the power desired.

The above could of course be encapsulated in a function to make use easier, but 
the code yields values that agree with both the G*Power application and 
A'Hern's tables.

Hope that this is helpful.

Regards,

Marc Schwartz

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


Re: [R] Take variables in data.frame and create list of matrices

2011-11-03 Thread jose Bartolomei

If i understood correctly this may help you  dlply(dat, .(id))
$`1`
  id o   r  v  s
1  1 1 0.5 -1.7131858 -2.0548666
2  1 2 0.5  0.6582979  0.9688939
3  1 3 0.5 -0.6861830  2.4213072
4  1 4 0.5  1.4134171 -0.4540244$`2`
  id o   r  v  s
5  2 1 0.5  0.2771839  1.0688474
6  2 3 0.5 -0.7543462 -1.0371494
7  2 4 0.5 -1.9810018 -0.6742232

  Date: Thu, 3 Nov 2011 08:54:52 -0700
 From: de...@wisc.edu
 To: r-help@r-project.org
 Subject: [R] Take variables in data.frame and create list of matrices
 
 Hi,
 
 I have this sample data below and would like to create a list of matricies.
 
 setseed(1254)
 id - c(1,1,1,1 ,2,2,2)
 o - as.factor(c(1:4, 1, 3, 4))
 r - rep(.5, 7)
 v - rnorm(7)
 s - rnorm(7)
 
 dat -data.frame(id, o, r, v, s)
 dat
 
 # dat
 # id o   r  v  s
 # 1  1 0.5  0.7024631  2.0813672
 # 1  2 0.5 -0.5541955  0.1095156
 # 1  3 0.5 -1.0418167  0.4164930
 # 1  4 0.5  1.9973868 -2.0402058
 # 2  1 0.5  1.3957243 -0.2548652
 # 2  3 0.5 -0.6571325  0.6946570
 # 2  4 0.5  1.3998202  0.4601017
 
 Is there an easy way (or convenient function) to convert this into a list
 where each unique 'id' has
 its own 4x4 matrix (based on the maximum number of factor levels in 'o')in
 the list?
 Each matrix would have v in the diagonal and r*s*s in the off-diagonal
 (e.g.,
 .5*2.0814*.1095 = 0.1139), where
 r is constant (.5) and s varies based on the wthin 'id' factor level of
 'o'.
 The output would look something like this (except values in all cells):
 
 [[id 1]]
 
  'o'-levels  [,1][,2]   [,3]  [,4]
 
  [1,]  .702  .1139 r*s1*s3  ...
 
  [2,]  .1139 .702  r*s2*s3  ...
 
  [3,]  r*s3*s1.... 702
 
  [4,] .702
 
 
 [[id 2]]
 
  'o'-levels  [,1]  [,2]   [,3]   [,4]
 
  [1,]  .702   NA  r*s1*s3  ...
 
  [2,]  NA   .702  NA ...
 
  [3,]  r*s3*s1   NA  .702
 
  [4,]   ....702
 
 
 any assistance is much appreciated.
 
 Thank you,
 
 AC
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
  
[[alternative HTML version deleted]]

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


Re: [R] Take variables in data.frame and create list of matrices

2011-11-03 Thread jose Bartolomei

 I missed; using the Hadley Wickham plyr package library (plyr) dlply(dat, 
.(id))
$`1`
  id o   r  v  s
1  1 1 0.5 -1.7131858 -2.0548666
2  1 2 0.5  0.6582979  0.9688939
3  1 3 0.5 -0.6861830  2.4213072
4  1 4 0.5  1.4134171 -0.4540244$`2`
  id o   r  v  s
5  2 1 0.5  0.2771839  1.0688474
6  2 3 0.5 -0.7543462 -1.0371494
7  2 4 0.5 -1.9810018 -0.6742232

  Date: Thu, 3 Nov 2011 08:54:52 -0700
 From: de...@wisc.edu
 To: r-help@r-project.org
 Subject: [R] Take variables in data.frame and create list of matrices
 
 Hi,
 
 I have this sample data below and would like to create a list of matricies.
 
 setseed(1254)
 id - c(1,1,1,1 ,2,2,2)
 o - as.factor(c(1:4, 1, 3, 4))
 r - rep(.5, 7)
 v - rnorm(7)
 s - rnorm(7)
 
 dat -data.frame(id, o, r, v, s)
 dat
 
 # dat
 # id o   r  v  s
 # 1  1 0.5  0.7024631  2.0813672
 # 1  2 0.5 -0.5541955  0.1095156
 # 1  3 0.5 -1.0418167  0.4164930
 # 1  4 0.5  1.9973868 -2.0402058
 # 2  1 0.5  1.3957243 -0.2548652
 # 2  3 0.5 -0.6571325  0.6946570
 # 2  4 0.5  1.3998202  0.4601017
 
 Is there an easy way (or convenient function) to convert this into a list
 where each unique 'id' has
 its own 4x4 matrix (based on the maximum number of factor levels in 'o')in
 the list?
 Each matrix would have v in the diagonal and r*s*s in the off-diagonal
 (e.g.,
 .5*2.0814*.1095 = 0.1139), where
 r is constant (.5) and s varies based on the wthin 'id' factor level of
 'o'.
 The output would look something like this (except values in all cells):
 
 [[id 1]]
 
  'o'-levels  [,1][,2]   [,3]  [,4]
 
  [1,]  .702  .1139 r*s1*s3  ...
 
  [2,]  .1139 .702  r*s2*s3  ...
 
  [3,]  r*s3*s1.... 702
 
  [4,] .702
 
 
 [[id 2]]
 
  'o'-levels  [,1]  [,2]   [,3]   [,4]
 
  [1,]  .702   NA  r*s1*s3  ...
 
  [2,]  NA   .702  NA ...
 
  [3,]  r*s3*s1   NA  .702
 
  [4,]   ....702
 
 
 any assistance is much appreciated.
 
 Thank you,
 
 AC
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
  
[[alternative HTML version deleted]]

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


[R] query about counting rows of a dataframe

2011-11-03 Thread Stefano Sofia
Dear R users,
I have got the following data frame, called my_df:

   gender day_birth month_birth year_birth labour
1   F 22  10   2001  1
2   M29  10   2001  2
3   M  1   11  2001  1
4   F   3  11   2001  1
5   M  3  11   2001  2
6   F  4   11   2001  1
7   F  4   11   2001  2
8   F  5   12   2001  2
9   M   22   14   2001  2
10 F   29   13   2001  2
...

I need to count data in different ways:

1. count the births for each day (having 0 when necessary) independently from 
the value of the labour column

2. count the births for each day (having 0 when necessary), divided by the 
value of labour (which can have two valuers, 1 or 2)

3. count the births for each day of all the years (i.e. the 22nd of October of 
all the years present in the data frame) independently from the value of 
labour

4. count the births for each day of all the years (i.e. the 22nd of October of 
all the years present in the data frame), divided by the value of labour

I tried with the command

table(my_df$year_birth, my_df$month_birth, my_df$day_birth)

which satisfies (partially) question numer 1 (I am not able to have 0 in the 
not available days).

Is there a smart way to do that without invoking too many loops?

thank you for your help
Stefano Sofia


AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
alla ricezione. I messaggi di posta elettronica per i client di Regione Marche 
possono contenere informazioni confidenziali e con privilegi legali. Se non si 
è il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al 
mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi 
dell’art. 6 della  DGR n. 1394/2008 si segnala che, in caso di necessità ed 
urgenza, la risposta al presente messaggio di posta elettronica può essere 
visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by 
persons entitled to receive the confidential information it may contain. E-mail 
messages to clients of Regione Marche may contain information that is 
confidential and legally privileged. Please do not read, copy, forward, or 
store this message unless you are an intended recipient of it. If you have 
received this message in error, please forward it to the sender and delete it 
completely from your computer system.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 plots and missing x-axis labels on second page

2011-11-03 Thread Bert Gunter
A follow-up to my reply below.

My explanation below is correct AFAICS, but my proposed remedy using
alternating is not. Instead(again, AFAICS), one must use even finer
control with the at and labels components of scales.This worked for
me.

-- Bert

On Thu, Nov 3, 2011 at 6:40 AM, Bert Gunter bgun...@gene.com wrote:

 I believe that the explanation is:

 Axes, including tick labels, appear only on the edges of the trellis
 array, which in your case would be at the bottom of the 4th row. However,
 on the second page there is no 4th row, and lattice is not smart enough to
 put them instead at the bottom of the second.

 See the scales argument of xyplot, especially the alternating
 component, for how you can gain finer control to deal with your situation.

 Note: I would appreciate correction if I'm wrong about this.

 -- Bert

 On Wed, Nov 2, 2011 at 5:23 PM, Evans, David G (DFG) 
 david.ev...@alaska.gov wrote:

 using




 --

 Bert Gunter
 Genentech Nonclinical Biostatistics

 Internal Contact Info:
 Phone: 467-7374
 Website:

 http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm





-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

[[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] variable transformation for lm

2011-11-03 Thread Bert Gunter
See the acepack package or the transace function in Hmisc for ACE or AVAS.

-- Bert

On Thu, Nov 3, 2011 at 8:55 AM, Johannes Radinger jradin...@gmx.at wrote:

 Hello,

 I am doing a simple regression using lm(Y~X).
 As my response and my predictor seemed to be skewed
 and I can't meet the model assumptions. Therefore
 I need to transform my variables.

 I wanted to ask what is the preferred way to find out
 if predictor and/or response needs to be transformed
 and if yes how (log-transform?).

 I found a procedure in A modern approach to Regressoin
 in R (Sheather, 2009): There they suggest an approach
 with the function bctrans from alr3...but it seems that it
 is deprecated. So what is the best way (box-cox test) find the best
 transformation for predictor and response simultaneously?
 AFAIK boxcox from MASS is used only used for transformation
 of the predictor?

 Thank you very much
 Johannes

 --

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




-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

[[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] Take variables in data.frame and create list of matrices

2011-11-03 Thread AC Del Re
Thats a good start but I am looking for more. Specifically (from previous
post):

 4x4 matrix (based on the maximum number of factor levels in 'o') for each
'id' as a list.
Each matrix would have v in the diagonal and r*s*s in the off-diagonal
(e.g.,
.5*2.0814*.1095 = 0.1139), where
r is constant (.5) and s varies based on the wthin 'id' factor level of
'o'.
The output would look something like this (except values in all cells):

[[id 1]]

 'o'-levels  [,1][,2]   [,3]  [,4]

 [1,]  .702  .1139 r*s1*s3  ...

 [2,]  .1139 .702  r*s2*s3  ...

 [3,]  r*s3*s1.... 702

 [4,] .702


[[id 2]]

 'o'-levels  [,1]  [,2]   [,3]   [,4]

 [1,]  .702   NA  r*s1*s3  ...

 [2,]  NA   .702  NA ...

 [3,]  r*s3*s1   NA  .702

 [4,]   ....702


Thanks,

AC

On Thu, Nov 3, 2011 at 9:25 AM, jose Bartolomei surfpr...@hotmail.comwrote:


 I missed; using the Hadley Wickham plyr package

 library (plyr)
  dlply(dat, .(id))
 $`1`

   id o   r  v  s
 1  1 1 0.5 -1.7131858 -2.0548666
 2  1 2 0.5  0.6582979  0.9688939
 3  1 3 0.5 -0.6861830  2.4213072
 4  1 4 0.5  1.4134171 -0.4540244
 $`2`
   id o   r  v  s
 5  2 1 0.5  0.2771839  1.0688474
 6  2 3 0.5 -0.7543462 -1.0371494
 7  2 4 0.5 -1.9810018 -0.6742232


  Date: Thu, 3 Nov 2011 08:54:52 -0700
  From: de...@wisc.edu
  To: r-help@r-project.org
  Subject: [R] Take variables in data.frame and create list of matrices
 
  Hi,
 
  I have this sample data below and would like to create a list of
 matricies.
 
  setseed(1254)
  id - c(1,1,1,1 ,2,2,2)
  o - as.factor(c(1:4, 1, 3, 4))
  r - rep(.5, 7)
  v - rnorm(7)
  s - rnorm(7)
 
  dat -data.frame(id, o, r, v, s)
  dat
 
  # dat
  # id o r v s
  # 1 1 0.5 0.7024631 2.0813672
  # 1 2 0.5 -0.5541955 0.1095156
  # 1 3 0.5 -1.0418167 0.4164930
  # 1 4 0.5 1.9973868 -2.0402058
  # 2 1 0.5 1.3957243 -0.2548652
  # 2 3 0.5 -0.6571325 0.6946570
  # 2 4 0.5 1.3998202 0.4601017
 
  Is there an easy way (or convenient function) to convert this into a list
  where each unique 'id' has
  its own 4x4 matrix (based on the maximum number of factor levels in
 'o')in
  the list?
  Each matrix would have v in the diagonal and r*s*s in the off-diagonal
  (e.g.,
  .5*2.0814*.1095 = 0.1139), where
  r is constant (.5) and s varies based on the wthin 'id' factor level of
  'o'.
  The output would look something like this (except values in all cells):
 
  [[id 1]]
 
  'o'-levels [,1] [,2] [,3] [,4]
 
  [1,] .702 .1139 r*s1*s3 ...
 
  [2,] .1139 .702 r*s2*s3 ...
 
  [3,] r*s3*s1 ... . 702
 
  [4,] .702
 
 
  [[id 2]]
 
  'o'-levels [,1] [,2] [,3] [,4]
 
  [1,] .702 NA r*s1*s3 ...
 
  [2,] NA .702 NA ...
 
  [3,] r*s3*s1 NA .702
 
  [4,] ... .702
 
 
  any assistance is much appreciated.
 
  Thank you,
 
  AC
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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


Re: [R] variable transformation for lm

2011-11-03 Thread David Winsemius


On Nov 3, 2011, at 11:55 AM, Johannes Radinger jradin...@gmx.at wrote:

 Hello,
 
 I am doing a simple regression using lm(Y~X).
 As my response and my predictor seemed to be skewed
 and I can't meet the model assumptions. Therefore
 I need to transform my variables.

The presence of skewness in either or both the response or predictors does NOT 
imply failure to meet model assumptions. The assumptions of linear regression 
regarding normality only apply to the residuals after the estimation of the 
model.

-- 
David.
 
 I wanted to ask what is the preferred way to find out
 if predictor and/or response needs to be transformed
 and if yes how (log-transform?).
 
 I found a procedure in A modern approach to Regressoin
 in R (Sheather, 2009): There they suggest an approach
 with the function bctrans from alr3...but it seems that it
 is deprecated. So what is the best way (box-cox test) find the best
 transformation for predictor and response simultaneously?
 AFAIK boxcox from MASS is used only used for transformation
 of the predictor?
 
 Thank you very much
 Johannes
 
 --
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] optimising a loop

2011-11-03 Thread Bastien.Ferland-Raymond
Dear R community,

I'm trying to remove a loop from my code but I'm stock and I can't find a good 
way to do it.  Hopefully one of you will have something clever to propose.

Here is a simplified example:

I have a squared matrix:

 nom.plac2 - c(102, 103, 301, 303,304, 403)
 poids2 - matrix(NA, 6,6, dimnames=list(nom.plac2,nom.plac2))
 poids2
102 103 301 303 304 403
102  NA  NA  NA  NA  NA  NA
103  NA  NA  NA  NA  NA  NA
301  NA  NA  NA  NA  NA  NA
303  NA  NA  NA  NA  NA  NA
304  NA  NA  NA  NA  NA  NA
403  NA  NA  NA  NA  NA  NA

I want to replace some of the NAs following specific criterion included in 2 
others matrix:

 wei2 - 
 matrix(c(.6,.4,.5,.5,.9,.1,.8,.2,.7,.3,.6,.4),6,2,dimnames=list(nom.plac2, 
 c(p1,p2)),byrow=T)
 wei2
 p1  p2
102 0.6 0.4
103 0.5 0.5
301 0.9 0.1
303 0.8 0.2
304 0.7 0.3
403 0.6 0.4
 voisin - matrix(c(103,304, 303, 102, 103 
 ,303,403,304,303,102,103 ,303),
  6,2,dimnames=list(nom.plac2, c(v1,v2)),byrow=T)
 voisin
v1v2
102 103 304
103 303 102
301 103 303
303 403 304
304 303 102
403 103 303

So my final result is:

102 103 301 303 304 403
102  NA 0.6  NA  NA 0.4  NA
103 0.5  NA  NA 0.5  NA  NA
301  NA 0.9  NA 0.1  NA  NA
303  NA  NA  NA  NA 0.2 0.8
304 0.3  NA  NA 0.7  NA  NA
403  NA 0.6  NA 0.4  NA  NA


So, globally I want to fill for each line of poids2 data from wei2 
associated with the good the good identifier found in voisin.

This can easily be done by a loop:

 loop - poids2
 for(i in 1:6){
+ loop[i,voisin[i,]] - wei2[i,]
+ }

But I expect it to be quite slow with my larger dataset.

Does any of you has an idea how I could remove the loop and speed up the 
operation?

Best regards,


Bastien Ferland-Raymond, M.Sc. Stat., M.Sc. Biol.
Division des orientations et projets spéciaux
Direction des inventaires forestiers
Ministère des Ressources naturelles et de la Faune du Québec

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

2011-11-03 Thread Ben quant
Hello,

Could someone who has experience with or knowledge regarding both
RPostgreSQL and RpgSQL packages provide some feedback? Thanks! I am most
interested in hearing from people who have knowledge regarding both
packages, not just one.

The only real difference I can see is that RpgSQL has a Java dependency,
which I am not apposed to if it provides some added benefit...otherwise I
will probably use the RPostgreSQL package. Both packages look to be
maintained still.

I have skimmed over both of these links:
http://cran.r-project.org/web/packages/RpgSQL/RpgSQL.pdf
http://cran.r-project.org/web/packages/RPostgreSQL/RPostgreSQL.pdf

Thanks,

Ben

[[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] does there any function like sumif in excel?

2011-11-03 Thread Celine
Sorry for the duplicates message and thanks for your help, it works well now.

Céline

--
View this message in context: 
http://r.789695.n4.nabble.com/does-there-any-function-like-sumif-in-excel-tp858444p3984899.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] How to interpret vglm output!!

2011-11-03 Thread Akram Khaleghei Ghosheh balagh
Hello ,
I need to estimate the parameters of generalized poisson regression model.
I found that I could use :
vglm(formula, family,.., data), but I dont know how to interpret the
output!!!

  min  1Q Median 3Q Max
elogit (lambda)-.66   -.61-.46 -.06 35.33
log(theta) -10.2-.02 .11  .64   1.2

coefficients: value stdt.value
intercept:1  .76 .019   39.32
intercept:2   1.02   .0239.88
sex .55 1.216.00
log-likelihood -990.83,


I dont know what is the exactly meaning of these two intercept?
Thanks in advance for your help.
Akram

[[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] Sum with condition

2011-11-03 Thread Celine
Problem solved, thanks everyone for your help.

Céline


--
View this message in context: 
http://r.789695.n4.nabble.com/Sum-with-condition-tp3972839p3984909.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Extract Data from Yahoo Finance

2011-11-03 Thread Deb Midya
Vikram,
 
Thanks for this.
 
The field names we put like this:
quote = c(Open, High, Low, Close)
 
But in order to download all the fields, what are the names I need to use in 
the object quote. 
In Yahho Finance these are special tags.
 
The special tags are:
a=Ask, b= Bid, ..., v= Volume, W= 52-week Range, x= Stock EXchange
 
quote= c(Open, High, Low, Close, Ask, Bid, , W, x). What 
are the names I can use to download Ask, Bid, ..., Stock Exchange?
 
Once again, thank you very much for the time you have given.
 
Regards,
 
Deb
 


From: Vikram Bahure economics.vik...@gmail.com

Sent: Thursday, 3 November 2011 7:15 PM
Subject: Re: [R] Extract Data from Yahoo Finance


Hi, 

You can install the following library:
library(tseries)

and use the following command:
?get.hist.quote

Regards
Vikram




Hi R –users,
 
I am using R-2.14.0 on Windows XP.
 
May I request you to assist me for the following please.
 
I like to extract all the fields (example: a : Ask, b : Bid, ……, w : 
52-week Range, x: Stock Exchange)  for certain period of time, say, 1 October 
2011 to 31 October 2011.
 
Is there any R-Package(s)  any R- script please?
 
Once again, thank you very much for the time you have given.
 
Regards,
 
Deb

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

[[alternative HTML version deleted]]

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


[R] Why can't this function be used with the 'by' command?

2011-11-03 Thread Kaiyin Zhong
Why can't this function be used with the 'by' command?

 x = array(runif(16), dim=c(8,2))
 x = data.frame(x)
 x$group = rep(c('wt', 'app'), each=4)

 shapiro.p = function(x) shapiro.test(x)[[2]]
 apply(x[,1:2], 2, shapiro.p)
   X1X2
0.4126345 0.2208781

 by(x[,1:2], x$group, shapiro.p)
Error in `[.data.frame`(x, complete.cases(x)) :
  undefined columns selected

[[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] EMD arguments default values

2011-11-03 Thread Sara
Hi,
i'm using this command line with EMD package

filename-emd(y,x,boundary=wave,plot.imf=F)

i'd like to know if this EMD uses default values for non-specified arguments. 
i'm especially interested in stoprule, max.imf, tol behavior in such 
cases.

Thanks

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


[R] data frame to workspace

2011-11-03 Thread playballa23
Is there a way to import a data frame into a workspace? I created a data
frame and from my understanding, a data frame is a type of object, and that
the workspace stores the current session's objects. Wondering why my data
frame is not showing up...

Any thoughts/suggestions?

--
View this message in context: 
http://r.789695.n4.nabble.com/data-frame-to-workspace-tp3986415p3986415.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Comparing negative binomial models

2011-11-03 Thread Davg
Hi,

I am trying to compare negative binomial models for the prediction of sports
games (I know that Poisson models would be better but I'm just trying
Negative Binomial at the moment).

But, to compare the models I need them to have the same theta value.  How
can I change the explanatory variables while maintaining the theta value?

Thanks for the help.

David 

--
View this message in context: 
http://r.789695.n4.nabble.com/Comparing-negative-binomial-models-tp3985353p3985353.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] take me off the list

2011-11-03 Thread Alan Gao
thank you. 


Alan Gao
University of Michigan '12
Statistics, B.S.
239.682.3509

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Fit continuous distribution to truncated empirical values

2011-11-03 Thread Michele Mazzucco
Hi all,

I am trying to fit a distribution to some data about survival times.
I am interested only in a specific interval, e.g., while the data lies in the 
interval (0,, 600), I want the best for the interval (0,..., 24).

I have tried both fitdistr (MASS package) and fitdist (from the fitdistrplus 
package), but I could not get them working, e.g.

fitdistr(left, weibull, upper=24)
Error in optim(x = c(529L, 528L, 527L, 526L, 525L, 524L, 523L, 522L, 521L,  : 
  L-BFGS-B needs finite values of 'fn'
In addition: Warning message:
In dweibull(x, shape, scale, log) : NaNs produced

Am I doing something wrong?


Thanks,
Michele


p.s. I have seen similar posts, e.g., 
http://tolstoy.newcastle.edu.au/R/help/05/02/11558.html, but I am not sure 
whether I can apply the same approach here.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem with merging two matrices

2011-11-03 Thread flokke
Dear Sarah, 
THanks for your answer!
Sorry that my thread is somehow not clear, that's because I am not really
experienced with R and 
dont know yet how to put thinings in words..

I am not trying to work with them differently, I am just trying to print
them as the result of a 
function. But as the result() function does allow only one argument I have
to somehow merge these 
two matrcices. I know that I could use the list() function as well but I
wanted to have some nicer output than that, that's why I created these two
matrices. 

Want I want to get in the end is that can call my function(x,y) and then you
get the print 
of the two matrices, above each other. 


--
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-merging-two-matrices-tp3983136p3986638.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Histograms in R

2011-11-03 Thread kerry1912
We have a histogram of our observed response and we want to overlay the
corresponding poisson distribution with respect to our poisson model. 


--
View this message in context: 
http://r.789695.n4.nabble.com/Histograms-in-R-tp3985397p3985397.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Back-transforming in lme

2011-11-03 Thread Allan Carson

Hello I am analysing aboveground biomass data from revegetation testplots which 
I constructed in a split-plot design using the function lme. For the 
experiment, the three factors are amelioration (2 levels), fertilizer (2 
levels) and treatment (7 levels). Each testplot (block) has a singlereplicate 
of each treatment (total of 8 testplots). The blocks were constructed of 
topsoil. Each block was divided in two subplots in which half were ameliorated 
the other half was not (amelioration - yes or no). Each subplot was divided 
again into two subplots (fertilizer - yes or no). Then for eachfertilizer 
subplot, the area was divided into 7 seeding treatments (treatments). I have 
transformed my data to meet model assumptions and simplified my model using 
stepwise elimination. Here is my minimal model: fm13- 
lme(sqrt(abovegroundbiomass.m.2)~amelioration+fertilizer+treatment,random=~1|block,
method=ML,na.action = na.omit) Here is a summary output: summary(fm13)$tTable
Value  Std.Error DF 
 t-value p-value
(Intercept) 1.6196612 0.9058574100   1.7879869  
   7.680688e-02
ameliorationyes  1.0155789 0.5970789100   1.7009125 
9.206718e-02
fertilizeryes 4.31538410.5970789100   7.2274943 
9.985161e-11
treatmentelymgla ecovar  5.01255841.1170323100   4.4873891 
1.931291e-05
treatmentelymgla local 2.76990721.1170323100   2.4797020
1.482059e-02
treatmentfestsax ecovar  0.6953266 1.1170323100   0.6224768 
5.350453e-01
treatmentlupiarc local  1.13918401.11703231001.0198309 
3.102696e-01
treatmentnativemix ecovar   2.10916831.11703231001.8881892
6.189917e-02
treatmentnativemix local  3.21031661.11703231002.8739694
4.951797e-03 I would like to obtain the back-transformed estimates but I cannot 
seem to find the a way to do this. I have a copy of Crawley (The R Book) but 
could not find instructions on how to back-transform in lme. I have also look 
for a copy of Zuur (Mixed Effects Models and Extensions in Ecology with R) but 
cannot seem to obtain a copy.  Any guidance in how to backtranform these 
estimates would be greatly appreciated. Thanks. Allan CarsonGraduate 
StudentUniversity of Northern British Columbia


 



  
[[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] Uploding package help

2011-11-03 Thread Reema Singh
Hello All

I want to upload a R package in CRAN. Kindly tell me how to upload a new
package in CRAN

REGARDS~
Reema Singh

[[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] data frame to workspace

2011-11-03 Thread Raphael Saldanha
Hi,

When you saves a workspace, all the objects created are saved inside the
workspace. When you restarts R, you are loading this workspace?

(Se quiser que eu te responda em português, me envie um e-mali direto para
saldanha.plan...@gmail.com).

On Thu, Nov 3, 2011 at 1:46 PM, playballa23 cj...@mail.usp.edu wrote:

 Is there a way to import a data frame into a workspace? I created a data
 frame and from my understanding, a data frame is a type of object, and that
 the workspace stores the current session's objects. Wondering why my data
 frame is not showing up...

 Any thoughts/suggestions?

 --
 View this message in context:
 http://r.789695.n4.nabble.com/data-frame-to-workspace-tp3986415p3986415.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.




-- 
Atenciosamente,

Raphael Saldanha
saldanha.plan...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] XLConnect Error

2011-11-03 Thread dcelta
Hi,
I am having the same issue as described by the original subscriber  

can you offer any guidance on how to install Java ???  Do I need to do this
from the R command line ???

or do I need to do this outside of the application??


Thanks

Daniel

--
View this message in context: 
http://r.789695.n4.nabble.com/XLConnect-Error-tp3628528p3986491.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] optimising a loop

2011-11-03 Thread William Dunlap
Try replacing your for loop with the line
   loop[cbind(as.vector(row(voisin)), match(voisin, nom.plac2))] - 
as.vector(wei2)

Look help(Subscript) to see how subscripting an n-way array by
an n-column integer matrix works.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Bastien.Ferland-
 raym...@mrnf.gouv.qc.ca
 Sent: Thursday, November 03, 2011 10:25 AM
 To: r-help@r-project.org
 Subject: [R] optimising a loop
 
 Dear R community,
 
 I'm trying to remove a loop from my code but I'm stock and I can't find a 
 good way to do it.
 Hopefully one of you will have something clever to propose.
 
 Here is a simplified example:
 
 I have a squared matrix:
 
  nom.plac2 - c(102, 103, 301, 303,304, 403)
  poids2 - matrix(NA, 6,6, dimnames=list(nom.plac2,nom.plac2))
  poids2
 102 103 301 303 304 403
 102  NA  NA  NA  NA  NA  NA
 103  NA  NA  NA  NA  NA  NA
 301  NA  NA  NA  NA  NA  NA
 303  NA  NA  NA  NA  NA  NA
 304  NA  NA  NA  NA  NA  NA
 403  NA  NA  NA  NA  NA  NA
 
 I want to replace some of the NAs following specific criterion included in 2 
 others matrix:
 
  wei2 - 
  matrix(c(.6,.4,.5,.5,.9,.1,.8,.2,.7,.3,.6,.4),6,2,dimnames=list(nom.plac2,
 c(p1,p2)),byrow=T)
  wei2
  p1  p2
 102 0.6 0.4
 103 0.5 0.5
 301 0.9 0.1
 303 0.8 0.2
 304 0.7 0.3
 403 0.6 0.4
  voisin - matrix(c(103,304, 303, 102, 103 
  ,303,403,304,303,102,103 ,303),
   6,2,dimnames=list(nom.plac2, c(v1,v2)),byrow=T)
  voisin
 v1v2
 102 103 304
 103 303 102
 301 103 303
 303 403 304
 304 303 102
 403 103 303
 
 So my final result is:
 
 102 103 301 303 304 403
 102  NA 0.6  NA  NA 0.4  NA
 103 0.5  NA  NA 0.5  NA  NA
 301  NA 0.9  NA 0.1  NA  NA
 303  NA  NA  NA  NA 0.2 0.8
 304 0.3  NA  NA 0.7  NA  NA
 403  NA 0.6  NA 0.4  NA  NA
 
 
 So, globally I want to fill for each line of poids2 data from wei2 
 associated with the good the
 good identifier found in voisin.
 
 This can easily be done by a loop:
 
  loop - poids2
  for(i in 1:6){
 + loop[i,voisin[i,]] - wei2[i,]
 + }
 
 But I expect it to be quite slow with my larger dataset.
 
 Does any of you has an idea how I could remove the loop and speed up the 
 operation?
 
 Best regards,
 
 
 Bastien Ferland-Raymond, M.Sc. Stat., M.Sc. Biol.
 Division des orientations et projets spéciaux
 Direction des inventaires forestiers
 Ministère des Ressources naturelles et de la Faune du Québec
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] L1 penalization for proportional odds logistic regression

2011-11-03 Thread blackscorpio
Dear community,
I am currently attempting to perform a (L1) penalized ordinal logistic
regression with proportional odds. For the moment I only found R packages
allowing to perform forward or backward continuation ratio model with
several penalizations.
Does anyone have a clue of what R package I could use ? I am not even quite
sure that penalized logistic regression with proportional odds has already
been developed theoretically...
Thanks a lot for your help !

--
View this message in context: 
http://r.789695.n4.nabble.com/L1-penalization-for-proportional-odds-logistic-regression-tp3986573p3986573.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] Uploding package help

2011-11-03 Thread Prof Brian Ripley

See 'Writing R Extensions',
http://cran.r-project.org/doc/manuals/R-exts.html#Submitting-a-package-to-CRAN

However, you can only submit a package: other people actually upload 
it to CRAN, if they accept it.


On Thu, 3 Nov 2011, Reema Singh wrote:


Hello All

I want to upload a R package in CRAN. Kindly tell me how to upload a new
package in CRAN

REGARDS~
Reema Singh

[[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,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [R] Creating barplot using time as X

2011-11-03 Thread PEL
Thank you very much. This is exactly what I needed.

Problem solved!

Thanks again
PEL

--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-barplot-using-time-as-X-tp3981961p3986882.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] take me off the list

2011-11-03 Thread Rich Shepard

On Thu, 3 Nov 2011, Alan Gao wrote:

Alan,

  This is a self-service mail list; no maids to do the work for you. Go to
the Web site http://www.r-project.org/, navigate to the mail list page,
and unsubscribe yourself.

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] optimising a loop

2011-11-03 Thread jim holtman
try this:

 nom.plac2 - c(102, 103, 301, 303,304, 403)
 poids2 - matrix(NA, 6,6, dimnames=list(nom.plac2,nom.plac2))
 poids2
102 103 301 303 304 403
102  NA  NA  NA  NA  NA  NA
103  NA  NA  NA  NA  NA  NA
301  NA  NA  NA  NA  NA  NA
303  NA  NA  NA  NA  NA  NA
304  NA  NA  NA  NA  NA  NA
403  NA  NA  NA  NA  NA  NA
 wei2 - 
 matrix(c(.6,.4,.5,.5,.9,.1,.8,.2,.7,.3,.6,.4),6,2,dimnames=list(nom.plac2, 
 c(p1,p2)),byrow=T)
 voisin - matrix(c(103,304, 303, 102, 103 
 ,303,403,304,303,102,103 ,303),
+  6,2,dimnames=list(nom.plac2, c(v1,v2)),byrow=T)

 # do matrix addressing by converting names to numbers
 indx - rbind(
+ cbind(match(rownames(voisin), rownames(poids2))
+, match(voisin[, 1], colnames(poids2))
+)
+   , cbind(match(rownames(voisin), rownames(poids2))
+, match(voisin[, 2], colnames(poids2))
+)
+   )
 indx
  [,1] [,2]
 [1,]12
 [2,]24
 [3,]32
 [4,]46
 [5,]54
 [6,]62
 [7,]15
 [8,]21
 [9,]34
[10,]45
[11,]51
[12,]64

 # change the data
 poids2[indx] - c(wei2[,1], wei2[,2])
 poids2
102 103 301 303 304 403
102  NA 0.6  NA  NA 0.4  NA
103 0.5  NA  NA 0.5  NA  NA
301  NA 0.9  NA 0.1  NA  NA
303  NA  NA  NA  NA 0.2 0.8
304 0.3  NA  NA 0.7  NA  NA
403  NA 0.6  NA 0.4  NA  NA




On Thu, Nov 3, 2011 at 1:25 PM,
bastien.ferland-raym...@mrnf.gouv.qc.ca wrote:
 Dear R community,

 I'm trying to remove a loop from my code but I'm stock and I can't find a 
 good way to do it.  Hopefully one of you will have something clever to 
 propose.

 Here is a simplified example:

 I have a squared matrix:

 nom.plac2 - c(102, 103, 301, 303,304, 403)
 poids2 - matrix(NA, 6,6, dimnames=list(nom.plac2,nom.plac2))
 poids2
    102 103 301 303 304 403
 102  NA  NA  NA  NA  NA  NA
 103  NA  NA  NA  NA  NA  NA
 301  NA  NA  NA  NA  NA  NA
 303  NA  NA  NA  NA  NA  NA
 304  NA  NA  NA  NA  NA  NA
 403  NA  NA  NA  NA  NA  NA

 I want to replace some of the NAs following specific criterion included in 2 
 others matrix:

 wei2 - 
 matrix(c(.6,.4,.5,.5,.9,.1,.8,.2,.7,.3,.6,.4),6,2,dimnames=list(nom.plac2, 
 c(p1,p2)),byrow=T)
 wei2
     p1  p2
 102 0.6 0.4
 103 0.5 0.5
 301 0.9 0.1
 303 0.8 0.2
 304 0.7 0.3
 403 0.6 0.4
 voisin - matrix(c(103,304, 303, 102, 103 
 ,303,403,304,303,102,103 ,303),
          6,2,dimnames=list(nom.plac2, c(v1,v2)),byrow=T)
 voisin
    v1    v2
 102 103 304
 103 303 102
 301 103 303
 303 403 304
 304 303 102
 403 103 303

 So my final result is:

    102 103 301 303 304 403
 102  NA 0.6  NA  NA 0.4  NA
 103 0.5  NA  NA 0.5  NA  NA
 301  NA 0.9  NA 0.1  NA  NA
 303  NA  NA  NA  NA 0.2 0.8
 304 0.3  NA  NA 0.7  NA  NA
 403  NA 0.6  NA 0.4  NA  NA


 So, globally I want to fill for each line of poids2 data from wei2 
 associated with the good the good identifier found in voisin.

 This can easily be done by a loop:

 loop - poids2
 for(i in 1:6){
 + loop[i,voisin[i,]] - wei2[i,]
 + }

 But I expect it to be quite slow with my larger dataset.

 Does any of you has an idea how I could remove the loop and speed up the 
 operation?

 Best regards,


 Bastien Ferland-Raymond, M.Sc. Stat., M.Sc. Biol.
 Division des orientations et projets spéciaux
 Direction des inventaires forestiers
 Ministère des Ressources naturelles et de la Faune du Québec

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




-- 
Jim Holtman
Data Munger Guru

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

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


Re: [R] EMD arguments default values

2011-11-03 Thread Raphael Saldanha
The help shows:

emd(xt, tt=NULL, tol=sd(xt)*0.1^2, max.sift=20, stoprule=type1,
boundary=periodic, smlevels=c(1), sm=none, spar=NA, weight=20,
check=FALSE, max.imf=10, plot.imf=TRUE, interm=NULL)

You can use ?emd to show the help and see the defaults.

On Thu, Nov 3, 2011 at 9:13 AM, Sara sarah_...@yahoo.it wrote:

 Hi,
 i'm using this command line with EMD package

 filename-emd(y,x,boundary=wave,plot.imf=F)

 i'd like to know if this EMD uses default values for non-specified
 arguments. i'm especially interested in stoprule, max.imf, tol
 behavior in such cases.

 Thanks

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




-- 
Atenciosamente,

Raphael Saldanha
saldanha.plan...@gmail.com

[[alternative HTML version deleted]]

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


[R] any updates w.r.t. lapply, sapply, apply retaining classes

2011-11-03 Thread Mike Williamson
Hi All,

I don't have a I need help question, so much as a query into any
update whether 'R' has made any progress with some of the core functions
retaining classes.  As an example, because it's one of the cases that most
egregiously impacts me  my work and keeps pushing me away from 'R' and
into other numerical languages (such as NumPy in python), I will use sapply
/ lapply to demonstrate, but this behavior is ubiquitous throughout 'R'.

Let's say I have a class which is theoretically supported, but not one
of the core numeric or character classes (and, to some degree, factor
classes).  Many of the basic functions will convert my desired class into
either numeric or character, so that my returned answer is gibberish.

E.g.:

test= as.difftime(c(1, 1, 8, 0.25, 8, 1.25), units= days)  ## create a
small array of time differences
class(test)  ## this will return the proper class, difftime
class(test[1] ) ## this will also return the proper class, difftime
sapply(test, class)  ## this will return *numerics* for all of the classes.
 Ack!!

In the example I give above, the impact might seem small, but the
implications are *huge*.  This means that I am, in effect, not allowed to
use *any* of the vectoring functions in 'R', which avoid performing loops
thereby speeding up process time extraordinarily.  Many can sympathize that
'R' is ridiculously slow with for loops, compared to other languages.
 But that's theoretically OK, a good statistician or data analyst should be
able to work comfortably with matrices and vectors.  However, *'R' cannot
work comfortably* with matrices or vectors, *unless* they are using the
numeric or character classes.  Many of the classes suffer the problem I
just described, although I only used difftime in the example.  Factors
seem a bit more comfortable, and can be handled most of the time, but not
as well as numerics, and at times functions working on factors can return
the numerical representation of the factor instead of the original factor.

Is there any progress in guaranteeing that all core functions either
(a) ideally return exactly the classes, and hierarchy of classes, that they
received (e.g., a list of data frames with difftimes  dates  characters
would return a list of data frames with difftimes  dates  characters), or
(b) barring that, the function should at least error out with a clear error
explaining that sapply, for example, cannot vectorize on the class being
used?  Returning incorrect answers is far worse than returning an error,
from a perspective of stability.

This is, by far, the largest Achilles' heel to 'R'.  Personally, as my
career advances and I work on more technical things, I am finding that I
have to leave 'R' by the wayside and use other languages for robust
numerical calculations and programming.  This saddens me, because there are
so many wonderful packages developed by the community.  The example above
came up because I am using the forecast library to great effect in
predicting how long our product cycle time will be.  However, I spend much
of my time fighting all these class  typing bugs in 'R' (and we have to
start recognizing that they are bugs, otherwise they may never get
resolved), such that many of the improvements in my productivity due to all
the wonderful computational packages are entirely offset by the time
I spend fighting this issue of poor classes.

 Thanks  Regards!
  Mike

---
XKCD http://www.xkcd.com

[[alternative HTML version deleted]]

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


[R] Create design matrix

2011-11-03 Thread Bond, Stephen
Greetings useRs,

What is the easiest way to create a design matrix of several factor variables? 
Function gendata in Design seems to do that for a fitted model, but how to do 
that only on several factor vectors??

The result should be a df with one row for each distinct combination of levels 
of factors eg for (M,F) (Y,O)
We get
M Y
M O
F Y
F O

In reality I will have more than 1000 rows so doing by hand not good.
Maybe there is a way with outer, but I couldn't see it.
All the best to everybody.

Stephen 

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


Re: [R] problem with merging two matrices

2011-11-03 Thread Sarah Goslee
Hi,

On Thu, Nov 3, 2011 at 12:31 PM, flokke flo...@live.de wrote:
 Dear Sarah,
 THanks for your answer!
 Sorry that my thread is somehow not clear, that's because I am not really
 experienced with R and
 dont know yet how to put thinings in words..

 I am not trying to work with them differently, I am just trying to print
 them as the result of a
 function. But as the result() function does allow only one argument I have
 to somehow merge these
 two matrcices. I know that I could use the list() function as well but I
 wanted to have some nicer output than that, that's why I created these two
 matrices.

 Want I want to get in the end is that can call my function(x,y) and then you
 get the print
 of the two matrices, above each other.

See, that would have been useful to know.

If you wish to return two such matrices, you need to use a list.

If you are determined that they appear in a particular way, you could
also print them from within the function, so that particular things
appear onscreen regardless of the way in which the results are
returned.

But, in that case, you may be better off reconsidering what your
actual objectives are, and whether separating form and function might
not be a more effective course.

Sarah

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

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


Re: [R] Create design matrix

2011-11-03 Thread Justin Haynes
?expand.grid

 expand.grid(c(M,F),c(Y,O))
  Var1 Var2
1MY
2FY
3MO
4FO



Justin

On Thu, Nov 3, 2011 at 10:56 AM, Bond, Stephen stephen.b...@cibc.com wrote:
 Greetings useRs,

 What is the easiest way to create a design matrix of several factor 
 variables? Function gendata in Design seems to do that for a fitted model, 
 but how to do that only on several factor vectors??

 The result should be a df with one row for each distinct combination of 
 levels of factors eg for (M,F) (Y,O)
 We get
 M Y
 M O
 F Y
 F O

 In reality I will have more than 1000 rows so doing by hand not good.
 Maybe there is a way with outer, but I couldn't see it.
 All the best to everybody.

 Stephen

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

2011-11-03 Thread Bert Gunter
?expand.grid   is what you're looking for, I think.
(which, I agree, is not something one could easily guess)

-- Bert

On Thu, Nov 3, 2011 at 10:56 AM, Bond, Stephen stephen.b...@cibc.comwrote:

 Greetings useRs,

 What is the easiest way to create a design matrix of several factor
 variables? Function gendata in Design seems to do that for a fitted model,
 but how to do that only on several factor vectors??

 The result should be a df with one row for each distinct combination of
 levels of factors eg for (M,F) (Y,O)
 We get
 M Y
 M O
 F Y
 F O

 In reality I will have more than 1000 rows so doing by hand not good.
 Maybe there is a way with outer, but I couldn't see it.
 All the best to everybody.

 Stephen

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




-- 

Bert Gunter
Genentech Nonclinical Biostatistics

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

[[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] For loop to cycle through datasets of differing lengths

2011-11-03 Thread Schatzi
I have encountered this problem on several occasions and am not sure how to
handle it. I use for-loops to cycle through datasets. When each dataset is
of equal length, it works fine as I can combine the datasets and have each
loop pick up a different column, but when the datasets are differing
lengths, I am struggling. Here is an example:
A-1:10
B-1:15
C-1:18

Set1-data.frame(A,runif(10))
Set2-data.frame(B,runif(15))
Set3-data.frame(C,runif(18))

for (i in 1:3){
if (i==1) Data-Set1 else if (i==2) Data-Set2 else Data-Set3
dev.new()
plot(Data[,1],Data[,2])
}


I don't always want to plot them and instead do other things, such as fit a
non-linear equation to the dataset, etc. I end up using that if statement
to cycle through the datasets and was hoping there is an easier method.
Maybe one would be to add extra zeros until they are the same length and
then take out the extra zeros in the first step. Any help would be
appreciated.

-
In theory, practice and theory are the same. In practice, they are not - Albert 
Einstein
--
View this message in context: 
http://r.789695.n4.nabble.com/For-loop-to-cycle-through-datasets-of-differing-lengths-tp3987308p3987308.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] For loop to cycle through datasets of differing lengths

2011-11-03 Thread Peter Langfelder
On Thu, Nov 3, 2011 at 11:41 AM, Schatzi adele_thomp...@cargill.com wrote:
 I have encountered this problem on several occasions and am not sure how to
 handle it. I use for-loops to cycle through datasets. When each dataset is
 of equal length, it works fine as I can combine the datasets and have each
 loop pick up a different column, but when the datasets are differing
 lengths, I am struggling. Here is an example:
 A-1:10
 B-1:15
 C-1:18

 Set1-data.frame(A,runif(10))
 Set2-data.frame(B,runif(15))
 Set3-data.frame(C,runif(18))

 for (i in 1:3){
 if (i==1) Data-Set1 else if (i==2) Data-Set2 else Data-Set3
 dev.new()
 plot(Data[,1],Data[,2])
 }


 I don't always want to plot them and instead do other things, such as fit a
 non-linear equation to the dataset, etc. I end up using that if statement
 to cycle through the datasets and was hoping there is an easier method.
 Maybe one would be to add extra zeros until they are the same length and
 then take out the extra zeros in the first step. Any help would be
 appreciated.

Well, you can start by putting your data sets in a list:

allSets = list(Set1, Set2, Set3)

then in your loop say

Data = allSets[[i]]

and you're done.

If you have an apriori unknown number of data sets, you can use get.
Before the loop you define the names,

setNames = c(Set1, Set2, Set3)

Then in the loop, you can use

Data = get(setNames[i])

But I'm not sure why this would be more useful than the list example
unless perhaps if you `load()' previously `save()'d data sets (the
load() function can give you the names of loaded variables). In any
case, if you repeat the same analysis on a number of data sets with
different dimensions, list() is IMHO the way to go.

HTH,

Peter

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


[R] Reclassify string values

2011-11-03 Thread Zev Ross

Hi All,

Is there a simple way to convert a string such as c(A, B ,C, D) 
to a string of c(Group1, Group1, Group2, Group2). Naturally I 
could use the factor function as below but I don't like seeing that 
warning message (and I don't want to turn off warning messages). Perhaps 
a function called reclassify or recategorize?


Zev

x-LETTERS[1:4]
x2-as.character(factor(x, levels=LETTERS[1:4], labels=rep(c(Group1, 
Group2), each=2)))


Warning message:
In `levels-`(`*tmp*`, value = c(Group1, Group1, Group2, Group2 :
  duplicated levels will not be allowed in factors anymore


--
Zev Ross
ZevRoss Spatial Analysis
120 N Aurora, Suite 3A
Ithaca, NY 14850
607-277-0004 (phone)
866-877-3690 (fax, toll-free)
zev at zevross.com

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


[R] Plotting skewed normal distribution with a bar plot

2011-11-03 Thread Steve_Friedman

Hi,

I need to create a plot (type = h)  and then overlay a skewed-normal
curve on this distribution, but I'm not finding a procedure to accomplish
this. I want to use the plot function here in order to control the bin
distributions.

I have explored the sn library and found the dsn function.  dsn uses known
location, scaling and shape parameters associated with a given input vector
of probabilities.  However, how can I calculate the skewed-normal curve if
I don't know these parameters in advance?

Is there another function to calculate the skew-normal, perhaps in a
different package?


I'm working with R 2.13.2 on a windows based machine.

Steve Friedman Ph. D.
Ecologist  / Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

steve_fried...@nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147

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


Re: [R] data frame to workspace

2011-11-03 Thread R. Michael Weylandt michael.weyla...@gmail.com
What did you do to create/save/load your data frame? There are n - infty ways 
to do all three of those steps and it's hard to give meaningful help without 
knowing what you tried. 

M

On Nov 3, 2011, at 11:46 AM, playballa23 cj...@mail.usp.edu wrote:

 Is there a way to import a data frame into a workspace? I created a data
 frame and from my understanding, a data frame is a type of object, and that
 the workspace stores the current session's objects. Wondering why my data
 frame is not showing up...
 
 Any thoughts/suggestions?
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/data-frame-to-workspace-tp3986415p3986415.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


[R] Is it possible to vectorize/accelerate this?

2011-11-03 Thread hihi
Dear Members,

I work on a simulaton experiment but it has an bottleneck. It's quite fast 
because of R and vectorizing, but it has a very slow for loop. The adjacent 
element of a vector (in terms of index number) depends conditionally on the 
former value of itself. Like a simple cumulating function (eg. cumsum) but with 
condition. Let's show me an example:
a_vec = rnorm(100)
b_vec = rep(0, 100)
b_vec[1]=a_vec[1]
for (i in 2:100){b_vec[i]=ifelse(abs(b_vec[i-1]+a_vec[i])1, a_vec[i], 
b_vec[i-1]+a_vec[i])}
print(b_vec)

(The behaviour is like cumsum's, but when the value would excess 1.0 then it 
has another value from a_vec.)
Is it possible to make this faster? I experienced that my way is even slower 
than in Excel! Programming in C would my last try...
Any suggestions?

Than you,
Peter

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


Re: [R] Reclassify string values

2011-11-03 Thread Peter Langfelder
On Thu, Nov 3, 2011 at 11:59 AM, Zev Ross z...@zevross.com wrote:
 Hi All,

 Is there a simple way to convert a string such as c(A, B ,C, D) to a
 string of c(Group1, Group1, Group2, Group2). Naturally I could use
 the factor function as below but I don't like seeing that warning message
 (and I don't want to turn off warning messages). Perhaps a function called
 reclassify or recategorize?

 Zev

 x-LETTERS[1:4]
 x2-as.character(factor(x, levels=LETTERS[1:4], labels=rep(c(Group1,
 Group2), each=2)))

 Warning message:
 In `levels-`(`*tmp*`, value = c(Group1, Group1, Group2, Group2 :
  duplicated levels will not be allowed in factors anymore

If you want to translate, why not first build a translation table

tt = cbind(LETTERS[1:4], c(group1, group1, group2, group2))

then apply it on an example:

xx = sample(LETTERS[1:4], 20, replace = TRUE)

translation = tt[ match(xx, tt[, 1]), 2]

 translation
 [1] group2 group2 group2 group2 group2 group1 group2 group1
 [9] group2 group1 group1 group2 group2 group2 group1 group2
[17] group2 group1 group1 group2

Or did I misunderstand your intent?

Peter

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


[R] [R-pkgs] new version of FRAILTYPACK: general frailty models

2011-11-03 Thread Rondeau Virginie

Dear R users,

We are pleased to tell you that FRAILTYPACK has been updated.

FRAILTYPACK stands now for general frailty models estimated with a 
semi-parametrical penalized likelihood,

but also with a parametrical approach.

In case of comments/corrections/remarks/suggestions -- which are very 
welcome --please contact the maintainer directly.


Kind regards,
The FRAILTYPACK team.

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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


[R] Searching elements in list

2011-11-03 Thread mstepano
Hi all,

I have a list ov vectors of enequal lenght and need to check is the given
vector in list.

 v1-c(1,2)
 v2-c(1,2,3)
 v3-c(1,3)
 allv-list(v1,v2,v3)

 somev-c(1,2)
 somev%in%allv
[1] FALSE FALSE

Hence, %in% checks that elements of vector somev are in list. How it is
possible to check that somev is element of list? 

--
View this message in context: 
http://r.789695.n4.nabble.com/Searching-elements-in-list-tp3987066p3987066.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] Searching elements in list

2011-11-03 Thread mstepano
I forget to mention that the vectors are ordered. I think that one of the
possible solutions is to use lapply, i.e.,

 T %in% lapply(allv, function(x,y) all.equal(x,y),y=somev)
[1] TRUE


--
View this message in context: 
http://r.789695.n4.nabble.com/Searching-elements-in-list-tp3987066p3987487.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] Is it possible to vectorize/accelerate this?

2011-11-03 Thread R. Michael Weylandt michael.weyla...@gmail.com
I don't immediately see a good trick for vectorization so this seems to me to 
be a good candidate for work in a lower-level language. Staying within R, I'd 
suggest you use if and else rather than ifelse() since your computation isn't 
vectorized: this will eliminate a small amount over overhead. Since you also 
always add a_vec, you could also define b_vec as a copy of a to avoid all those 
calls to subset a, but I don't think the effects will be large and the code 
might not be as clear. 

You indicated that you may be comfortable with writing C, but I'd suggest you 
look into the Rcpp/Inline package pair which make the whole process much easier 
than it would otherwise be.

 I'm not at a computer write now or I'd write a fuller example, but the 
documentation for those packages is uncommonly good an you should be able to 
easily get it down into C++. If you aren't able to get it by tomorrow, let me 
know and I can help troubleshoot. The only things I foresee that you'll need to 
change are zero-basing, C's loop syntax, and (I think) the call to abs(). (I 
always forget where abs() lives in c++ )

The only possible hold up is that you need to be at a computer with a C compiler

Hope this helps,

Michael 

On Nov 3, 2011, at 3:10 PM, hihi v.p.m...@freemail.hu wrote:

 Dear Members,
 
 I work on a simulaton experiment but it has an bottleneck. It's quite fast 
 because of R and vectorizing, but it has a very slow for loop. The adjacent 
 element of a vector (in terms of index number) depends conditionally on the 
 former value of itself. Like a simple cumulating function (eg. cumsum) but 
 with condition. Let's show me an example:
 a_vec = rnorm(100)
 b_vec = rep(0, 100)
 b_vec[1]=a_vec[1]
 for (i in 2:100){b_vec[i]=ifelse(abs(b_vec[i-1]+a_vec[i])1, a_vec[i], 
 b_vec[i-1]+a_vec[i])}
 print(b_vec)
 
 (The behaviour is like cumsum's, but when the value would excess 1.0 then it 
 has another value from a_vec.)
 Is it possible to make this faster? I experienced that my way is even slower 
 than in Excel! Programming in C would my last try...
 Any suggestions?
 
 Than you,
 Peter
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Histograms in R

2011-11-03 Thread R. Michael Weylandt michael.weyla...@gmail.com
Try something like this

Lam - 3
X - rpois(500, Lam)
hist(X, freq = F)
x - seq(min(X), max(X), length = 500)
lines(x, dpois(x, Lam), col=2)

Adapt as necessary

Michael

On Nov 3, 2011, at 8:03 AM, kerry1912 kerry1...@hotmail.com wrote:

 We have a histogram of our observed response and we want to overlay the
 corresponding poisson distribution with respect to our poisson model. 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Histograms-in-R-tp3985397p3985397.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Comparing negative binomial models

2011-11-03 Thread Ben Bolker
Davg davidgrimsey at hotmail.com writes:

 I am trying to compare negative binomial models for the prediction of sports
 games (I know that Poisson models would be better but I'm just trying
 Negative Binomial at the moment).
 
 But, to compare the models I need them to have the same theta value.  How
 can I change the explanatory variables while maintaining the theta value?

  library(MASS)
  modelfit - glm(..., family=negative.binomial(theta=theta_value))

I believe that drop1() applied to a glm.nb() fit does this correctly
(i.e. holds the theta parameter fixed at the estimate from the most complex
model).

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 possible to vectorize/accelerate this?

2011-11-03 Thread hihi
Thank you, I will try as soon as possible...
Regards,
Peter

2011/11/3 Mark Leeds marklee...@gmail.com

 hi hihi: you're not using the ifelse construct correctly because it's
 already vectorized
 so there's no need to use a loop.

 check if below works AND if it's fast enough because I didn't check either
 one. Also,
 i bet someone else can send something better so I would wait anyway. good
 luck.

 set.seed(1)
 avec = rnorm(100)
 bvec = rep(0, 100)
 bvec[1]=avec[1]

 bveclagged - c(999,head(bvec,-1))
 bvec - ifelse((abs(bveclagged + avec)  1), avec, bveclagged + avec)





 On Thu, Nov 3, 2011 at 7:10 PM, hihi v.p.m...@freemail.hu wrote:

 Dear Members,

 I work on a simulaton experiment but it has an bottleneck. It's quite
 fast because of R and vectorizing, but it has a very slow for loop. The
 adjacent element of a vector (in terms of index number) depends
 conditionally on the former value of itself. Like a simple cumulating
 function (eg. cumsum) but with condition. Let's show me an example:
 a_vec = rnorm(100)
 b_vec = rep(0, 100)
 b_vec[1]=a_vec[1]
 for (i in 2:100){b_vec[i]=ifelse(abs(b_vec[i-1]+a_vec[i])1, a_vec[i],
 b_vec[i-1]+a_vec[i])}
 print(b_vec)

 (The behaviour is like cumsum's, but when the value would excess 1.0 then
 it has another value from a_vec.)
 Is it possible to make this faster? I experienced that my way is even
 slower than in Excel! Programming in C would my last try...
 Any suggestions?

 Than you,
 Peter

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




[[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 possible to vectorize/accelerate this?

2011-11-03 Thread Dennis Murphy
Hi:

You're doing the right thing in R by pre-allocating memory for the
result, but ifelse() is a vectorized function and your loop is
operating elementwise, so if-else is more appropriate. Try

for (i in 2:100){
b_vec[i] - if(abs(b_vec[i-1] + a_vec[i])  1) a_vec[i] else
b_vec[i-1] + a_vec[i]
  }

If speed is an issue, then I echo Michael's suggestion to write a
C(++) function and call it within R. The inline package is good for
this kind of thing.

HTH,
Dennis


On Thu, Nov 3, 2011 at 12:10 PM, hihi v.p.m...@freemail.hu wrote:
 Dear Members,

 I work on a simulaton experiment but it has an bottleneck. It's quite fast 
 because of R and vectorizing, but it has a very slow for loop. The adjacent 
 element of a vector (in terms of index number) depends conditionally on the 
 former value of itself. Like a simple cumulating function (eg. cumsum) but 
 with condition. Let's show me an example:
 a_vec = rnorm(100)
 b_vec = rep(0, 100)
 b_vec[1]=a_vec[1]
 for (i in 2:100){b_vec[i]=ifelse(abs(b_vec[i-1]+a_vec[i])1, a_vec[i], 
 b_vec[i-1]+a_vec[i])}
 print(b_vec)

 (The behaviour is like cumsum's, but when the value would excess 1.0 then it 
 has another value from a_vec.)
 Is it possible to make this faster? I experienced that my way is even slower 
 than in Excel! Programming in C would my last try...
 Any suggestions?

 Than you,
 Peter

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


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


Re: [R] Reclassify string values

2011-11-03 Thread Zev Ross

Hi Peter,

Thanks for the response. What you've suggested works fine but I'm 
looking for something that is simpler than my solution and avoids the 
pesky warning message. Your response avoids the warning message but just 
as complex (if not more). I just assumed there would be a function along 
the lines of:


 mydata - c(A, C, A, D, B, B)
 reclassify(mydata, inCategories=c(A, B ,C, D),  
outCategories=c(Group1, Group1, Group2, Group2))


[1] Group1 Group2 Group1 Group2 Group1 Group1

Zev


On 11/3/2011 3:13 PM, Peter Langfelder wrote:

On Thu, Nov 3, 2011 at 11:59 AM, Zev Rossz...@zevross.com  wrote:

Hi All,

Is there a simple way to convert a string such as c(A, B ,C, D) to a
string of c(Group1, Group1, Group2, Group2). Naturally I could use
the factor function as below but I don't like seeing that warning message
(and I don't want to turn off warning messages). Perhaps a function called
reclassify or recategorize?

Zev

x-LETTERS[1:4]
x2-as.character(factor(x, levels=LETTERS[1:4], labels=rep(c(Group1,
Group2), each=2)))

Warning message:
In `levels-`(`*tmp*`, value = c(Group1, Group1, Group2, Group2 :
  duplicated levels will not be allowed in factors anymore

If you want to translate, why not first build a translation table

tt = cbind(LETTERS[1:4], c(group1, group1, group2, group2))

then apply it on an example:

xx = sample(LETTERS[1:4], 20, replace = TRUE)

translation = tt[ match(xx, tt[, 1]), 2]


translation

  [1] group2 group2 group2 group2 group2 group1 group2 group1
  [9] group2 group1 group1 group2 group2 group2 group1 group2
[17] group2 group1 group1 group2

Or did I misunderstand your intent?

Peter



--
Zev Ross
ZevRoss Spatial Analysis
120 N Aurora, Suite 3A
Ithaca, NY 14850
607-277-0004 (phone)
866-877-3690 (fax, toll-free)
z...@zevross.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] Problem with R CMD check and the inconsolata font business.

2011-11-03 Thread Brian Diggs

On 11/3/2011 12:37 AM, Rolf Turner wrote:


I have just installed R version 2.14.0 and tried to re-build and
re-check some
of the packages that I maintain.

I'm getting a warning (in the process of running R CMD check on my deldir
package):


* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
! Font T1/fi4/m/n/10=ec-inconsolata at 10.0pt not loadable: Metric
(TFM) file n
ot found.
to be read again
relax
l.19 ...lf Turner }\email{r.tur...@auckland.ac.nz}
! \textfont 0 is undefined (character h).
\Url@FormatString ...\Url@String \UrlRight \m@th $

l.26 ...\AsIs{}\url{http://www.math.unb.ca/~rolf/}
\AsIs{}
! \textfont 0 is undefined (character t).
\Url@FormatString ...\Url@String \UrlRight \m@th $

l.26 ...\AsIs{}\url{http://www.math.unb.ca/~rolf/}
\AsIs{}
! \textfont 0 is undefined (character t).

.. etc., etc., etc., ad (almost) infinitum.

So there's some problem with a font file not being loadable.

Can anyone tell me what the expletive deleted I should ***do***
about this? I managed to install the inconsolata package from CTAN.
At least I think I managed; I downloaded the *.zip file and then unzipped
it in /usr/share/texmf/tex/latex. And ran texhash. This stopped R CMD
check from complaining that the inconsolata package could not be found,
but then led to the further complaint described above.

So how do I make the required font loadable? What files do I need?
Where do I get them? And where should I put them once I've got them?

I would be grateful for any assistance that can be rendered.

(I know it's just a warning, but I *hate* to ignore warnings!)

cheers,

Rolf Turner

P. S. I'm running Ubuntu; session info, in case it's of any relevance is:

sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: i686-pc-linux-gnu (32-bit)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] misc_0.0-15


I'm having a similar, though different, problem with inconsolata.  It 
may be the same root problem.  The error on R CMD check I get is:


* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
!pdfTeX error: pdflatex.EXE (file ec-inconsolata): Font ec-inconsolata 
at 540 n

ot found
 == Fatal error occurred, no output PDF file produced!

Now, oddly, there _is_ a -manual.pdf file in the .Rcheck directory 
(despite the message saying no PDf was produced).  If I just try to run 
the pdflatex on the -manual.tex file in that directory, I get the same 
error and no PDF (?!)


I am on Windows 7 64 bit using MiKTeX 2.9; I get the same error whether 
I use the 32 or 64 bit version of R for R CMD check.


 sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-pc-mingw32/x64 (64-bit)

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

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


Some info from my tex installation (showing I have inconsolata installed 
and that I am pulling the correct Rd.sty):


C:\kpsewhich Rd.sty
C:/Program Files/R/R-2.14.0/share/texmf/tex/latex/Rd.sty

C:\kpsewhich inconsolata.sty
C:/Program Files (x86)/MiKTeX 2.9/tex/latex/inconsolata/inconsolata.sty

C:\kpsewhich ec-inconsolata.tfm
C:/Program Files (x86)/MiKTeX 
2.9/fonts/tfm/public/inconsolata/ec-inconsolata.tfm





--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health  Science 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] Reclassify string values

2011-11-03 Thread Peter Langfelder
On Thu, Nov 3, 2011 at 1:31 PM, Zev Ross z...@zevross.com wrote:
 Hi Peter,

 Thanks for the response. What you've suggested works fine but I'm looking
 for something that is simpler than my solution and avoids the pesky warning
 message. Your response avoids the warning message but just as complex (if
 not more). I just assumed there would be a function along the lines of:

 mydata - c(A, C, A, D, B, B)
 reclassify(mydata, inCategories=c(A, B ,C, D),
  outCategories=c(Group1, Group1, Group2, Group2))

 [1] Group1 Group2 Group1 Group2 Group1 Group1


But of course, except sometimes you have to write the function yourself.

reclassify = function(data, inCategories, outCategories)
{
   outCategories[ match(data, inCategories)]
}

Sorry I can't make it any simpler than a 1-line solution :)

Feel free to add some checking of input validity, if you need that.

Peter

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


Re: [R] Searching elements in list

2011-11-03 Thread David Winsemius


On Nov 3, 2011, at 3:21 PM, mstepano wrote:

I forget to mention that the vectors are ordered. I think that one  
of the

possible solutions is to use lapply, i.e.,

 T %in% lapply(allv, function(x,y) all.equal(x,y),y=somev)
[1] TRUE


all.equal worked fine when the answer was 'true' but not so well in my  
hands when it was 'false'. Also not a good idea to replace the base  
definition of %in%.


 any( sapply( allv, identical, v1) )
[1] TRUE
 any( sapply( allv, identical, c(3,3,4)) )
[1] FALSE

`%l.in%` - function(vec,lis) any( sapply( lis, identical, vec) )

Use:
 v1 %l.in% allv
[1] TRUE

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Reclassify string values

2011-11-03 Thread David Winsemius


On Nov 3, 2011, at 4:40 PM, Peter Langfelder wrote:


On Thu, Nov 3, 2011 at 1:31 PM, Zev Ross z...@zevross.com wrote:

Hi Peter,

Thanks for the response. What you've suggested works fine but I'm  
looking
for something that is simpler than my solution and avoids the pesky  
warning
message. Your response avoids the warning message but just as  
complex (if
not more). I just assumed there would be a function along the lines  
of:



mydata - c(A, C, A, D, B, B)
reclassify(mydata, inCategories=c(A, B ,C, D),
 outCategories=c(Group1, Group1, Group2, Group2))


[1] Group1 Group2 Group1 Group2 Group1 Group1



But of course, except sometimes you have to write the function  
yourself.


reclassify = function(data, inCategories, outCategories)
{
  outCategories[ match(data, inCategories)]
}

Sorry I can't make it any simpler than a 1-line solution :)


It will be difficult to beat a oneliner like that. If Zev is still  
holding out for a canned solution he might look in the 'car'' package  
where there is at least one function that does releveling and  
grouping. I foget its name at the moment but it wouldn't hurt a new  
learneR to scroll through the entire 'car' suite of functions.


--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Kaplan Meier - not for dates

2011-11-03 Thread Polwart Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST)
Thanks for the reply.

The treatment is effectively for a chronic condition - so you stay on the 
treatment till it stops working.  We know from trials how long that should be 
and we know the theoretical cost of that treatment but that's based on the text 
book dose (patients dose reduce and delay treatment and its based on weight so 
variable).  We've been asked to provide our national planning team with an 
average cost based on our early experiences. So we have suggested to them we 
might be able to get a median cost.  Some patients will stay on treatment 
several years so it will be impossible to get an average for years.

So the censored patients will be those still on treatment (the event being 
stopping treatment)

I'll give what you've suggested a go.

Thanks


Calum Polwart BSc(Hons) MSc MRPharmS SPres IPres
Network Pharmacist - NECN and Pharmacy Clinical Team Manager (Cancer  Aseptic 
Services) - CDDFT
Our website has now been unlocked and updated.  Should you require contacts, 
meeting details, publications etc, please visit us on www.cancernorth.nhs.uk

From: Lancaster, Robert (Orbitz) [robert.lancas...@orbitz.com]
Sent: 03 November 2011 19:55
To: Polwart Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST); 
r-help@r-project.org
Subject: RE: Kaplan Meier - not for dates

I think it really depends on what your event of interest is.  If your event is 
that the patient got better and left treatment then I think this could work.  
You would have to mark as censored any patient still in treatment or any 
patient that stopped treatment w/o getting better (e.g. in the case of death).  
You would then be predicting the cost required to make the patient well enough 
to leave treatment.  It is a little non-standard to use $ instead of time, but 
time is money after all.

You could set up your data frame with two columns: 1) cost 2) event/censored.

Then create your survival object:
mySurv = Surv(my_data$cost,my_data$event)

And then use survfit to create your KM curves:
myFit = survfit(mySurv~NULL)


If you have other explanatory variables that you think may influence the cost, 
you can of course add them to your data frame and change the formula you use in 
survfit.  For instance, you could have some severity measure, e.g. High, 
Medium, Low.  You could then do:
myFit = survfit(mySurv~my_data$severity)




-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Polwart Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST)
Sent: Monday, October 31, 2011 1:29 PM
To: r-help@r-project.org
Subject: [R] Kaplan Meier - not for dates

I have some data which is censored and I want to determine the median.  Its 
actually cost data for a cohort of patients, many of whom are still on 
treatment and so are censored.

I can do the same sort of analysis for a survival curve and get the median 
survival... ...but can I just use the survival curve functions to plot an X 
axis that is $ rather than date? If not is there some other way to achieve this?

Thanks

Calum



This message may contain confidential information. If yo...{{dropped:21}}

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



This message may contain confidential information. If you are not the intended 
recipient please inform the
sender that you have received the message in error before deleting it.
Please do not disclose, copy or distribute information in this e-mail or take 
any action in reliance on its contents:
to do so is strictly prohibited and may be unlawful.

Thank you for your co-operation.

NHSmail is the secure email and directory service available for all NHS staff 
in England and Scotland
NHSmail is approved for exchanging patient data and other sensitive information 
with NHSmail and GSi recipients
NHSmail provides an email address for your career in the NHS and can be 
accessed anywhere
For more information and to find out how you can switch, visit 
www.connectingforhealth.nhs.uk/nhsmail

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


Re: [R] Problem with R CMD check and the inconsolata font business.

2011-11-03 Thread Rolf Turner

On 03/11/11 20:37, Rolf Turner wrote:


I have just installed R version 2.14.0 and tried to re-build and 
re-check some

of the packages that I maintain.

I'm getting a warning (in the process of running R CMD check on my 
deldir

package):


* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
! Font T1/fi4/m/n/10=ec-inconsolata at 10.0pt not loadable: Metric 
(TFM) file n

ot found.
to be read again


SNIP

I received two replies off-line and one that was sent to the list.  The 
gist of the
off-line replies was ``you need to install some fonts'', and (unusually, 
and very

kindly! :-) ) the responders told me *how* to do so.

The first message that I read was from John Nash who wrote:

Have you tried

sudo apt-get install texlive-fonts-extra

to get the font in? I had to do this just yesterday myself.

If that works, maybe put a note on R-help. I've not sent to R-help in case it 
doesn't
work, and we get a bunch of unnecessary noise.


Well it *did* work; thank you very much John!

A similar message from G. Jay Kerns said:

It looks like you are missing some font files.  Did you do:

apt-get install texlive-fonts-recommended ?


The third message (which *was* posted to the list) was from Brian Diggs,
who said that he was having a related problem:


The error on R CMD check I get is:

* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
!pdfTeX error: pdflatex.EXE (file ec-inconsolata): Font ec-inconsolata 
at 540 n

ot found
 == Fatal error occurred, no output PDF file produced! 


I think this is the same as/similar to the problem I had before I installed
the inconsolata (LaTeX) package from CTAN.  Since Brian does Windoze I
cannot advise as to how to install the package on his system, but I presume
it is not too difficult --- once you know how! :-)

I'm posting this so that John Nash's and Jay Kerns' solutions to my problem
are there in the archives ``for the record''.

Thanks to all who replied.

cheers,

Rolf Turner

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


Re: [R] Histograms in R

2011-11-03 Thread David L Carlson
The lines() command doesn't work and histogram combines categories unless
you specify the number. How about a barplot

Lam - 3
X - table(rpois(500, Lam))
Max - length(X)-1
barplot(rbind(X, 500*dpois(0:Max, Lam)), beside=TRUE,
legend.text=c(Observed, Expected))

or a rootogram
library(vcd)
rootogram(X, dpois(0:Max, Lam)*500)


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of R. Michael Weylandt michael.weyla...@gmail.com
Sent: Thursday, November 03, 2011 2:55 PM
To: kerry1912
Cc: r-help@r-project.org
Subject: Re: [R] Histograms in R

Try something like this

Lam - 3
X - rpois(500, Lam)
hist(X, freq = F)
x - seq(min(X), max(X), length = 500)
lines(x, dpois(x, Lam), col=2)

Adapt as necessary

Michael

On Nov 3, 2011, at 8:03 AM, kerry1912 kerry1...@hotmail.com wrote:

 We have a histogram of our observed response and we want to overlay the
 corresponding poisson distribution with respect to our poisson model. 
 
 
 --
 View this message in context:
http://r.789695.n4.nabble.com/Histograms-in-R-tp3985397p3985397.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 possible to vectorize/accelerate this?

2011-11-03 Thread R. Michael Weylandt
Yes -- if  else is much faster than ifelse() because if is a
primitive while ifelse() is a whole function call (in fact, you can
see the code by typing ifelse into the prompt and see that it has two
if calls within it.

Michael

On Thu, Nov 3, 2011 at 4:38 PM, hihi v.p.m...@freemail.hu wrote:
 Hi,
 thank you for your very immediate response. :-) Is if than and else faster
 than ifelse? I'm wondering (or not knowing something)
 Best regards,
 Peter
 2011/11/3 R. Michael Weylandt michael.weyla...@gmail.com
 michael.weyla...@gmail.com

 I don't immediately see a good trick for vectorization so this seems to me
 to be a good candidate for work in a lower-level language. Staying within R,
 I'd suggest you use if and else rather than ifelse() since your computation
 isn't vectorized: this will eliminate a small amount over overhead. Since
 you also always add a_vec, you could also define b_vec as a copy of a to
 avoid all those calls to subset a, but I don't think the effects will be
 large and the code might not be as clear.

 You indicated that you may be comfortable with writing C, but I'd suggest
 you look into the Rcpp/Inline package pair which make the whole process much
 easier than it would otherwise be.

  I'm not at a computer write now or I'd write a fuller example, but the
 documentation for those packages is uncommonly good an you should be able to
 easily get it down into C++. If you aren't able to get it by tomorrow, let
 me know and I can help troubleshoot. The only things I foresee that you'll
 need to change are zero-basing, C's loop syntax, and (I think) the call to
 abs(). (I always forget where abs() lives in c++ )

 The only possible hold up is that you need to be at a computer with a C
 compiler

 Hope this helps,

 Michael

 On Nov 3, 2011, at 3:10 PM, hihi v.p.m...@freemail.hu wrote:

  Dear Members,
 
  I work on a simulaton experiment but it has an bottleneck. It's quite
  fast because of R and vectorizing, but it has a very slow for loop. The
  adjacent element of a vector (in terms of index number) depends
  conditionally on the former value of itself. Like a simple cumulating
  function (eg. cumsum) but with condition. Let's show me an example:
  a_vec = rnorm(100)
  b_vec = rep(0, 100)
  b_vec[1]=a_vec[1]
  for (i in 2:100){b_vec[i]=ifelse(abs(b_vec[i-1]+a_vec[i])1, a_vec[i],
  b_vec[i-1]+a_vec[i])}
  print(b_vec)
 
  (The behaviour is like cumsum's, but when the value would excess 1.0
  then it has another value from a_vec.)
  Is it possible to make this faster? I experienced that my way is even
  slower than in Excel! Programming in C would my last try...
  Any suggestions?
 
  Than you,
  Peter
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.



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


Re: [R] any updates w.r.t. lapply, sapply, apply retaining classes

2011-11-03 Thread Joshua Wiley
Hi Mike,

This isn't really an answer to your question, but perhaps will serve
to continue discussion.  I think that there are some fundamental
issues when working special classes.  As a thought example, suppose I
wrote a class, posreal, which inherits from the numeric class.  It
is only valid for positive, real numbers.  I use it in a package, but
do not develop methods for it.  A user comes along and creates a
vector, x that is a posreal.  Then tries: mean(x * -3).  Since I never
bothered to write a special method for mean for my class, R falls back
to the inherited numeric, but gives a value that is clearly not valid
for posreal.  What should happen?  S3 methods do not really have
validation, so in principle, one could write a function like:

f - function(x) {
  vclass - class(x)
  res - mean(x)
  class(res) - vclass
  return(res)
}

which retains the appropriate class, but in name only.  R core
cannot possibly know or imagine all classes that may be written that
inherit from more basic types but with possible special aspects and
requirements.  I think the inherited is considered to be more generic
and that is returned.  It is usually up to the user to ensure that the
function (whose methods were not specific to that special class but
the inherited) is valid for that class and can manually convert it
back:

res - as.posreal(res)

What about lapply and sapply?  Neither are generic or have methods for
difftime, and so do some unexpected/desirable things.  Again, without
methods defined for a particular class, they cannot know what is
special or appropriate way to handle it, they use defaults which
sometimes work but may give unexpected or undesirable results, but
what else can be done?  (okay, they could just throw an error)  If a
function is naive about a class, it does not seem right to operate on
it using unknown methods and then pretend to be returning the same
type of data.  As it stands, they convert to a data type they know and
return that.

Now, you mention that for loops are slow in R, and this is true to a
degree.  However, the *apply functions are basically just internal
loops, so they do not really save you (they are certainly not
vectorized!), though they are more elegant than explicit loops IMO.
One way to use them while retaining class would be like:

sapply(seq_along(test), function(i) class(test[i]))

this is less efficient then sapply(test, class), but the overhead
drops considerably as the function does nontrivial calculations.
Finally, I find the (relatively) new compiler package really shines at
making functions that are just wrappers for for loops more efficient.
Take a look at the examples from:

require(compiler)
?cmpfun

I am not familiar with numPy so I do not know how it handles new
classes, but with some tweaks to my workflow, I do not find myself
running into problems with how R handles them.  I definitely
appreciate your position because I have been there...as I became more
familiar with R, classes, and methods, I find I work in a way that
avoids passing objects to functions that do not know how to handle
them properly.

Cheers,

Josh


On Thu, Nov 3, 2011 at 11:08 AM, Mike Williamson this.is@gmail.com wrote:
 Hi All,

    I don't have a I need help question, so much as a query into any
 update whether 'R' has made any progress with some of the core functions
 retaining classes.  As an example, because it's one of the cases that most
 egregiously impacts me  my work and keeps pushing me away from 'R' and
 into other numerical languages (such as NumPy in python), I will use sapply
 / lapply to demonstrate, but this behavior is ubiquitous throughout 'R'.

    Let's say I have a class which is theoretically supported, but not one
 of the core numeric or character classes (and, to some degree, factor
 classes).  Many of the basic functions will convert my desired class into
 either numeric or character, so that my returned answer is gibberish.

 E.g.:

 test= as.difftime(c(1, 1, 8, 0.25, 8, 1.25), units= days)  ## create a
 small array of time differences
 class(test)  ## this will return the proper class, difftime
 class(test[1] ) ## this will also return the proper class, difftime
 sapply(test, class)  ## this will return *numerics* for all of the classes.
  Ack!!

    In the example I give above, the impact might seem small, but the
 implications are *huge*.  This means that I am, in effect, not allowed to
 use *any* of the vectoring functions in 'R', which avoid performing loops
 thereby speeding up process time extraordinarily.  Many can sympathize that
 'R' is ridiculously slow with for loops, compared to other languages.
  But that's theoretically OK, a good statistician or data analyst should be
 able to work comfortably with matrices and vectors.  However, *'R' cannot
 work comfortably* with matrices or vectors, *unless* they are using the
 numeric or character classes.  Many of the classes suffer the problem I
 just described, although I only used difftime in the 

Re: [R] Is it possible to vectorize/accelerate this?

2011-11-03 Thread William Dunlap
You should get familiar with some basic timing tools
and techniques so you can investigate things like this
yourself.

system.time is the most basic timing tool.  E.g.,
   system.time(for(i in 1:1000)f0(a))
 user  system elapsed
   22.920   0.000  22.932
means it took c. 23 seconds of real time to run f0(a)
1000 times.

When comparing timing, it makes things easier to define
a series of functions that implement the various algorithms
but have the same inputs and outputs.  E.g., for your problem

f0 - function(a_vec) {
b_vec - a_vec
for (i in 2:length(b_vec)){
b_vec[i] - ifelse(abs(b_vec[i-1] + a_vec[i])  1, a_vec[i], b_vec[i-1] 
+ a_vec[i])
}
b_vec
}

f1 - function(a_vec) {
b_vec - a_vec
for (i in 2:length(b_vec)){
b_vec[i] - if(abs(b_vec[i-1] + a_vec[i])  1) a_vec[i] else b_vec[i-1] 
+ a_vec[i]
}
b_vec
}

f2 - function(a_vec) {
b_vec - a_vec
for (i in 2:length(b_vec)){
if(abs(s - b_vec[i-1] + a_vec[i]) = 1) b_vec[i] - s
}
b_vec
}

Then run them with the same dataset:
 a - runif(1000, 0, .3)
 system.time(for(i in 1:1000)f0(a))
   user  system elapsed
 22.920   0.000  22.932
 system.time(for(i in 1:1000)f1(a))
   user  system elapsed
  5.510   0.000   5.514
 system.time(for(i in 1:1000)f2(a))
   user  system elapsed
  4.210   0.000   4.217

(The rbenchmark package's benchmark function encapsulates this idiom.) 

It pays to use a dataset similar to the one you will ultimately be using,
where similar depends on the context.  E.g., the algorithm in f2 is relatively
faster when the cumsum exceeds 1 most of the time

 a - runif(1000, 0, 10)
 system.time(for(i in 1:1000)f0(a))
   user  system elapsed
 21.900   0.000  21.912
 system.time(for(i in 1:1000)f1(a))
   user  system elapsed
  4.610   0.000   4.609
 system.time(for(i in 1:1000)f2(a))
   user  system elapsed
  2.490   0.000   2.494

If you will be working with large datasets, you should look at how the
time grows as the size of the dataset grows.  If the time looks quadratic 
between,
say, length 100 and length 200, don't waste your time testing it for length 
100.
For algorithms that work on data.frames (or matrices), the relative speed ofen
depends on the ratio of the number of rows and the number of columns of data.
Check that out.  For these sorts of tests it is worthwhile to make a function to
generate typical looking data of any desired size.
 
It doesn't take too long to do this once you have the right mindset.  Once you
do you don't have to rely on folklore like never use loops and instead do
evidence-based computing.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of R. Michael
 Weylandt
 Sent: Thursday, November 03, 2011 2:51 PM
 To: hihi; r-help
 Subject: Re: [R] Is it possible to vectorize/accelerate this?
 
 Yes -- if  else is much faster than ifelse() because if is a
 primitive while ifelse() is a whole function call (in fact, you can
 see the code by typing ifelse into the prompt and see that it has two
 if calls within it.
 
 Michael
 
 On Thu, Nov 3, 2011 at 4:38 PM, hihi v.p.m...@freemail.hu wrote:
  Hi,
  thank you for your very immediate response. :-) Is if than and else faster
  than ifelse? I'm wondering (or not knowing something)
  Best regards,
  Peter
  2011/11/3 R. Michael Weylandt michael.weyla...@gmail.com
  michael.weyla...@gmail.com
 
  I don't immediately see a good trick for vectorization so this seems to me
  to be a good candidate for work in a lower-level language. Staying within 
  R,
  I'd suggest you use if and else rather than ifelse() since your computation
  isn't vectorized: this will eliminate a small amount over overhead. Since
  you also always add a_vec, you could also define b_vec as a copy of a to
  avoid all those calls to subset a, but I don't think the effects will be
  large and the code might not be as clear.
 
  You indicated that you may be comfortable with writing C, but I'd suggest
  you look into the Rcpp/Inline package pair which make the whole process 
  much
  easier than it would otherwise be.
 
   I'm not at a computer write now or I'd write a fuller example, but the
  documentation for those packages is uncommonly good an you should be able 
  to
  easily get it down into C++. If you aren't able to get it by tomorrow, let
  me know and I can help troubleshoot. The only things I foresee that you'll
  need to change are zero-basing, C's loop syntax, and (I think) the call to
  abs(). (I always forget where abs() lives in c++ )
 
  The only possible hold up is that you need to be at a computer with a C
  compiler
 
  Hope this helps,
 
  Michael
 
  On Nov 3, 2011, at 3:10 PM, hihi v.p.m...@freemail.hu wrote:
 
   Dear Members,
  
   I work on a simulaton experiment but it has an bottleneck. It's quite
   fast because of R and vectorizing, but it has a very slow for loop. The
   adjacent 

  1   2   >