Re: [R] Rpart - best split selection for class method and Gini splitting index

2009-05-21 Thread Prof Brian Ripley

On Thu, 21 May 2009, Paolo Radaelli wrote:



Dear R-users,
I'm working with the Rpart package and trying to understand how the procedure


I presume you mean 'rpart': R package names are case sensitive.

select the best split in the case the method "class" and the 
splitting index "Gini" are used. In particular I'd like to have look 
to the source code that works out the best split for un unordered 
predictor.


Does anyone can suggest me which functions in the sources I should 
consider ?


It done in C.  Start with file bsplit.c, that says

** The routine which will find the best split for a node

Then look at gini.c (again, pretty obvious, I believe).


Any input would be highly appreciated.

Thank you
Paolo

Paolo Radaelli
Dipartimento di Metodi Quantitativi per le Scienze Economiche ed Aziendali
Facoltà di Economia
Università degli Studi di Milano-Bicocca
Via Bicocca degli Arcimboldi, 8
20126 Milano
Italy
e-mail paolo.radae...@unimib.it
Tel +39 02 6448 3163
Fax +39 02 6448 3105

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] [R-pkgs] New package for medical image manipulation: tractor.base

2009-05-21 Thread Jon Clayden
Dear all,

The "tractor.base" package has recently been added to CRAN. This
package provides functions to read, write, visualise and manipulate
magnetic resonance images. The standard Analyze, NIfTI and DICOM file
formats are supported (read-only for DICOM), and all metadata is
stored with the image data internally. The code can be used to
visualise image slices or maximum intensity projections; and to apply
masking, thresholding or other arbitrary functions to the image data.
The package is written in pure R.

This package stands alone, but it is also part of the larger TractoR
project for working with MR images and diffusion MR based
tractography. Further information about TractoR can be found at
.

Regards,
Jon

--
Jonathan D. Clayden, Ph.D.
Research Fellow
Radiology and Physics Unit
UCL Institute of Child Health
30 Guilford Street
LONDON  WC1N 1EH
United Kingdom

t | +44 (0)20 7905 2708
f | +44 (0)20 7905 2358
w | www.homepages.ucl.ac.uk/~sejjjd2/

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

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


Re: [R] Re order variables in a dataframe

2009-05-21 Thread Peter Dalgaard

Simon Blomberg wrote:

How about to insert a variable a2 inbetween the first and second columns
of dat:

 dat2 <- cbind(dat[,1], a2=a2, dat[,2:3])

Where a2 is the new variable. This mangles the variable name for column
1, unfortunately. Surely someone else will offer a better solution.

Simon.


Just lose the commas:

> head(cbind(aq[1],data.frame(log(aq$Ozone)),aq[2:6]))
  Ozone log.aq.Ozone. Solar.R Wind Temp Month Day
141  3.713572 190  7.4   67 5   1
236  3.583519 118  8.0   72 5   2
312  2.484907 149 12.6   74 5   3
418  2.890372 313 11.5   62 5   4
5NANA  NA 14.3   56 5   5
628  3.332205  NA 14.9   66 5   6

(Otherwise the infamous drop-to-vector effect will bite you and you need 
drop=FALSE, but this does not apply to list-like indexing. For matrices 
you do need drop=FALSE.)


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

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


[R] em algorithm mixture of multivariate normals

2009-05-21 Thread daniele riggi
Hi,
I would like to know if it is possible to have a "R code" to estimate the
parameters of a mixture of bivariate (or multivariate) normals via EM
Algorithm. I tried to write it, but in the estimation of the matrix of
variance and covariance, i have some problems. I generate two bidimensional
vectors both from different distribution with their own vector means and
variance and covariance structure. When I create a unique vector, the
structure of covariance changes, and so the implementation of the EM
algorithm doesn't work.

Maybe someone knows the reason. If I fix the starting initial value of the
covariance matrix and I don't update the estimate of this matrix, the
algorithm works and finds the estimate of the vector means, so I wrote it in
the correct way. However if someone could help me I will be very grateful to
him for kindness.

Best RegardsDaniele

-- 
Dr. Daniele Riggi, PhD student
University of Milano-Bicocca
Department of Statistics
Building U7, Via Bicocca degli Arcimboldi, 8
20126 Milano, Italy
cell. +39 328 3380690
mailto: daniele.ri...@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] [newbie] how to do a 3d plot of bivariate density?

2009-05-21 Thread Francesco Stablum
Hello everybody.
I am new to R. Yesterday I passed the afternoon reading the
introduction and language reference, but I could'nt find a way to do a
3d plot of the density of a data table of size 2.
I am trying with:

 plot(density(t(t2)))

but it mixes the two columns and calculate the density like it is a
1-dimensional casual variable.
I have looked at the documentation of density, but I was not able to do it.
I have also spent quite a lot time looking in the internet for similar
issues, but found nothing helpful.

any suggestions?
thanks
-Francesco Stablum
P.S. sorry for my poor english
-- 
The generation of random numbers is too important to be left to chance
- Robert R. Coveyou

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


Re: [R] [R-sig-Geo] Comparing spatial distributions - permutation test implementation

2009-05-21 Thread Marcelino de la Cruz

Hi,

Jose M. Blanco-Moreno an myself have implemented 
Syrjala's test in the ecespa package. As a matter 
of fact, Jose M. has implemented a Frotran 
version of Syrjala's original QBasic function. 
Using your data the results are very close to 
your reported # statistic= 0.224 and # p-value   = 0.1900.



Cheers,

Marcelino



# with Fortran code
> syrjala0(dataCod[,1:2], dataCod$var1, dataCod$var2,R=F,nsim=1000)
Cramer-von Misses test for the difference between
the spatial distributions of  dataCod$var1 and dataCod$var2
based on 1000 permutations.

   psi: 0.223504
   p-value: 0.2167832

Kolmogorov-Smirnov test for the difference between
the spatial distributions of  dataCod$var1 and dataCod$var2
based on 1000 permutations.

   psi: 0.061354
   p-value: 0.2867133


### With R-code (a bit lengthy, so I use only 100 permutations)
> syrjala0(dataCod[,1:2], dataCod$var1, dataCod$var2,R=T,nsim=100)
Syrjala test for the difference between the spatial distributions of
 dataCod$var1 and  dataCod$var2 , based on 100 simulations

   psi:  0.223504
   p-value:  0.2079208







At 17:34 20/05/2009, JiHO wrote:

Hello everyone,

I am looking at the joint spatial distribution of 2 kinds of organisms
(estimated on a grid of points) and want to test for significant
association or dissociation.

My first question is: do you know a nice technique to do that,
considering that I have a limited number of points (36) but that they
are repeated (4 times)? I did GLMs to test for correlations between
the two (hence forgetting about the spatial aspect of it) and was
previously pointed to the SADIE software. Would there be anything
explicitly spatial and available in R please?

Then, Syrjala's test[1] seems appropriate and tests for differences in
distribution. It computes a Cramér-von Mises-type statistic and tests
its significance with a permutation test.
I implemented the test in R and posted the code on these mailing
lists[2]. Some people checked it and confirmed that the statistic
gives correct results but my estimation of the p-value does not match
the one predicted with the orignal software from Syrjala. I don't know
what I am doing wrong. The permutation test is described by Syrjala as:

(...) Under the null hypothesis,
at a given sampling location (x_k, y_k), either density ob-
servation y_i(x_k, y_k), i = 1, 2, is equally likely for each
population. Thus, for a given data set, the distribution
of the test statistic can be constructed by calculating
the value of the test statistic for all 2^k pairwise per-
mutations of the data set. (...) The level of signif-
icance of a specific realization of the test statistic T is
determined from its position in the ordered set of test
statistic values from all 2^k permutations. (...)

My understanding is that, for each permutation I should choose a
random number of points (between 1 and k), swap the values for species
1 and species 2 at those points, and recompute the test on the new
data. But this does not work :/ . Here is my code and associated data
from Syrjala (for which I have reference values). Any advice would be
very welcome (in particular if there is a way to leverage boot() for
this).
NB: computing the 1000 permutations can be a bit lengthy, but
fortunately, by using plyr, you get a nice progress bar to look at!

syrjala.stat <- function(x, y=NULL, var1=NULL, var2=NULL)
#
#   Compute Syrjala statistic
#   x, ycoordinates
#   var1, var2  value of 2 parameters both measured at (x,y) points
#   NB: x can also be a data.frame/matrix containing x,y,var1,var2 as
columns
#
{
# Input checks
if (!is.null(ncol(x))) {
if (ncol(x) == 4) {
names(x) = c("x","y","var1","var2")
dat = x
} else {
stop("Wrong number of columns in argument x")
}
} else {
dat = data.frame(x, y, var1, var2)
}

# Normalize abundances
dat$var1 = dat$var1/sum(dat$var1)
dat$var2 = dat$var2/sum(dat$var2)

# For each point (each line of dat)
# compute the squared difference in gammas from each origin
meanSqDiff = apply(dat, 1, function(d, coord, variab) {
north = (coord$x>=d[1])
east = (coord$y>=d[2])
south = (coord$x<=d[1])
west = (coord$y<=d[2])
return( mean( c(
(diff(sapply(variab[(north & east),], sum)))^2,
(diff(sapply(variab[(south & east),], sum)))^2,
(diff(sapply(variab[(south & west),], sum)))^2,
(diff(sapply(variab[(north & west),], sum)))^2
) )
)
}, dat[,c("x","y")], dat[,c("var1","var2")])

# Compute the statistic (i.e. sum of mean

[R] Error in importing table from SQL to R

2009-05-21 Thread Madan Mohan

Hi Friends,

I am trying to import a table from SQL server to R(2.9.0), however i am
getting errors while running the below codes. Can anyone identify and let me
know where did i go wrong??? Thanks in anticipation :)

library(RODBC)

myconn <- odbcConnect("RDATABASE")
 
myconn

RODB Connection 6
Details:
  case=nochange
  DSN=RDATABASE
  Description=Database for R
  UID=Madana_Babu
  WSID=IBLPN1B049040
  Trusted_Connection=Yes

NEWDATASQL1 <- sqlFetch(myconne, CampaignDataLarge)

Error in odbcTableExists(channel, sqtable) : 
object 'CampaignDataLarge' not found

NEWDATASQL2 <- sqlFetch(myconne, CampaignDataLarge, colnames = FALSE,
rownames = TRUE)

Error in odbcTableExists(channel, sqtable) : 
object 'CampaignDataLarge' not found

NEWDATASQL3 <- sqlFetchMore(myconne, CampaignDataLarge, colnames = TRUE,
rownames = TRUE)

NEWDATASQL3

[1] -1

NEWDATASQL4 <- sqlQuery(myconne, "select * from CampaignDataLarge", errors =
TRUE, colnames = FALSE, rownames = TRUE)

NEWDATASQL4

[1] "[RODBC] ERROR: Could not SQLExecDirect"
   
[2] "42S02 208 [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object
name 'CampaignDataLarge'."

Regards,
Madan
-- 
View this message in context: 
http://www.nabble.com/Error-in-importing-table-from-SQL-to-R-tp23650489p23650489.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] XML parse error

2009-05-21 Thread Richard . Cotton
>I am trying to parse XML file ( binary hex) but get an error. 
> Code I am using is:
> xsd = xmlTreeParse(system.file("exampleData", "norel.xsd", package =
> "XML"), isSchema =TRUE) doc = xmlInternalTreeParse(system.
> file("exampleData", "LogCallSummary.bin", package = "XML")) Start 
> tag expected, '<' not found
> 
>  xmlParse command results in same error as well: 
> f = system.file("exampleData", "LogCallSummary.bin", package = 
> "XML") > doc = xmlParse(f)Start tag expected, '<' not found
> I am at beginner level with XML and will appreciate any help with 
> this error or general guidance. 
> Thanks 
> Kulwinder Banipal
> 
> file is:
> 000: 0281 0001 0201 0098 c1d5 c000    
> 010: 000a c0a8 db35 0055 6000 00af 0001 0001  .5.U`...
> 020: 5f00 2200 4530  4411 2233 4455 0f08  _.".E0..D."3DU..
> 030: 0123 4567 8901 2340  04d2    .#eg...@
> 040:   0002 0100 0001 0003 0303   
> 050:   0100  6400  0100   d...
> 060: 6401 0300 0900 00fe fe00 012f 0001   d../
> 070: 0101 0001   0001  2200 0033  "..
> 3080: 3306   0022  1100    3...33."
> 090: 0033 3400 2300 0011  0001  3335  .34.#.
> 350a0: 0024  1100  0200 0033 3600 2500  .$.36.%.
> 0b0: 0011  0003  3337 0026  1100  37.&
> 0c0:  0400 0033 3800 2700 0011  0005  .38.'...
> 0d0: 5504 7700 8800 0044 4406  2323 0099  U.wDD...##..
> 0e0: 0100 0200   0023 2400 9901 0002  .#$.
> 0f0:  0001  2325 0099 0100 0200   ..#%
> 100: 0200 0023 2600 9901 0002  0003   ...#&...
> 110: 2327 0099 0100 0200  0400 0023 2800  #'...#(.
> 120: 9901 0002  0005 0102 0008 0100 0066  ...
> f130: 6600 0055 5533   3400  0a35  f..UU34
> 5140:  0014 3600  1e37  0028 3800  67...(8.
> 150:  3239  003c 3a00  463b   ..29...<:...F;..
> 160: 0050 3c00  5a00 0088 8800 0077 7744  .P<...Z..
> wwD170:   4500  0a46  0014 4700  EF
> G.180:  1e48  0028 4900  324a   ...H...(I...2J..
> 190: 003c 4b00  464c  0050 4d00   . 1a0: 5a02 2207 7766 6604 0500  1100 0088  Z.".wff.
> 1b0: 8800  0106  0011  8889   
> 1c0: 0011 0700  1100 0088 8a00  2108  ..!.
> 1d0:  0011  888b  0031 0405   ...1
> 1e0: 0022  0044  0001 0600  2200  ."...D".
> 1f0:  4500  1107  0022  0046  ..E"...
> F200:  0021 0800  2200  4700   ...!"...G...
> 210: 3106  0001 0002 0003 0004 0005 0200  1...
> 220: 0033 4400 0055 6609 0101 0202 0303 0404  .3D..Uf.
> 230: 0505 0606 0707 0808 0909 0405  0011  
> 240:  0044  0022  0088 0500   ...D..."
> 250: 1200  4500  2300  8905   E...#...
> 260: 0013  0046  0024  008a 0500  .F...$..
> 270:  1400  4700  2500  8bfa 
..G...%.280: ae

Um, this isn't an XML file. An XML file should look something like this:



   value


The wikipedia entry on XML gives a reasonable intro to the format.  
http://en.wikipedia.org/wiki/Xml

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

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

2009-05-21 Thread Zeljko Vrba
I use the following function to export some figures to .eps:

p.eps <- function(p, fname, title = NULL, width, height)
{
  postscript(file=fname, onefile=FALSE, paper="special",
 width=width, height=height, horizontal=FALSE)
  print(p + opts(title = title))
  dev.off()
}

Whenever I have a page consisting of *only* figures exported in this way,
Acrobat Reader shows them in landscape.  If the figures are mixed with
text, the page retains its portrait orientation.

Any ideas on what's going wrong?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 can I estimate a Box-Cox function with R?

2009-05-21 Thread Ikerne del Valle


Dear Fernando and all:

	Thanks for your help. Now works. This is 
a training example to learn how to estimate a 
Box-Cox (right and/or left side transformations) 
with R (as LIMDEP does) in order to compare these 
estimations with the ones derived by applying 
NLS, ones the dependent variable has been divided 
by its geometric mean (see below) as suggested by 
(Zarembka (1974) and Spitzer (1984). However the 
example of the demand of money seems not to work. 
Any idea to face the error messages or how to 
estimate a Box-Cox function with R?


Best regards,
Ikerne

library(nlrwr)
r<-c(4.50,4.19,5.16,5.87,5.95,4.88,4.50,6.44,7.83,6.25,5.50,5.46,7.46,10.28,11.77,13.42,11.02,8.50,8.80,7.69)
Lr<-log(r)
M<-c(480.00,524.30,566.30,589.50,628.20,712.80,805.20,861.00,908.40,1023.10,1163.60,1286.60,1388.90,1497.90,1631.40,1794.40,1954.90,2188.80,2371.70,2563.60)
LM<-log(M)
Y<-c(2208.30,2271.40,2365.60,2423.30,2416.20,2484.80,2608.50,2744.10,2729.30,2695.00,2826.70,2958.60,3115.20,3192.40,3187.10,3248.80,3166.00,3277.70,3492.00,3573.50)
LY<-log(Y)
gmM<-exp((1/20)*sum(LM))
GM<-M/gmM
Gr<-r/gmM
GY<-Y/gmM
money<-data.frame(r,M,Y,Lr,LM,LY,GM,Gr,GY)
attach(money)
ols1<-lm(GM~r+Y)
output1<-summary(ols1)
coef1<-ols1$coefficients
a1<-coef1[[1]]
b11<-coef1[[2]]
b21<-coef1[[3]]
ols2<-lm(GM~Gr+GY)
output2<-summary(ols2)
coef2<-ols2$coefficients
a2<-coef2[[1]]
b12<-coef2[[2]]
b22<-coef2[[3]]
money.m1<-nls(GM~a+b*r^g+c*Y^g,data=money,start=list(a=a1,b=b11,g=1,c=b21))
money.m2<-nls(GM~a+b*Gr^g+c*GY^g,data=money,start=list(a=a2,b=b12,g=1,c=b22))


Ikerne del Valle Erkiaga
Department of Applied Economics V
Faculty of Economic and Business Sciences
University of the Basque Country
Avda. Lehendakari Agirre, Nº 83
48015 Bilbao (Bizkaia) Spain

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

2009-05-21 Thread Kon Knafelman

Hi Guys,

i think this is a relatively simple question.

I have coded the following polynomial function

y= function(x) x^3-2*x^2+1

I need to find the inverse of this, but the code i am using now isnt returning 
what i want it to.

What is the general code for finding an inverse function?

Thanks guys 

_
View photos of singles in your area Click Here

au%2Fsearch%2Fsearch%2Easpx%3Fexec%3Dgo%26tp%3Dq%26gc%3D2%26tr%3D1%26lage%3D18%26uage%3D55%26cl%3D14%26sl%3D0%26dist%3D50%26po%3D1%26do%3D2%26trackingid%3D1046138%26r2s%3D1&_t=773166090&_r=Hotmail_Endtext&_m=EXT
[[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] em algorithm mixture of multivariate normals

2009-05-21 Thread Christian Hennig

Look up packages flexmix and mclust!

Christian

On Thu, 21 May 2009, daniele riggi wrote:


Hi,
I would like to know if it is possible to have a "R code" to estimate the
parameters of a mixture of bivariate (or multivariate) normals via EM
Algorithm. I tried to write it, but in the estimation of the matrix of
variance and covariance, i have some problems. I generate two bidimensional
vectors both from different distribution with their own vector means and
variance and covariance structure. When I create a unique vector, the
structure of covariance changes, and so the implementation of the EM
algorithm doesn't work.

Maybe someone knows the reason. If I fix the starting initial value of the
covariance matrix and I don't update the estimate of this matrix, the
algorithm works and finds the estimate of the vector means, so I wrote it in
the correct way. However if someone could help me I will be very grateful to
him for kindness.

Best RegardsDaniele

--
Dr. Daniele Riggi, PhD student
University of Milano-Bicocca
Department of Statistics
Building U7, Via Bicocca degli Arcimboldi, 8
20126 Milano, Italy
cell. +39 328 3380690
mailto: daniele.ri...@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.



*** --- ***
Christian Hennig
University College London, Department of Statistical Science
Gower St., London WC1E 6BT, phone +44 207 679 1698
chr...@stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche

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


[R] "Error: C stack usage is too close to the limit" (can't understand explanations of how to fix this)

2009-05-21 Thread anon36

Apparently the way to deal with this error message is to set
  R_CStackLimit = (uintptr_t)-1
I tried typing this in the R console, but it says Error: object
"R_CStackLimit" not found.
So where do I type it? In one of the initialization files that R uses when
it starts up?
I can't find the answer anywhere. Please note that I don't understand words
like "DLL" or "embed", and I don't understand how R works at any deep level.
I am using R 2.8.1 on Windows XP. 
-- 
View this message in context: 
http://www.nabble.com/%22Error%3A-C-stack-usage-is-too-close-to-the-limit%22-%28can%27t-understand-explanations-of-how-to-fix-this%29-tp23650518p23650518.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 ci for lmer

2009-05-21 Thread Xin Shi
Hi,

I am trying to calculate ci from lmer. However, I have the error message
below:

 

library(gmodels)

library(lme4)

fm2 <- lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject), sleepstudy)

ci(fm2)

 

Error in as.vector(x, mode) : 

  cannot coerce type 'S4' to vector of type 'any'

In addition: Warning message:

In mean.default(x, na.rm = na.rm) :

  argument is not numeric or logical: returning NA

 

I also tried another example below and got the same problem.

 

y=c(1,0,1,1,0,1,0,1,1,1)

x1=c(1,2,3,4,5,1,2,3,4,5)

x2=c(1.5,2,1.3,3.2,2.7,9.1,5.4,2,4,1)

fit<-lmer(y~x2+(1|x1))

ci(fit)

 

Does anyone know the solution?

 

In addition, I want to do the daily update for R. I run the code below and
it is not working.

 

svn log -v -r HEAD:\{`date +%Y-%m-%d -d'7 days ago'`\}
https://svn.r-project.org/R

 

Does anyone use this code before?

 

Thanks!

 

Xin

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


Re: [R] [newbie] how to do a 3d plot of bivariate density?

2009-05-21 Thread Richard . Cotton
> I am new to R. Yesterday I passed the afternoon reading the
> introduction and language reference, but I could'nt find a way to do a
> 3d plot of the density of a data table of size 2.
> I am trying with:
> 
>  plot(density(t(t2)))
> 
> but it mixes the two columns and calculate the density like it is a
> 1-dimensional casual variable.

I presume what you mean by a data table of size 2 is something like this:

data <- matrix(c(3,53,36,17), nrow=2)

3D plots are almost never the best solution.  (You get all sorts of issues 
with perspective problems and some bits of the plot being obscured by 
other bits.)  Would something like this to the trick?

image(data)

If you want something different, then please provide an example of your 
data (nothing too big, so we can reproduce it), and a description of what 
you would like to show.

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

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


Re: [R] Inverse

2009-05-21 Thread Zeljko Vrba
On Thu, May 21, 2009 at 08:36:27PM +1000, Kon Knafelman wrote:
> 
> I have coded the following polynomial function
> 
> y= function(x) x^3-2*x^2+1
> 
> I need to find the inverse of this, but the code i am using now isnt 
> returning what i want it to.
> 
This function is not injective, so the inverse does not exist.  For example,
y==0.5 has three solutions: -0.452, 0.597, 1.855

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


Re: [R] postscript problems (landscape orientation)

2009-05-21 Thread Prof Brian Ripley

On Thu, 21 May 2009, Zeljko Vrba wrote:


I use the following function to export some figures to .eps:

p.eps <- function(p, fname, title = NULL, width, height)
{
 postscript(file=fname, onefile=FALSE, paper="special",
width=width, height=height, horizontal=FALSE)
 print(p + opts(title = title))
 dev.off()
}

Whenever I have a page consisting of *only* figures exported in this way,
Acrobat Reader shows them in landscape.  If the figures are mixed with
text, the page retains its portrait orientation.

Any ideas on what's going wrong?


Using Acrobat Reader to view PostScript!  It is a PDF viewer.

Acrobat Distiller has an auto-rotation option (on by default) when 
converting PostScript to PDF, which ghostscript later copied.  I 
suspect you need to track down where conversion to PDF is happening 
and disable auto-rotation.



From ?postscript:


Note:

 If you see problems with postscript output, do remember that the
 problem is much more likely to be in your viewer than in R.  Try
 another viewer if possible.

What happened when you followed that request?

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

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


[R] transformation and outliers

2009-05-21 Thread Fernando Marmolejo Ramos
Dear R people

I ask again…

1.  Is there a published reference presenting the normal score
transformation? Is there a published paper (in any field) using that
transformation in the analysis of data?

And this is a new question…

2.  The “outliers” library has a function called “rm.outlier”. It offers
the option of either removing one outlier (the largest or the smallest) or
replacing the identified outlier by the mean or median of the data. Does anyone
know of a published paper introducing that particular approach (replacing the
outlier by the group’s mean/median)?

Cheers

Fer

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


Re: [R] postscript problems (landscape orientation)

2009-05-21 Thread Zeljko Vrba
On Thu, May 21, 2009 at 12:32:28PM +0100, Prof Brian Ripley wrote:
> 
> Using Acrobat Reader to view PostScript!  It is a PDF viewer.
> 
Ah, sorry, I explicitly convert the PS with ghostscript's ps2pdf. 

>
> suspect you need to track down where conversion to PDF is happening 
> and disable auto-rotation.
> 
Thanks, I'll search for auto-rotation.

> 
> What happened when you followed that request?
> 
People got printed pages in strange orientations.

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


Re: [R] transformation and outliers

2009-05-21 Thread Peter Dalgaard

Fernando Marmolejo Ramos wrote:

Dear R people

I ask again…

1.  Is there a published reference presenting the normal score
transformation? Is there a published paper (in any field) using that
transformation in the analysis of data?


Dunno, but I'd search for "Normal Scores Test", AKA van der Waerden's 
Test, in books dealing with nonparametric tests.  It comes out in a 
natural way as the score test in a model  where you assume that you have 
normally distributed data with a location shift, but transformed by an 
unknown monotone transformation.


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

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


[R] Offsets in bigglm

2009-05-21 Thread Linda Eaton

Is it possible to have offsets in a glm when using bigglm? 

_
[[elided Hotmail spam]]

[[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] postscript problems (landscape orientation)

2009-05-21 Thread Peter Dalgaard

Zeljko Vrba wrote:

On Thu, May 21, 2009 at 12:32:28PM +0100, Prof Brian Ripley wrote:

Using Acrobat Reader to view PostScript!  It is a PDF viewer.

Ah, sorry, I explicitly convert the PS with ghostscript's ps2pdf. 

suspect you need to track down where conversion to PDF is happening 
and disable auto-rotation.



Thanks, I'll search for auto-rotation.


I think the trick is

jade:~/> env | grep GS_
GS_OPTIONS=-dAutoRotatePages=/None

which I still have on my work login. However, I almost never use PS 
these days since it is easier just to create the plot files with the 
pdf() device.




What happened when you followed that request?


People got printed pages in strange orientations.

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



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

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


Re: [R] postscript problems (landscape orientation)

2009-05-21 Thread Zeljko Vrba
On Thu, May 21, 2009 at 02:14:01PM +0200, Peter Dalgaard wrote:
> 
> I think the trick is
> 
> jade:~/> env | grep GS_
> GS_OPTIONS=-dAutoRotatePages=/None
> 
Thanks, I found that myself.  However, when using ps2pdf from Miktex 2.7, I
get the following error:

Unrecoverable error: typecheck in .putdeviceprops

I will try to manually invoke gs or, eventually, just use Distiller.

>
> which I still have on my work login. However, I almost never use PS 
> these days since it is easier just to create the plot files with the 
> pdf() device.
> 
Ah, now I remember why I don't use pdflatex: when you re-create the document,
the viewer gets _very_ confused, so I have to close and reopen the file and go
to the page I was viewing.  When I recreate postscript and turn on "Watch file"
in ghostview, I get automatic and quick previews of my work.

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


[R] Need help on ploting Histograms

2009-05-21 Thread Bonna

this is the command i made for a normal distribution, but when i try to plot
the histograms, i dont know why the bars don't stick on the line...

nsamples<-1000
sampsize<-15
Samples<-matrix(rnorm(nsamples*sampsize,0,1),nrow=nsamples) 
a<-apply(Samples,1,var)
NC14<-a*14
x<-0:40
plot(x,dchisq(x,14),type='h') 
hist(NC14,freq=F,add=T)
-- 
View this message in context: 
http://www.nabble.com/Need-help-on-ploting-Histograms-tp23652178p23652178.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] Negative value for adjustedRandIndex?

2009-05-21 Thread Pooka

Hello, 

I am a very new user to R so please have patience with me. :clap:

I am trying to evalute the "internal response" for a couple of different
cluster methods with the help of the AdjustedRandIndex, which is included in
the mclust package. 

However, I do get a bit puzzled when I get a negative value as the value
should be in intervall of [0,1], am I correct? Have I done something wrong?
Or should I interpret the negative value as the two methods do not group the
cases to the same cluster?

I have for example used k-means and k-median, and choosen five clusters. 
Each respondent has been labelled as either beloning to cluster 1,2,3,4 or
5. I have picked out the first 32 respondents. 

Example:


a   <- c(1,2,3,4,5,2,1,5,1,2,2,4,2,3,3,2,4,5,5,4,4,4,5,5,2,3,1,5,5,5,4,1)
b   <- c(5,5,5,2,5,3,2,2,2,5,3,4,5,5,2,5,2,3,5,5,5,3,5,3,3,2,4,5,2,2,2,3)
adjustedRandIndex (a,b)

[1] -0.01608168



Thanks in advance,

Pooka
-- 
View this message in context: 
http://www.nabble.com/Negative-value-for-adjustedRandIndex--tp23652402p23652402.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to google for R stuff?

2009-05-21 Thread David Cross

You can also try:

http://www.rseek.org/

Cheers

Duncan Murdoch wrote:

On 20/05/2009 10:01 AM, cr...@binghamton.edu wrote:

For Google searches, I find that throwing in the term cran on every search 
helps weed out irrelevant pages.

For example, instead of 


r residuals

I type

r cran residuals


You are very picky.  When I enter

R residuals

into Google, 8 out of the first 10 hits are for R topics.  Isn't that 
good enough for you?


I think this is true of most Google searches:  the letter R most often 
means the R project.


Duncan Murdoch


--Chris Ryan

 Original message 

Date: Wed, 20 May 2009 09:43:14 -0400
From: Luc Villandre   
Subject: Re: [R] How to google for R stuff?  
To: Kynn Jones 

Cc: r-help@r-project.org


Kynn Jones wrote:

Hi!  I'm new to R programming, though I've been programming in other
languages for years.

One thing I find most frustrating about R is how difficult it is to use
Google (or any other search tool) to look for answers to my R-related
questions.  With languages with even slightly more distinctive names like
Perl, Java, Python, Matlab, OCaml, etc., usually including the name of the
language in the query is enough to ensure that the top hits are relevant.
 But this trick does not work for R, because the letter R appears by itself
in so many pages, that the chaff overwhelms the wheat, so to speak.

So I'm curious to learn what strategies R users have found to get around
this annoyance.

TIA!

KJ

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

Hi Kynn,

I've had this problem too in the beginning. Luckily, my personal 
experience has taught me that almost all relevant R-related information 
can be found either by searching directly through the archives of the 
different R-forums or by using the functions "RSiteSearch()" or 
"help.search()". The reference manuals provided with each package 
(easily accessible on CRAN) are also invaluable sources of information.


Unfortunately, phrasing queries in a way that will yield relevant 
results is sometimes hard. Knowledge of the terminology mostly comes 

>from experience, so patience is in order.

Of course, as a last recourse, there's always the mailing list.

Bottom line is, I suggest you try to avoid generic search engines and 
concentrate your efforts on the different R-forums (note that there are 
also package-specific forums).


I suspect the more experienced R-users might have better strategies to 
propose though...


Cheers,
--
*Luc Villandré*
/Biostatistician
McGill University Health Center -
Montreal Children's Hospital Research Institute/

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

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


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


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

2009-05-21 Thread Andy Choens
> You are very picky.  When I enter
> 
> R residuals
> 
> into Google, 8 out of the first 10 hits are for R topics.  Isn't that 
> good enough for you?
> 
> I think this is true of most Google searches:  the letter R most
often 
> means the R project.

Although it does not appear to be a factor with this search, it is worth
remembering that Google will customize search results for individual
users. I have found with certain computer/linux searches that when I
search from my Google Account I _do_ get different results compared to
when I am not logged into my google account. I tried this search and was
still able to easily find R related materials, but it is worth
remembering that for those of us who use Google services heavily and
have accounts, our results may differ.


-- 
This is the price and the promise of citizenship.
- Barack Obama

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


Re: [R] Example for parsing XML file?

2009-05-21 Thread Brigid Mooney
Thanks!  That helps a lot!

A quick follow-up question - I can't really tell what part of the
commands tell it to only look at the child nodes of .  Is there any
way to also access the fields that are in the  heirarchy?  (ie the
S, D, C, and F)

I wouldn't necessarily want those repeated thousands of times in the
data frame, but C and F are useful reference points as they are
actually row numbers where specific events occurred.

Thanks again for all the help!
-Brigid



On Wed, May 20, 2009 at 5:16 PM, Duncan Temple Lang
 wrote:
> Hi Brigid.
>
> Here are a few commands that should do what you want:
>
> bri = xmlParse("myDataFile.xml")
>
> tmp =  t(xmlSApply(xmlRoot(bri), xmlAttrs))[, -1]
> dd = as.data.frame(tmp, stringsAsFactors = FALSE,
>                    row.names = 1:nrow(tmp))
>
> And then you can convert the columns to whatever types you want
> using regular R commands.
>
> The basic idea is that for each of the child nodes of C,
> i.e. the 's, we want the character vector of attributes
> which we can get with xmlAttrs().
>
> Then we stack them together into a matrix, drop the "N"
> and then convert the result to a data frame, avoiding
> duplicate row names which are all "T".
>
> (BTW, make certain the '-' on the second line is not in the XML content.
>  I assume that came from bringing the text into mail.)
>
> HTH
>  D.
>
>
> Brigid Mooney wrote:
>>
>> Hi,
>>
>> I am trying to parse XML files and read them into R as a data frame,
>> but have been unable to find examples which I could apply
>> successfully.
>>
>> I'm afraid I don't know much about XML, which makes this all the more
>> difficult.  If someone could point me in the right direction to a
>> resource (preferably with an example or two), it would be greatly
>> appreciated.
>>
>> Here is a snippet from one of the XML files that I am looking to read,
>> and I am aiming to be able to get it into a data frame with columns N,
>> T, A, B, C as in the 2nd level of the heirarchy.
>>
>>  
>> - 
>>  
>>  
>>  
>>  
>>  
>>  
>>  
>>  
>> 
>>
>> Thanks for any help or direction anyone can provide.
>>
>> As a point of reference, I am using R 2.8.1 and have loaded the XML
>> package.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] Loop avoidance and logical subscripts

2009-05-21 Thread retama

Hello!

I'm writing a script with a lot of loops and it executes really slowly over
huge amounts of data. I assume it's because I don't know how to avoid using
loops. Logical subscripts are more desirable, but I don't know how to
implement them. One example of that issue:

library(seqinr)
GCsequence <- vector()
for( i in 1:(length(data$sequence))) {
c(GCsequence,GC(s2c(data$sequence[i])))->data$GCsequence[i]
}
rm(GCsequence)

How should I speed up that? 

Thank you, 

Retama
-- 
View this message in context: 
http://www.nabble.com/Loop-avoidance-and-logical-subscripts-tp23652935p23652935.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] Example for parsing XML file?

2009-05-21 Thread Duncan Temple Lang



Brigid Mooney wrote:

Thanks!  That helps a lot!

A quick follow-up question - I can't really tell what part of the
commands tell it to only look at the child nodes of .  


xmlRoot(bri) gives us the C node.

xmlSApply(node, f) is short-hand for
  sapply(xmlChildren(node), f)
so that is where we loop over the children.

>Is there any

way to also access the fields that are in the  heirarchy?  (ie the
S, D, C, and F)


  xmlAttrs(xmlRoot(bri))



I wouldn't necessarily want those repeated thousands of times in the
data frame, but C and F are useful reference points as they are
actually row numbers where specific events occurred.

Thanks again for all the help!
-Brigid



On Wed, May 20, 2009 at 5:16 PM, Duncan Temple Lang
 wrote:

Hi Brigid.

Here are a few commands that should do what you want:

bri = xmlParse("myDataFile.xml")

tmp =  t(xmlSApply(xmlRoot(bri), xmlAttrs))[, -1]
dd = as.data.frame(tmp, stringsAsFactors = FALSE,
   row.names = 1:nrow(tmp))

And then you can convert the columns to whatever types you want
using regular R commands.

The basic idea is that for each of the child nodes of C,
i.e. the 's, we want the character vector of attributes
which we can get with xmlAttrs().

Then we stack them together into a matrix, drop the "N"
and then convert the result to a data frame, avoiding
duplicate row names which are all "T".

(BTW, make certain the '-' on the second line is not in the XML content.
 I assume that came from bringing the text into mail.)

HTH
 D.


Brigid Mooney wrote:

Hi,

I am trying to parse XML files and read them into R as a data frame,
but have been unable to find examples which I could apply
successfully.

I'm afraid I don't know much about XML, which makes this all the more
difficult.  If someone could point me in the right direction to a
resource (preferably with an example or two), it would be greatly
appreciated.

Here is a snippet from one of the XML files that I am looking to read,
and I am aiming to be able to get it into a data frame with columns N,
T, A, B, C as in the 2nd level of the heirarchy.

 
- 
 
 
 
 
 
 
 
 


Thanks for any help or direction anyone can provide.

As a point of reference, I am using R 2.8.1 and have loaded the XML
package.

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

2009-05-21 Thread Richard . Cotton
> this is the command i made for a normal distribution, but when i try to 
plot
> the histograms, i dont know why the bars don't stick on the line...
> 
> nsamples<-1000
> sampsize<-15
> Samples<-matrix(rnorm(nsamples*sampsize,0,1),nrow=nsamples) 
> a<-apply(Samples,1,var)
> NC14<-a*14
> x<-0:40
> plot(x,dchisq(x,14),type='h') 
> hist(NC14,freq=F,add=T)

Set the histogram bins to match the plot.  Change the last line of your 
code to, e.g.

hist(NC14,freq=F,add=T, breaks=x, border="transparent", col="#")

Note that the histogram contains sample values, while the plot shows a 
theoretical distribution, so they won't match exactly.

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] index to select rows of a large matrix

2009-05-21 Thread tsunhin wong
Dear R Users,

I have created a 1500 x 2 data frame - DataSeq. Each of the 1500
rows represents a data sequence.
I have another data frame iData that stores the information of these
1500 data sequences in the same order, for example, condition, gender,
etc.

If I use "subset" to select certain groups within iData according to
some criteria that I have set, e.g. condition, gender
Then how can I used the retrieved subset of iData to point to and
retrieve corresponding rows in the DataSeq data.frame for
manipulations and analysis?

I hope some of you can give me some idea!
Thank you very much!!!

- John

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

2009-05-21 Thread Mark Bilton

I am having a slight problem with probabilities.

To calculate the final probability of an event p(F), we can take the product of 
the chance that each independent event that makes p(F) will NOT occur.
So...
p(F) = 1- ( (1-p(A)) * (1-p(B)) * (1-p(C))...(1-p(x)) )

If the chance of an event within the product occurring remains the same, we can 
therefore raise this probability to a power of the number of times that event 
occurs.
e.g. rolling a dice p(A) = 1/6 of getting a 1...
p(F) = 1 - (1- (1/6))^z 
p(F) = 1 - (1-p(A))^z tells us the probabiltity of rolling a 1 'at least once' 
in z number of rolls.

So then to R...

if p(A) = 0.01; z = 4; p(F) = 0.039

obviously p(F) > p(A)

however the problem arises when we use very small numbers e.g. p(B) = 1 * 10^-30
R understands this value
However when you have 1-p(B) you get something very close to 1 as you 
expect...but R seems to think it is 1.
So when I calculate p(F) = 1 - (1-p(B))^z = 1 to the power anything equals 1 so 
p(F) = 0 and not just close to zero BUT zero.
It doesn't matter therefore if z = 1*10^1000, the answer is still zero !!

Obviously therefore now p(F) < p(B)

Is there any solution to my problem, e.g.
- is it a problem with the sum (-) ? ie could I change the number of bits the 
number understands (however it seems strange that it can hold it as a value 
close to 0 but not close to 1)
-or should I maybe use a function to calculate the exact answer ?
-or something else

Any help greatly appreciated
Mark
-



  

_


[[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] index to select rows of a large matrix

2009-05-21 Thread jim holtman
Assuming that you get the list of indices into iData for the criteria, then
you can use that to get the appropriate rows:

indx <- which(iData >5)  # or whatever your criteria is
DataSeq[indx,, drop=FALSE]  # gives you a subset matrix of just the rows you
are interested in.

On Thu, May 21, 2009 at 10:10 AM, tsunhin wong  wrote:

> Dear R Users,
>
> I have created a 1500 x 2 data frame - DataSeq. Each of the 1500
> rows represents a data sequence.
> I have another data frame iData that stores the information of these
> 1500 data sequences in the same order, for example, condition, gender,
> etc.
>
> If I use "subset" to select certain groups within iData according to
> some criteria that I have set, e.g. condition, gender
> Then how can I used the retrieved subset of iData to point to and
> retrieve corresponding rows in the DataSeq data.frame for
> manipulations and analysis?
>
> I hope some of you can give me some idea!
> Thank you very much!!!
>
> - John
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] [R-sig-Geo] Comparing spatial distributions - permutation test implementation

2009-05-21 Thread JiHO

On 2009-May-21  , at 05:40 , Marcelino de la Cruz wrote:

Jose M. Blanco-Moreno an myself have implemented Syrjala's test in  
the ecespa package. As a matter of fact, Jose M. has implemented a  
Frotran version of Syrjala's original QBasic function. Using your  
data the results are very close to your reported # statistic= 0.224  
and # p-value   = 0.1900.


Thanks a lot. Having the fortran implementation is very nice!
I still don't find the values computed with the quickbasic code but  
the values reported in the article for this data set are different  
from those computed with QB and actually closer to yours.


Looking at your code I still don't get what I am doing wrong though.  
It seems we both use sample to get a few of the columns and then swap  
them. Well, I'll use your test anyway.


JiHO
---
http://jo.irisson.free.fr/

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


Re: [R] Error in importing table from SQL to R

2009-05-21 Thread Seeliger . Curt
Madan asks:
> I am trying to import a table from SQL server to R(2.9.0), however i am
> getting errors while running the below codes. Can anyone identify and 
let me
> know where did i go wrong??? Thanks in anticipation :)
> ...
> NEWDATASQL1 <- sqlFetch(myconne, CampaignDataLarge)
> 
> Error in odbcTableExists(channel, sqtable) : 
> object 'CampaignDataLarge' not found
> ...

Try quoting your table name: 'CampaignDataLarge'

cur
[[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] minmun p-value for wilcox.test and correlation

2009-05-21 Thread Uwe Ligges



Peter Flom wrote:
charles78  wrote 


I have a stupid question on how to get the real p-values for wilcox.test and
correlation.  the minmun can be reached is 2.2E-16 using the R version
2.6.2.  I do not think it is the R version causing this but other issues.

Any help is highly appreciated.



Can I ask why you want this?

I'm curious.



I'm also curious. Anyway, you can get the calculated value by:

wilcox.test()$p.value

Note that printing of htest objects results always in the above 
mentioned minimum for very small values, because we cannot be sure about 
numerical precision, particularly also in the far from centre regions of 
a distribution... (and since you should not report a p-value of exactly 
0 that may numerically arise when doing such computations).


Uwe Ligges






Peter

Peter L. Flom, PhD
Statistical Consultant
www DOT peterflomconsulting DOT 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] Product of 1 - probabilities

2009-05-21 Thread Gabor Grothendieck
There are several arbitrary precision packages available: gmp (an
interface to the GNU multi-precision library on CRAN) and
bc (an R interface to the bc arbitrary precision calculator):
http://r-bc.googlecode.com

There are also packages providing R interfaces to two computer
algebra systems and they both support not only arbitrary
precision but also exact calculation:

http://rsympy.googlecode.com
http://ryacas.googlecode.com

> library(bc)
> 1 - (1-10^-75)^10
[1] 0
> bc("1 - (1-10^-75)^10")
[1] 
".0100"


On Thu, May 21, 2009 at 10:15 AM, Mark Bilton  wrote:
>
> I am having a slight problem with probabilities.
>
> To calculate the final probability of an event p(F), we can take the product 
> of the chance that each independent event that makes p(F) will NOT occur.
> So...
> p(F) = 1- ( (1-p(A)) * (1-p(B)) * (1-p(C))...(1-p(x)) )
>
> If the chance of an event within the product occurring remains the same, we 
> can therefore raise this probability to a power of the number of times that 
> event occurs.
> e.g. rolling a dice p(A) = 1/6 of getting a 1...
> p(F) = 1 - (1- (1/6))^z
> p(F) = 1 - (1-p(A))^z tells us the probabiltity of rolling a 1 'at least 
> once' in z number of rolls.
>
> So then to R...
>
> if p(A) = 0.01; z = 4; p(F) = 0.039
>
> obviously p(F) > p(A)
>
> however the problem arises when we use very small numbers e.g. p(B) = 1 * 
> 10^-30
> R understands this value
> However when you have 1-p(B) you get something very close to 1 as you 
> expect...but R seems to think it is 1.
> So when I calculate p(F) = 1 - (1-p(B))^z = 1 to the power anything equals 1 
> so p(F) = 0 and not just close to zero BUT zero.
> It doesn't matter therefore if z = 1*10^1000, the answer is still zero !!
>
> Obviously therefore now p(F) < p(B)
>
> Is there any solution to my problem, e.g.
> - is it a problem with the sum (-) ? ie could I change the number of bits the 
> number understands (however it seems strange that it can hold it as a value 
> close to 0 but not close to 1)
> -or should I maybe use a function to calculate the exact answer ?
> -or something else
>
> Any help greatly appreciated
> Mark
> -
>
>
>
>
>
> _
>
>
>        [[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] Product of 1 - probabilities

2009-05-21 Thread Ted Harding
On 21-May-09 14:15:08, Mark Bilton wrote:
> I am having a slight problem with probabilities.
> 
> To calculate the final probability of an event p(F), we can take the
> product of the chance that each independent event that makes p(F) will
> NOT occur.
> So...
> p(F) = 1- ( (1-p(A)) * (1-p(B)) * (1-p(C))...(1-p(x)) )
> 
> If the chance of an event within the product occurring remains the
> same, we can therefore raise this probability to a power of the number
> of times that event occurs.
> e.g. rolling a dice p(A) = 1/6 of getting a 1...
> p(F) = 1 - (1- (1/6))^z 
> p(F) = 1 - (1-p(A))^z tells us the probabiltity of rolling a 1 'at
> least once' in z number of rolls.
> 
> So then to R...
> 
> if p(A) = 0.01; z = 4; p(F) = 0.039
> 
> obviously p(F) > p(A)
> 
> however the problem arises when we use very small numbers e.g. p(B) = 1
> * 10^-30
> R understands this value
> However when you have 1-p(B) you get something very close to 1 as you
> expect...but R seems to think it is 1.
> So when I calculate p(F) = 1 - (1-p(B))^z = 1 to the power anything
> equals 1 so p(F) = 0 and not just close to zero BUT zero.
> It doesn't matter therefore if z = 1*10^1000, the answer is still zero
> !!
> 
> Obviously therefore now p(F) < p(B)
> 
> Is there any solution to my problem, e.g.
> - is it a problem with the sum (-) ? ie could I change the number of
> bits the number understands (however it seems strange that it can hold
> it as a value close to 0 but not close to 1)
> -or should I maybe use a function to calculate the exact answer ?
> -or something else
> 
> Any help greatly appreciated
> Mark

The problem is not with sum(), but with the fact that R adopts the
exact value 1 for (1-x) if (on my machine) x < 10^(-16). This is to
do with the number of binary digits used to store a number. Your
10^(-30) is much smaller than that!

  x <- 10^(-30)
  x
# [1] 1e-30
  y <- (1-x) ; 1-y
# [1] 0
  x <- 10^(-15)
  y <- (1-x) ; 1-y
# [1] 9.992007e-16
  x <- 10^(-16)
  y <- (1-x) ; 1-y
# [1] 1.110223e-16
  x <- 10^(-17)
  y <- (1-x) ; 1-y
# [1] 0

Read ?.Machine and, in particular, about:
  double.eps: the smallest positive floating-point number 'x'
such that '1 + x != 1'.  It equals 'base^ulp.digits' if
either 'base' is 2 or 'rounding' is 0;  otherwise, it is
'(base^ulp.digits) / 2'.  Normally '2.220446e-16'.

There is no cure for this in R, but you could try to work round it
(depending on the details of your problem) by using an approximation
to the value of the expression.

For instance, if x is very small (say 10^(-20)), and n is not very
large, then to first order

  (1 - x)^n = 1 - n*x

or, if X is a vector of very small numbers,

  prod((1 - X)) = 1 - sum(X)

Either of these may still result in 1 if what is being subtracted
is less than .Machine$double.eps.

However, in the particular type of application you describe,

  1 - (1 - x)^n = n*x to first order
  1 - prod((1 - X)) = sum(X) to first order

You will just have to work out what will give you a sensible answer.
Basically, you are trying to operate beyond the limits of precision
of R, and so will need to re-cast your question in alternative terms
which will yield an adequately precise result.

Hoping this helps,
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 21-May-09   Time: 15:59:47
-- XFMail --

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


[R] Matrix sum

2009-05-21 Thread daniele riggi
Someone knows the existence of a function to sum the elements of the same
place A[i,j] B[i,j] of a matrix?thank you


-- 
Dr. Daniele Riggi, PhD student
University of Milano-Bicocca
Department of Statistics
Building U7, Via Bicocca degli Arcimboldi, 8
20126 Milano, Italy
cell. +39 328 3380690
mailto: daniele.ri...@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] Matrix sum

2009-05-21 Thread Jorge Ivan Velez
Dear Daniele,
Try this:

A <- matrix(1:10,ncol=2)
B <- matrix(10:20,ncol=2)
A+B
#[,1] [,2]
#[1,]   11   21
#[2,]   13   23
#[3,]   15   25
#[4,]   17   27
#[5,]   19   29

HTH,

Jorge


On Thu, May 21, 2009 at 11:11 AM, daniele riggi wrote:

> Someone knows the existence of a function to sum the elements of the same
> place A[i,j] B[i,j] of a matrix?thank you
>
>
> --
> Dr. Daniele Riggi, PhD student
> University of Milano-Bicocca
> Department of Statistics
> Building U7, Via Bicocca degli Arcimboldi, 8
> 20126 Milano, Italy
> cell. +39 328 3380690
> mailto: daniele.ri...@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.
>

[[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] Matrix sum

2009-05-21 Thread Uwe Ligges



daniele riggi wrote:

Someone knows the existence of a function to sum the elements of the same
place A[i,j] B[i,j] of a matrix?thank you





Yes:

+


Uwe Ligges

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


Re: [R] Matrix sum

2009-05-21 Thread Jorge Ivan Velez
For this, you might want to take a look at the first example in ?Reduce.
HTH,

Jorge


On Thu, May 21, 2009 at 11:21 AM, daniele riggi wrote:

> Ok, I know this waybut if i have a lot of matrix, does a function exist to
> sum all of them elements by elements?
>
>
> 2009/5/21 Jorge Ivan Velez 
>
>
>> Dear Daniele,
>> Try this:
>>
>> A <- matrix(1:10,ncol=2)
>> B <- matrix(10:20,ncol=2)
>> A+B
>> #[,1] [,2]
>> #[1,]   11   21
>> #[2,]   13   23
>> #[3,]   15   25
>> #[4,]   17   27
>> #[5,]   19   29
>>
>> HTH,
>>
>> Jorge
>>
>>
>> On Thu, May 21, 2009 at 11:11 AM, daniele riggi 
>> wrote:
>>
>>> Someone knows the existence of a function to sum the elements of the same
>>> place A[i,j] B[i,j] of a matrix?thank you
>>>
>>>
>>> --
>>> Dr. Daniele Riggi, PhD student
>>> University of Milano-Bicocca
>>> Department of Statistics
>>> Building U7, Via Bicocca degli Arcimboldi, 8
>>> 20126 Milano, Italy
>>> cell. +39 328 3380690
>>> mailto: daniele.ri...@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.
>>>
>>
>>
>
>
> --
> Dr. Daniele Riggi, PhD student
> University of Milano-Bicocca
> Department of Statistics
> Building U7, Via Bicocca degli Arcimboldi, 8
> 20126 Milano, Italy
> cell. +39 328 3380690
> mailto: daniele.ri...@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] Product of 1 - probabilities

2009-05-21 Thread Duncan Murdoch

On 5/21/2009 10:15 AM, Mark Bilton wrote:

I am having a slight problem with probabilities.

To calculate the final probability of an event p(F), we can take the product of 
the chance that each independent event that makes p(F) will NOT occur.
So...
p(F) = 1- ( (1-p(A)) * (1-p(B)) * (1-p(C))...(1-p(x)) )

If the chance of an event within the product occurring remains the same, we can 
therefore raise this probability to a power of the number of times that event 
occurs.
e.g. rolling a dice p(A) = 1/6 of getting a 1...
p(F) = 1 - (1- (1/6))^z 
p(F) = 1 - (1-p(A))^z tells us the probabiltity of rolling a 1 'at least once' in z number of rolls.


So then to R...

if p(A) = 0.01; z = 4; p(F) = 0.039

obviously p(F) > p(A)

however the problem arises when we use very small numbers e.g. p(B) = 1 * 10^-30
R understands this value
However when you have 1-p(B) you get something very close to 1 as you 
expect...but R seems to think it is 1.
So when I calculate p(F) = 1 - (1-p(B))^z = 1 to the power anything equals 1 so 
p(F) = 0 and not just close to zero BUT zero.
It doesn't matter therefore if z = 1*10^1000, the answer is still zero !!

Obviously therefore now p(F) < p(B)

Is there any solution to my problem, e.g.
- is it a problem with the sum (-) ? ie could I change the number of bits the 
number understands (however it seems strange that it can hold it as a value 
close to 0 but not close to 1)
-or should I maybe use a function to calculate the exact answer ?


The problem is that R maintains about 15-16 decimal places of accuracy, 
and to that accuracy, 1- 1.e-30 is equal to 1.  You need to find a 
different formula, e.g.


(1-x)^z = exp(z * log(1-x)) = exp(z * log1p(-x))

So if you have z = 1.e20, and p(A) = 1.e-30, then

1 - (1-1.e-30)^1.e20 can be calculated in R as

1 - exp(1.e20 * log1p(-1.e-30))

which works out to 1.e-10.

Duncan Murdoch


-or something else

Any help greatly appreciated
Mark
-



  


_


[[alternative HTML version deleted]]

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


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


[R] help

2009-05-21 Thread daniele riggi
Someone knows the existence of a function to sum the elements of the same
place A[i,j] B[i,j] of a matrix?thank you


-- 
Dr. Daniele Riggi, PhD student
University of Milano-Bicocca
Department of Statistics
Building U7, Via Bicocca degli Arcimboldi, 8
20126 Milano, Italy
cell. +39 328 3380690
mailto: daniele.ri...@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] Matrix sum

2009-05-21 Thread daniele riggi
Ok, I know this waybut if i have a lot of matrix, does a function exist to
sum all of them elements by elements?


2009/5/21 Jorge Ivan Velez 

>
> Dear Daniele,
> Try this:
>
> A <- matrix(1:10,ncol=2)
> B <- matrix(10:20,ncol=2)
> A+B
> #[,1] [,2]
> #[1,]   11   21
> #[2,]   13   23
> #[3,]   15   25
> #[4,]   17   27
> #[5,]   19   29
>
> HTH,
>
> Jorge
>
>
> On Thu, May 21, 2009 at 11:11 AM, daniele riggi 
> wrote:
>
>> Someone knows the existence of a function to sum the elements of the same
>> place A[i,j] B[i,j] of a matrix?thank you
>>
>>
>> --
>> Dr. Daniele Riggi, PhD student
>> University of Milano-Bicocca
>> Department of Statistics
>> Building U7, Via Bicocca degli Arcimboldi, 8
>> 20126 Milano, Italy
>> cell. +39 328 3380690
>> mailto: daniele.ri...@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.
>>
>
>


-- 
Dr. Daniele Riggi, PhD student
University of Milano-Bicocca
Department of Statistics
Building U7, Via Bicocca degli Arcimboldi, 8
20126 Milano, Italy
cell. +39 328 3380690
mailto: daniele.ri...@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] Re placing a "+" in a string

2009-05-21 Thread Tom La Bone

I know this is easy, but I am stumped:
 
> gsub("0","K","8.00+00")
[1] "8.KK+KK"

> gsub("+","K","8.00+00")
Error in gsub("+", "K", "8.00+00") : invalid regular expression '+'
In addition: Warning message:
In gsub("+", "K", "8.00+00") :
  regcomp error:  'Invalid preceding regular expression'

I don't understand the error message. How do I go about replacing the "+" in
the string "8.00+00" with another character?

Tom




-- 
View this message in context: 
http://www.nabble.com/Replacing-a-%22%2B%22-in-a-string-tp23655515p23655515.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] help

2009-05-21 Thread Sarah Goslee
If your matrices are the same size, you can just add them. If they aren't the
same size, I'm not sure what you are trying to accomplish.

> mat1 <- matrix(1:9, nrow=3)
> mat1
 [,1] [,2] [,3]
[1,]147
[2,]258
[3,]369
> mat2 <- matrix(runif(9), nrow=3)
> mat2
   [,1]  [,2]  [,3]
[1,] 0.54837515 0.3476839 0.6298484
[2,] 0.25790633 0.3394281 0.3601670
[3,] 0.08251705 0.2288201 0.4216952
>
> mat1 + mat2
 [,1] [,2] [,3]
[1,] 1.548375 4.347684 7.629848
[2,] 2.257906 5.339428 8.360167
[3,] 3.082517 6.228820 9.421695



On Thu, May 21, 2009 at 11:08 AM, daniele riggi  wrote:
> Someone knows the existence of a function to sum the elements of the same
> place A[i,j] B[i,j] of a matrix?thank you
>
>


-- 
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] Product of 1 - probabilities

2009-05-21 Thread William Dunlap

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Bilton
> Sent: Thursday, May 21, 2009 7:15 AM
> To: r-help@r-project.org
> Subject: [R] Product of 1 - probabilities
> 
> 
> I am having a slight problem with probabilities.
> 
> To calculate the final probability of an event p(F), we can 
> take the product of the chance that each independent event 
> that makes p(F) will NOT occur.
> So...
> p(F) = 1- ( (1-p(A)) * (1-p(B)) * (1-p(C))...(1-p(x)) )
> 
> If the chance of an event within the product occurring 
> remains the same, we can therefore raise this probability to 
> a power of the number of times that event occurs.
> e.g. rolling a dice p(A) = 1/6 of getting a 1...
> p(F) = 1 - (1- (1/6))^z 
> p(F) = 1 - (1-p(A))^z tells us the probabiltity of rolling a 
> 1 'at least once' in z number of rolls.
> 
> So then to R...
> 
> if p(A) = 0.01; z = 4; p(F) = 0.039
> 
> obviously p(F) > p(A)
> 
> however the problem arises when we use very small numbers 
> e.g. p(B) = 1 * 10^-30
> R understands this value
> However when you have 1-p(B) you get something very close to 
> 1 as you expect...but R seems to think it is 1.
> So when I calculate p(F) = 1 - (1-p(B))^z = 1 to the power 
> anything equals 1 so p(F) = 0 and not just close to zero BUT zero.
> It doesn't matter therefore if z = 1*10^1000, the answer is 
> still zero !!
> 
> Obviously therefore now p(F) < p(B)
> 
> Is there any solution to my problem, e.g.
> - is it a problem with the sum (-) ? ie could I change the 
> number of bits the number understands (however it seems 
> strange that it can hold it as a value close to 0 but not close to 1)
> -or should I maybe use a function to calculate the exact answer ?
> -or something else
> 
> Any help greatly appreciated
> Mark

R uses double precision arithmetic, which gives you 52 binary
digits of precision (about 17 decimal digits), so 1.0-10.0^-30==1.0
even though 10.0^-30 is greater than 0.0 (you need to get down
to 10^-323 to make it 0.0 because there are 11 binary digits for
the exponent used to scale the value).

To work around this you can work on a log scale.  The R functions
log1p(x) and expm1(x) compute the much better approximations
to the real functions log(1+x) and exp(x)-1, respectively, than do
the R expressions log(1+x) and exp(x)-1 when x is very close to 0.
E.g., 
> pB <- 1e-30 # 1*10^-30
> exp(100 * log1p(-pB))
[1] 1
> exp(100 * log1p(-pB))-1
[1] 0
> expm1(100 * log1p(-pB))
[1] -1e-28

You have another problem: you want z=10^1000, which is infinite
in double precision arithmetic.  You can take logs again to deal
with this or do some more analysis.

Also, if you are computing your basic pB and pF from R's p
family of functions, they all have arguments to let you get the upper
tail probabilities and output on a log scale.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 

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


Re: [R] Re placing a "+" in a string

2009-05-21 Thread Romain Francois

Tom La Bone wrote:

I know this is easy, but I am stumped:
 
  

gsub("0","K","8.00+00")


[1] "8.KK+KK"

  

gsub("+","K","8.00+00")


Error in gsub("+", "K", "8.00+00") : invalid regular expression '+'
In addition: Warning message:
In gsub("+", "K", "8.00+00") :
  regcomp error:  'Invalid preceding regular expression'

I don't understand the error message. How do I go about replacing the "+" in
the string "8.00+00" with another character?
  

+ has a special meaning in regular expressions

gsub( "[+]", "K", "8.00+00" )
gsub( "\\+", "K", "8.00+00" )
gsub( "+", "K", "8.00+00", fixed = TRUE )

see ?regex for details

Tom
  



--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr

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


Re: [R] Product of 1 - probabilities

2009-05-21 Thread Ted Harding
On 21-May-09 14:45:20, Gabor Grothendieck wrote:
> There are several arbitrary precision packages available: gmp (an
> interface to the GNU multi-precision library on CRAN) and
> bc (an R interface to the bc arbitrary precision calculator):
> http://r-bc.googlecode.com
> 
> There are also packages providing R interfaces to two computer
> algebra systems and they both support not only arbitrary
> precision but also exact calculation:
> 
> http://rsympy.googlecode.com
> http://ryacas.googlecode.com
> 
>> library(bc)
>> 1 - (1-10^-75)^10
> [1] 0
>> bc("1 - (1-10^-75)^10")
> [1]
> ".00
> 000100"

Thanks for pointing this out, Gabor! In particular, bc is something
I often use (but on its own). It is good to know that R can connect
with it.

However, while your call above will indeed return an adequate answer
for 1 - (1-10^-75)^10, and can be assigned numerically by, say,

  w <- as.numeric(bc("1 - (1-10^-75)^10"))

this still does not let Mark off the hook of verifying that he will,
in the end, get a sensible answer. If this calculation were part of
a more elaborate computation in which, say, some formula called for
(1-w), then that would still evaluate to 1, with possible dire results.

While plain algebraic expressions can easily be evaluated in bc, its
repertoire of mathematical functions is limited. No doubt the other
mathematical packages you mention have much richer resources; but for
anything complicated requiring their use I would probably go for
working externally with such a package. However, that may be a naive
view, since I have not tried the R interfaces!

Nevertheless, I would still strongly recommend doing some analysis
of the expressions in a computation when limits of precision are an
issue, since often a simple expression can be obtained which, in R,
would give adequate results.

Ted.


> On Thu, May 21, 2009 at 10:15 AM, Mark Bilton 
> wrote:
>>
>> I am having a slight problem with probabilities.
>>
>> To calculate the final probability of an event p(F), we can take the
>> product of the chance that each independent event that makes p(F) will
>> NOT occur.
>> So...
>> p(F) = 1- ( (1-p(A)) * (1-p(B)) * (1-p(C))...(1-p(x)) )
>>
>> If the chance of an event within the product occurring remains the
>> same, we can therefore raise this probability to a power of the number
>> of times that event occurs.
>> e.g. rolling a dice p(A) = 1/6 of getting a 1...
>> p(F) = 1 - (1- (1/6))^z
>> p(F) = 1 - (1-p(A))^z tells us the probabiltity of rolling a 1 'at
>> least once' in z number of rolls.
>>
>> So then to R...
>>
>> if p(A) = 0.01; z = 4; p(F) = 0.039
>>
>> obviously p(F) > p(A)
>>
>> however the problem arises when we use very small numbers e.g. p(B) =
>> 1 * 10^-30
>> R understands this value
>> However when you have 1-p(B) you get something very close to 1 as you
>> expect...but R seems to think it is 1.
>> So when I calculate p(F) = 1 - (1-p(B))^z = 1 to the power anything
>> equals 1 so p(F) = 0 and not just close to zero BUT zero.
>> It doesn't matter therefore if z = 1*10^1000, the answer is still zero
>> !!
>>
>> Obviously therefore now p(F) < p(B)
>>
>> Is there any solution to my problem, e.g.
>> - is it a problem with the sum (-) ? ie could I change the number of
>> bits the number understands (however it seems strange that it can hold
>> it as a value close to 0 but not close to 1)
>> -or should I maybe use a function to calculate the exact answer ?
>> -or something else
>>
>> Any help greatly appreciated
>> Mark
>> -
>>
>>
>>
>>
>>
>> _
>>
>>
>> _ _ _ _[[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.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 21-May-09   Time: 16:39:16
-- XFMail --

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


Re: [R] Re placing a "+" in a string

2009-05-21 Thread Jorge Ivan Velez
Dear Tom,
Use "\\" before "+":

gsub("\\+","K","8.00+00")
[1] "8.00K00"

See ?regex.

HTH,

Jorge


On Thu, May 21, 2009 at 11:45 AM, Tom La Bone wrote:

>
> I know this is easy, but I am stumped:
>
> > gsub("0","K","8.00+00")
> [1] "8.KK+KK"
>
> > gsub("+","K","8.00+00")
> Error in gsub("+", "K", "8.00+00") : invalid regular expression '+'
> In addition: Warning message:
> In gsub("+", "K", "8.00+00") :
>  regcomp error:  'Invalid preceding regular expression'
>
> I don't understand the error message. How do I go about replacing the "+"
> in
> the string "8.00+00" with another character?
>
> Tom
>
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Replacing-a-%22%2B%22-in-a-string-tp23655515p23655515.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Re placing a "+" in a string

2009-05-21 Thread jim holtman
You need to escape the '+' since it is used in regular expressions:

>  gsub("\\+","K","8.00+00 ")
[1] "8.00K00"
>


On Thu, May 21, 2009 at 11:45 AM, Tom La Bone wrote:

>
> I know this is easy, but I am stumped:
>
> > gsub("0","K","8.00+00")
> [1] "8.KK+KK"
>
> > gsub("+","K","8.00+00")
> Error in gsub("+", "K", "8.00+00") : invalid regular expression '+'
> In addition: Warning message:
> In gsub("+", "K", "8.00+00") :
>  regcomp error:  'Invalid preceding regular expression'
>
> I don't understand the error message. How do I go about replacing the "+"
> in
> the string "8.00+00" with another character?
>
> Tom
>
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Replacing-a-%22%2B%22-in-a-string-tp23655515p23655515.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] Re placing a "+" in a string

2009-05-21 Thread Gabor Grothendieck
Here are a few ways:

gsub("[+]", "K", "8.00+00")
gsub("\\+", "K", "8.00+00")
gsub("+", "K", "8.00+00", fixed = TRUE)

Note that with gsubfn you can replace several at once as
it is like gsubfn but can take a replacement translation list:

library(gsubfn)
gsubfn(".", list("+" = " plus", "0" = " zero"), "8.00+00")
# gives this: "8. zero zero plus zero zero"

On Thu, May 21, 2009 at 11:45 AM, Tom La Bone  wrote:
>
> I know this is easy, but I am stumped:
>
>> gsub("0","K","8.00+00")
> [1] "8.KK+KK"
>
>> gsub("+","K","8.00+00")
> Error in gsub("+", "K", "8.00+00") : invalid regular expression '+'
> In addition: Warning message:
> In gsub("+", "K", "8.00+00") :
>  regcomp error:  'Invalid preceding regular expression'
>
> I don't understand the error message. How do I go about replacing the "+" in
> the string "8.00+00" with another character?
>
> Tom
>
>
>
>
> --
> View this message in context: 
> http://www.nabble.com/Replacing-a-%22%2B%22-in-a-string-tp23655515p23655515.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] subsetting of a data.frame

2009-05-21 Thread culpritNr1

Hello everybody

How do you subset a data.frame when your boundaries are a combination of
explicit and implicit limits?

For example, I need to subset from the fourth (explicit) to the last
(implicit) column a data.frame named A.

In other languages you would do A[ , 4:]. Would anybody show me the R's way?

Thank you,

Your culprit


-- 
View this message in context: 
http://www.nabble.com/subsetting-of-a-data.frame-tp23655883p23655883.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] subsetting of a data.frame

2009-05-21 Thread Sarah Goslee
You can for example use ncol(A) to get the number of columns.

Sarah

On Thu, May 21, 2009 at 12:06 PM, culpritNr1  wrote:
>
> Hello everybody
>
> How do you subset a data.frame when your boundaries are a combination of
> explicit and implicit limits?
>
> For example, I need to subset from the fourth (explicit) to the last
> (implicit) column a data.frame named A.
>
> In other languages you would do A[ , 4:]. Would anybody show me the R's way?
>
> Thank you,
>
> Your culprit
>
>


-- 
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] combining xYplot with map

2009-05-21 Thread Greg Snow
For future reference, you may want to look at the symbols function instead of 
points (for this example points works, but symbols gives more 
options/flexibility, the my.symbols function in the TeachingDemos package gives 
even more options for adding symbols to a plot).

Hope this helps,

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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of eric.archer
> Sent: Wednesday, May 20, 2009 4:39 PM
> To: r-help@r-project.org
> Subject: Re: [R] combining xYplot with map
> 
> I'll retract my request for help.  I managed to solve the problem by
> calling map followed by a call to points after rescaling the cex.  Its
> the kind of solution that deserves a head-slap.
> 
> library(Hmisc)
> library(maps)
> 
> sample.data <- data.frame(lat = c(12.1667, 14.6333, -6.874, 2.6167,
> 14.6833,
> 11.2, 3.2667, 11.4167, -13.8623, 13.1667), lon = c(-126.25, -103.4667,
> -88.4572, -93.65, -97.7, -88.65, -111.0167, -119.7333, -100.0748,
> -108.0333), exp.index = c(23.6266244576543, 2.06824648038330,
> 0, 1.46378849121688, 24.1824663424805, 0, 0.364600074527829,
> 4.468039274638, 0.543833744085446, 18.2301918845932))
> 
> xlim <- c(-150, -80)
> ylim <- c(-5, 30)
> cex.range <- c(1, 5)
> exp.range <- range(sample.data$exp.index)
> exp.cex <- diff(cex.range) * sample.data$exp.index / exp.range[2] +
> cex.range[1]
> map("world", fill = TRUE, col = "gray", xlim = xlim, ylim = ylim)
> points(sample.data$lon, sample.data$lat, pch = 21, cex = exp.cex)
> 
> 
> 
> eric.archer wrote:
> > I'm using xYplot to create a bubble plot of values that I'd like to
> > visualize on top of a filled-in map of the coast, but I'm too much of
> > a lattice (which I understand xYplot is built on) and mapping newbie
> > to figure out how to begin to make this happen.  Below is some sample
> > code that doesn't work but illustrates my goal.  Any pointers anyone
> > has would be much appreciated.  I'm using R v2.9.0 on Windows with
> > Hmisc v3.6-0 and maps v2.1-0.
> >
> > Cheers,
> > eric
> >
> > library(Hmisc)
> > library(maps)
> >
> > sample.data <- data.frame(lat = c(12.1667, 14.6333, -6.874, 2.6167,
> > 14.6833,
> > 11.2, 3.2667, 11.4167, -13.8623, 13.1667), lon = c(-126.25, -
> 103.4667,
> > -88.4572, -93.65, -97.7, -88.65, -111.0167, -119.7333, -100.0748,
> > -108.0333), exp.index = c(23.6266244576543, 2.06824648038330,
> > 0, 1.46378849121688, 24.1824663424805, 0, 0.364600074527829,
> > 4.468039274638, 0.543833744085446, 18.2301918845932))
> >
> > xlim <- c(-150, -80)
> > ylim <- c(-5, 30)
> > print(xYplot(lat ~ lon, data = sample.data, size =
> sample.data$exp.index,
> > xlim = xlim, ylim = ylim
> > ))
> > map("world", fill = TRUE, col = "gray", xlim = xlim, ylim = ylim, add
> > = TRUE)
> >
> 
> --
> 
> Eric Archer, Ph.D.
> Southwest Fisheries Science Center
> National Marine Fisheries Service
>  North Torrey Pines Court
> La Jolla, CA 92037-1022
> 858-546-7121 (work)
> 858-546-7003 (FAX)
> 
> ETP Cetacean Assessment Program: http://swfsc.noaa.gov/prd-etp.aspx
> Population ID Program: http://swfsc.noaa.gov/prd-popid.aspx
> 
> 
> "Innocence about Science is the worst crime today."
>- Sir Charles Percy Snow
> 
> "Lighthouses are more helpful than churches."
>- Benjamin Franklin
> 
>"...but I'll take a GPS over either one."
>- John C. "Craig" George
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] RES: help

2009-05-21 Thread Leandro Marino
> a <- matrix(c(1:4),ncol=2)

> b <- matrix(c(5:8),ncol=2)

> a
 [,1] [,2]
[1,]13
[2,]24

> b
 [,1] [,2]
[1,]57
[2,]68

> a+b
 [,1] [,2]
[1,]6   10
[2,]8   12


Atenciosamente,
Leandro Lins Marino
Centro de Avaliação
Fundação CESGRANRIO
Rua Santa Alexandrina, 1011 - 2º andar
Rio de Janeiro, RJ - CEP: 20261-903
R (21) 2103-9600 R.:236 
  (21) 8777-7907
( lean...@cesgranrio.org.br

"Aquele que suporta o peso da sociedade
é precisamente aquele que obtém
 as menores vantagens". (SMITH, Adam)

  Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO 
AMBIENTE 

Esta mensagem, incluindo seus anexos, pode conter informacoes privilegiadas 
e/ou de carater confidencial, nao podendo ser retransmitida sem autorizacao do 
remetente. Se voce nao e o destinatario ou pessoa autorizada a recebe-la, 
informamos que o seu uso, divulgacao, copia ou arquivamento sao proibidos. 
Portanto, se você recebeu esta mensagem por engano, por favor, nos informe 
respondendo imediatamente a este e-mail e em seguida apague-a.

-Mensagem original-
De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Em nome 
de daniele riggi
Enviada em: quinta-feira, 21 de maio de 2009 12:08
Para: r-help@r-project.org
Assunto: [R] help

Someone knows the existence of a function to sum the elements of the same
place A[i,j] B[i,j] of a matrix?thank you


-- 
Dr. Daniele Riggi, PhD student
University of Milano-Bicocca
Department of Statistics
Building U7, Via Bicocca degli Arcimboldi, 8
20126 Milano, Italy
cell. +39 328 3380690
mailto: daniele.ri...@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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] subsetting of a data.frame

2009-05-21 Thread Jorge Ivan Velez
Dear  culprit
Try this:
A[ , 4:ncol(A) ]

HTH,

Jorge



On Thu, May 21, 2009 at 12:06 PM, culpritNr1  wrote:

>
> Hello everybody
>
> How do you subset a data.frame when your boundaries are a combination of
> explicit and implicit limits?
>
> For example, I need to subset from the fourth (explicit) to the last
> (implicit) column a data.frame named A.
>
> In other languages you would do A[ , 4:]. Would anybody show me the R's
> way?
>
> Thank you,
>
> Your culprit
>
>
> --
> View this message in context:
> http://www.nabble.com/subsetting-of-a-data.frame-tp23655883p23655883.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] subsetting of a data.frame

2009-05-21 Thread culpritNr1

Hi Sarah and Jorge,

ncol(). How elegant!

Thank you.





Jorge Ivan Velez wrote:
> 
> Dear  culprit
> Try this:
> A[ , 4:ncol(A) ]
> 
> HTH,
> 
> Jorge
> 
> 
> 
> On Thu, May 21, 2009 at 12:06 PM, culpritNr1 
> wrote:
> 
>>
>> Hello everybody
>>
>> How do you subset a data.frame when your boundaries are a combination of
>> explicit and implicit limits?
>>
>> For example, I need to subset from the fourth (explicit) to the last
>> (implicit) column a data.frame named A.
>>
>> In other languages you would do A[ , 4:]. Would anybody show me the R's
>> way?
>>
>> Thank you,
>>
>> Your culprit
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/subsetting-of-a-data.frame-tp23655883p23655883.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/subsetting-of-a-data.frame-tp23655883p23656179.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] Rpart - best split selection for class method and Gin

2009-05-21 Thread Terry Therneau
 I would suggest looking at the documentation found in Technical Report #61 in 
our department series.
 
 http://mayoresearch.mayo.edu/mayo/research/biostat/
 
The formulas for priors, losses, etc in Gini splitting are such that I can't 
deduce them myself from the source code (and I wrote it), but need to have the
document.

Terry T.

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


Re: [R] Loop avoidance and logical subscripts

2009-05-21 Thread retama

Patrick Burns kindly provided an article about this issue called 'The R
Inferno'. However, I will expand a little bit my question because I think it
is not clear and, if I coud improve the code it will be more understandable
to other users reading this messages when I will paste it :)

In my example, I have a dataframe with several hundreds of DNA sequences in
the column data$sequences (each value is a long string written in an
alphabet of four characters, which are A, C, T and G). I'm trying to know
parameter number of Gs plus Cs over the total  [G+C/(A+T+C+G)] in each
sequence. In example, data$sequence [1] is something like AATTCCCGG but
a little bit longer, and, its G+C content is 0.69 . I need to compute a
vector with all G+C contents (in my example, in data$GCsequence, in which
data$GCsequence[1] is 0.69).

So the question was if making a loop and a combination of values with c() or
cbind() or with logical subscripts is ok or not. And which approach should
produce better results in terms of efficiency (my script goes really slow).

Thank you,

Retama


-- 
View this message in context: 
http://www.nabble.com/Loop-avoidance-and-logical-subscripts-tp23652935p23656703.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] Changelog for the survival package

2009-05-21 Thread Terry Therneau
>  Several changes in print.survfit, plot.survfit and seemingly in the 
> structure 
> of ratetabels effect some of my syntax files.
> Is there somewhere a documentation of these changes, besides the code itself?

 I agree, the Changelog.09 file is not as comprehensive as one would like.  
Specific comments:

 1. The ratetables were recently changed to accomodate a new option.  I thought 
that I had made them completely backwards compatable with the old -- please let 
me know specifics if I overlooked something.
  The routines that make use of the rate tables can now use multiple date 
types, 
but they still support the older 'date' class.
  
  2. My local code and the R code had gotton badly out of sync, I spent a 
substantial fraction of my evenings re-merging them for over a year.  2/3 of 
the 
changes were disjoint improvments in the two trees, these were easy to merge.  
The hardest were survfit and its print/plot methods and some summary methods, 
where both of us had worked towards the same goal but in not quite the same 
way. 
  I had made 3x as many updates to survfit as the R tree, so used my (Mayo) 
code 
as the base, almost all the others stayed closer to the R side.
  Feel free to ask me direct questions about any feature or change.  I can't 
necessarily promise fast resolution, but will try.
  
  3. I don't understand putting legend or title options into a plot method, 
since a separate call after the plot is so much more flexible.  They got pushed 
to the bottom of my change list, and then completely forgotton. 
  
  4. In the last few weeks issues with anova.coxph, and 
predict.coxph/factors/newdata were raised.  The fixes were added to Rforge last 
night, and include 2 new test cases to avoid future mishaps.
  
   Terry T.

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


Re: [R] Loop avoidance and logical subscripts

2009-05-21 Thread Martin Morgan

retama wrote:

Patrick Burns kindly provided an article about this issue called 'The R
Inferno'. However, I will expand a little bit my question because I think it
is not clear and, if I coud improve the code it will be more understandable
to other users reading this messages when I will paste it :)

In my example, I have a dataframe with several hundreds of DNA sequences in
the column data$sequences (each value is a long string written in an
alphabet of four characters, which are A, C, T and G). I'm trying to know
parameter number of Gs plus Cs over the total  [G+C/(A+T+C+G)] in each
sequence. In example, data$sequence [1] is something like AATTCCCGG but
a little bit longer, and, its G+C content is 0.69 . I need to compute a
vector with all G+C contents (in my example, in data$GCsequence, in which
data$GCsequence[1] is 0.69).


A very efficient way to do this is

  library(Biostrings)
  dna = DNAStringSet(data$sequence)
  alf = alphabetFrequency(dna, baseOnly=TRUE)
  gc = rowSums(alf[,c("G", "C")]) / rowSums(alf)

this takes about .8 second for 3 million 36mers, for instance. 
Biostrings is installed with


  source('http://bioconductor.org/biocLite.R')
  biocLite('Biostrings')

Martin



So the question was if making a loop and a combination of values with c() or
cbind() or with logical subscripts is ok or not. And which approach should
produce better results in terms of efficiency (my script goes really slow).

Thank you,

Retama





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

Location: Arnold Building M1 B861
Phone: (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.


Re: [R] Loop avoidance and logical subscripts

2009-05-21 Thread Ted Harding
On 21-May-09 16:56:23, retama wrote:
> Patrick Burns kindly provided an article about this issue called
> 'The R Inferno'. However, I will expand a little bit my question
> because I think it is not clear and, if I coud improve the code
> it will be more understandable to other users reading this messages
> when I will paste it :)
> 
> In my example, I have a dataframe with several hundreds of DNA
> sequences in the column data$sequences (each value is a long string
> written in an alphabet of four characters, which are A, C, T and G).
> I'm trying to know parameter number of Gs plus Cs over the total 
> [G+C/(A+T+C+G)] in each sequence. In example, data$sequence [1] is
> something like AATTCCCGG but a little bit longer, and, its G+C
> content is 0.69 . I need to compute a vector with all G+C contents
> (in my example, in data$GCsequence, in which data$GCsequence[1] is
> 0.69).
> 
> So the question was if making a loop and a combination of values with
> c() or cbind() or with logical subscripts is ok or not. And which
> approach should produce better results in terms of efficiency (my
> script goes really slow).
> 
> Thank you,
> Retama

Perhaps the following could be the basis of your code for the bigger
problem:

  S <- unlist(strsplit("AATTCCCGG",""))
  S
#  [1] "A" "A" "T" "T" "C" "C" "C" "G" "G" "G" "G" "G" "G"
  (sum((S=="C")|(S=="G")))
# [1] 9
  (sum((S=="C")|(S=="G")))/length(S)
# [1] 0.6923077

You could build a function on those lines, to evaluate what you
want for any given string; and then apply() it to the elements
(which are the separate character strings) of data$sequences
(which is presumably a vector of character strings).

Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 21-May-09   Time: 18:18:24
-- XFMail --

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


Re: [R] How can I estimate a Box-Cox function with R?

2009-05-21 Thread Greg Snow
Have you looked at the boxcox function in the MASS package?  That may do what 
you want.

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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Ikerne del Valle
> Sent: Thursday, May 21, 2009 4:29 AM
> To: fernando.tus...@ehu.es
> Cc: r-help@r-project.org
> Subject: [R] How can I estimate a Box-Cox function with R?
> 
> 
>   Dear Fernando and all:
> 
>   Thanks for your help. Now works. This is
> a training example to learn how to estimate a
> Box-Cox (right and/or left side transformations)
> with R (as LIMDEP does) in order to compare these
> estimations with the ones derived by applying
> NLS, ones the dependent variable has been divided
> by its geometric mean (see below) as suggested by
> (Zarembka (1974) and Spitzer (1984). However the
> example of the demand of money seems not to work.
> Any idea to face the error messages or how to
> estimate a Box-Cox function with R?
> 
>   Best regards,
>   Ikerne
> 
> library(nlrwr)
> r<-
> c(4.50,4.19,5.16,5.87,5.95,4.88,4.50,6.44,7.83,6.25,5.50,5.46,7.46,10.2
> 8,11.77,13.42,11.02,8.50,8.80,7.69)
> Lr<-log(r)
> M<-
> c(480.00,524.30,566.30,589.50,628.20,712.80,805.20,861.00,908.40,1023.1
> 0,1163.60,1286.60,1388.90,1497.90,1631.40,1794.40,1954.90,2188.80,2371.
> 70,2563.60)
> LM<-log(M)
> Y<-
> c(2208.30,2271.40,2365.60,2423.30,2416.20,2484.80,2608.50,2744.10,2729.
> 30,2695.00,2826.70,2958.60,3115.20,3192.40,3187.10,3248.80,3166.00,3277
> .70,3492.00,3573.50)
> LY<-log(Y)
> gmM<-exp((1/20)*sum(LM))
> GM<-M/gmM
> Gr<-r/gmM
> GY<-Y/gmM
> money<-data.frame(r,M,Y,Lr,LM,LY,GM,Gr,GY)
> attach(money)
> ols1<-lm(GM~r+Y)
> output1<-summary(ols1)
> coef1<-ols1$coefficients
> a1<-coef1[[1]]
> b11<-coef1[[2]]
> b21<-coef1[[3]]
> ols2<-lm(GM~Gr+GY)
> output2<-summary(ols2)
> coef2<-ols2$coefficients
> a2<-coef2[[1]]
> b12<-coef2[[2]]
> b22<-coef2[[3]]
> money.m1<-
> nls(GM~a+b*r^g+c*Y^g,data=money,start=list(a=a1,b=b11,g=1,c=b21))
> money.m2<-
> nls(GM~a+b*Gr^g+c*GY^g,data=money,start=list(a=a2,b=b12,g=1,c=b22))
> 
> 
>   Ikerne del Valle Erkiaga
>   Department of Applied Economics V
>   Faculty of Economic and Business Sciences
>   University of the Basque Country
>   Avda. Lehendakari Agirre, Nº 83
>   48015 Bilbao (Bizkaia) Spain
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] arrangement of crowded labels

2009-05-21 Thread Thomas Zumbrunn
> -Original Message-
> I'm looking for algorithms that assist in spreading out crowded labels, e.g.
> labels of points in a scatter plot, in order to obtain a nicer visual
> appearance and better legibility.
> 
> I'm probably just stuck because I didn't find the right key words for a
> successful search on the R websites or in the mailing list archives.

On Wednesday 20 May 2009, richard.cot...@hsl.gov.uk wrote:
> Try thigmophobe.labels in the plotrix package.

On Wednesday 20 May 2009, Greg Snow wrote:
> Look at the spread.labs and the dynIdentify and TkIdentify functions in the
> TeachingDemos package.

Thanks for your answers. This was almost what I was looking for, except that I 
would need something for a 2-dimensional context (my question was not specific 
enough).

Best wishes
/thomas

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 get remote ESS graphics to work?

2009-05-21 Thread Matthew Keller
Hi all,

I got a few comments offline. Here's the final of how to get graphics
remotely using ESS on a mac. It's working fine for us now.

1) change your /etc/sshd_config file. There is a line that reads:
#X11 Forwarding no
change this to:
X11 Forwarding yes
(note no # at start of line)

2) make sure that your .bash_profile files in the remote machine do
not explicitly set DISPLAY. These files live in the user root, i.e.,
~/ (which is the same as /Users//). If you see a line
names "DISPLAY" in this file, this could create problems because you
are explicitly telling X11 where to draw displays. I just erased the
lines in mine, which allows X11 to figure out where to draw displays.

3) Then, from within emacs, type
M-x ssh 
then type
-XC usern...@remote.machine.name 
the -X should begin x11 forwarding. The -C compresses the graphics
making the connection much faster

4) then just start R. Make sure to set your options() in R to use x11
rather than the default graphics device (which is quartz on the mac):
> options(device='x11')

5) now when you make graphics, they should appear on your x11 window.

These steps worked for us. Hopefully, they will provide some help to
other ESS Aquamacs Mac users who want to remotely get interactive
graphics. Best,

Matt



On Wed, May 20, 2009 at 5:07 PM, Matthew Keller  wrote:
> Hi all,
>
> I figured out how to get this to work. Not saying this is the best way
> to do it, but it is working for me. The only problem is that the
> graphics are very slow (several seconds to draw hist(rnorm(50))!)
>
> First, I changed both /etc/ssh_config and /etc/ssh_configd to allow
> X11 forwarding (i.e., emacs into those files, find the ForwardAgent
> and ForwardX11 lines, and change these from "no" to "yes").
>
> Then I used the -X option when ssh'ing into the remote machine:
>
> ssh -X myn...@remotecomp.
>
> Then I started R remotely. Within the remote R session, I changed the
> default graphics device from 'quartz' to 'x11':
> options(device='x11')
>
> That's it. It is working, but as I said, is surprisingly slow. Not
> sure why that is. Does anyone have more experience with graphics
> remotely? Are they typically slow, or is it my connection, or perhaps
> a setting?
>
> Best,
>
> Matt
>
>
>
> On Wed, May 20, 2009 at 3:13 PM, Matthew Keller  
> wrote:
>> Hi all,
>>
>> My graduate student is logging onto my macpro and running R through
>> ESS aquamacs (with Mx ssh and then  Mx ess-remote). Everything is
>> working fine until we get to graphing.
>>
>>  We are trying to give him the ability to look at graphics
>> interactively. The ESS manual is not too helpful: "If you run X11 (See
>> Section 13.3.2 [X11], page 68, X-windows) on both the local and remote
>> machines then you should be able to display the graphs locally by
>> setting the ‘DISPLAY’ environment variable appropriately."
>>
>> It's unclear what DISPLAY is appropriate. I have X11 forwarding set up
>> on my machine (the remote machine). When we try to create a graphic in
>> his ESS remote process, (e.g., hist(rnorm(50))), we get the following
>> error:
>> "Error in X11(...
>> unable to start device X11cairo
>> In addition: Warning message:
>> In x11(): unable to open connection to X11 display"
>>
>> Does anyone out there use interactive graphics on their ESS remote
>> sessions? If so, could you provide any help? We're really stuck and
>> just need a step-by-step from anyone who knows.
>>
>> Thank you,
>>
>> Matt
>>
>>
>>
>>
>> --
>> Matthew C Keller
>> Asst. Professor of Psychology
>> University of Colorado at Boulder
>> www.matthewckeller.com
>>
>
>
>
> --
> Matthew C Keller
> Asst. Professor of Psychology
> University of Colorado at Boulder
> www.matthewckeller.com
>



-- 
Matthew C Keller
Asst. Professor of Psychology
University of Colorado at Boulder
www.matthewckeller.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] NA when indexing vectors

2009-05-21 Thread Szilard
Hello:

Is there a more natural way to get all elements that satisfy a condition
when there are NAs in the sample?

> x=c(1,2,NA)

> x>=2
[1] FALSE  TRUENA

> x[x>=2]
[1]  2 NA ## I would expect here to get just "2"

> x[!is.na(x) & x>=2]   ## seems a bit cumbersome
[1] 2

Thanks,
Szilard

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


Re: [R] NA when indexing vectors

2009-05-21 Thread Jorge Ivan Velez
Hi,
Try:

which( x>=2 )

HTH,

Jorge


On Thu, May 21, 2009 at 2:28 PM, Szilard wrote:

> Hello:
>
> Is there a more natural way to get all elements that satisfy a condition
> when there are NAs in the sample?
>
> > x=c(1,2,NA)
>
> > x>=2
> [1] FALSE  TRUENA
>
> > x[x>=2]
> [1]  2 NA ## I would expect here to get just "2"
>
> > x[!is.na(x) & x>=2]   ## seems a bit cumbersome
> [1] 2
>
> Thanks,
> Szilard
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] size of point symbols

2009-05-21 Thread baptiste auguie

Dear list,

This might be a topic for r-devel but i may be missing something  
obvious.


I don't understand the rationale in the absolute sizes of the point  
symbols, and I couldn't find it documented. The example below uses  
Grid to check the size of the symbols against a square of 10mm x 10mm.



checkOneSymbol <- function(pch=0){
gTree(children=gList(
rectGrob(0.5, 0.5, width=unit(10, "mm"), height=unit(10,  
"mm"),

gp=gpar(lty=2, fill=NA, col=alpha("black", 0.5))),
pointsGrob(0.5, 0.5, size=unit(10, "mm"),pch=pch,
gp=gpar(col=alpha("red", 0.5)))
))

}
all.symbols <- lapply(0:23, checkOneSymbol)

pdf("symbols.pdf", height=1.2/2.54, width=24.2/2.54)

vp <- viewport(width=0.5, height=0.5, name="main")
pushViewport(vp)

pushViewport(viewport(layout=grid.layout(1, 24,
widths=unit(10, "mm"),
heights=unit(10, "mm"),
just="center")))

for(ii in 0:23){
pushViewport(viewport(layout.pos.col=ii+1, layout.pos.row=1))
grid.draw(all.symbols[[ii+1]])
upViewport(1)
}
dev.off()



What dictates the size of each symbol? (in other words, why is pch=21  
a circle of radius given in inches, while pch=0 is a cross of arms'  
length specified  in mm?)


Best regards,

baptiste


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Behavior of seq with vector from

2009-05-21 Thread Rowe, Brian Lee Yung (Portfolio Analytics)
Hello,

I want to use seq with multiple from values and am getting unexpected
(to me) behavior. I'm wondering if this behavior is intentional or not.

> seq(2, by=3, length.out=4)
[1]  2  5  8 11

> seq(3, by=3, length.out=4)
[1]  3  6  9 12

Now if I want the combined sequence, I thought I could pass in c(2,3),
and I get:
> seq(c(2,3), by=3, length.out=8)
[1]  2  6  8 12 14 18 20 24

However, the result is not what I expected (i.e. what I wanted):
[1]  2  3  5  6  8  9 11 12

It seems that this is a consequence of vector recycling during the
summation in seq.default:
  if (missing(to)) from + (0L:(length.out - 1L)) * by

To get the value I want, I am using the following code:
> sort(as.vector(apply(array(c(2,3)), 1, seq, by=3,length.out=4)))
[1]  2  3  5  6  8  9 11 12

So two questions:
1. Is seq designed/intended to be used with a vector from argument, and
is this the desired behavior?
2. If so, is there a cleaner way of implementing what I want?

Thanks,
Brian




--
This message w/attachments (message) may be privileged, ...{{dropped:27}}

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


Re: [R] arrangement of crowded labels

2009-05-21 Thread Greg Snow
The dynIdentify and TkIdentify functions work in 2 dimensions (and I think the 
thigmophope.labels does as well).  The algorithm in spread.labs could be 
adapted to 2 dimensions (the example shows a semi-2 dimensional approach) if 
you can define what you want to happen (can labels overplot the points?, how 
far from the points can they move?, etc.), other than toy examples, I think the 
interactive approach in (dyn/Tk)Identify is probably better than trying to work 
out all the rules to give to a fully automated function (unless you need 
something fully automatic).

Hope this helps,

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


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Thomas Zumbrunn
> Sent: Thursday, May 21, 2009 11:24 AM
> To: r-help@r-project.org
> Subject: Re: [R] arrangement of crowded labels
> 
> > -Original Message-
> > I'm looking for algorithms that assist in spreading out crowded
> labels, e.g.
> > labels of points in a scatter plot, in order to obtain a nicer visual
> > appearance and better legibility.
> >
> > I'm probably just stuck because I didn't find the right key words for
> a
> > successful search on the R websites or in the mailing list archives.
> 
> On Wednesday 20 May 2009, richard.cot...@hsl.gov.uk wrote:
> > Try thigmophobe.labels in the plotrix package.
> 
> On Wednesday 20 May 2009, Greg Snow wrote:
> > Look at the spread.labs and the dynIdentify and TkIdentify functions
> in the
> > TeachingDemos package.
> 
> Thanks for your answers. This was almost what I was looking for, except
> that I
> would need something for a 2-dimensional context (my question was not
> specific
> enough).
> 
> Best wishes
> /thomas
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Barchart in lattice - wrong order of groups, data labels on top of each other, and a legend question

2009-05-21 Thread Dimitri Liakhovitski
Deepayan, thank you very much for your response.
I have a general question. And please remember - I am really just a
beginner in R.
Is it truly the case that in order to build quite a basic bar chart
with value labels attached to it I have to be a true R graphics guru -
because the only way to do achieve what I am trying to achive is to
modify the underlying R function (panel.barchart)?
Really?

Dimitri


On Tue, May 19, 2009 at 7:53 PM, Deepayan Sarkar
 wrote:
> On Mon, May 18, 2009 at 11:47 AM, Dimitri Liakhovitski  
> wrote:
>> Hello!
>> I have a question about my lattice barchart that I am trying to build
>> in Section 3 below. I can't figure out a couple of things:
>> 1. When I look at the dataframe "test" that I am trying to plot, it
>> looks right to me (the group "Total" is always the first out of 5).
>> However, in the chart it is the last. Why?
>> 2. How can I make sure the value labels (on y) are not sitting on top
>> of each other but on top of the respective bar?
>> 3. Is there any way to make the legend group items horizontally as
>> opposed to now (vertically - taking up too much space)
>
> For 1 and 3, use
>
>         auto.key = list(points = FALSE,
>                         rectangles = TRUE,
>                         reverse.rows = TRUE,
>                         columns = 2,
>                         space = "bottom")
>
> From ?xyplot (under 'key'):
>
>               'reverse.rows' logical, defaulting to 'FALSE'.  If
>                    'TRUE', all components are reversed _after_ being
>                    replicated (the details of which may depend on the
>                    value of 'rep').  This is useful in certain
>                    situations, e.g. with a grouped 'barchart' with
>                    'stack = FALSE' with the categorical variable on
>                    the vertical axis, where the bars in the plot will
>                    usually be ordered from bottom to top, but the
>                    corresponding legend will have the levels from top
>                    to bottom (unless, of course, 'reverse.rows =
>                    TRUE').  Note that in this case, unless all columns
>                    have the same number or rows, they will no longer
>                    be aligned.
>
>               'columns' the number of columns column-blocks the key is
>                    to be divided into, which are drawn side by side.
>
>
> 2 is hard with a simple custom panel function, because you need to
> replicate some fairly involved calculations that are performed in
> panel.barchart. Your best bet is to start with a copy of
> panel.barchart, and then add calls to panel.text at suitable places.
>
> -Deepayan
>
>
>> Thanks a lot!
>> Dimitri
>>
>> ### Section 1: generates my data set "data" - just run: #
>>
>> N<-100
>> myset1<-c(1,2,3,4,5)
>> probs1<-c(.05,.10,.15,.40,.30)
>> myset2<-c(0,1)
>> probs2<-c(.65,.30)
>> myset3<-c(1,2,3,4,5,6,7)
>> probs3<-c(.02,.03,.10,.15,.20,.30,.20)
>>
>> group<-unlist(lapply(1:4,function(x){
>>        out<-rep(x,25)
>>        return(out)
>> }))
>> set.seed(1)
>> a<-sample(myset1, N, replace = TRUE,probs1)
>> a[which(rbinom(100,2,.01)==1)]<-NA
>> set.seed(12)
>> b<-sample(myset1, N, replace = TRUE,probs1)
>> b[which(rbinom(100,2,.01)==1)]<-NA
>> set.seed(123)
>> c<-sample(myset2, N, replace = TRUE,probs2)
>> set.seed(1234)
>> d<-sample(myset2, N, replace = TRUE,probs2)
>> set.seed(12345)
>> e<-sample(myset3, N, replace = TRUE,probs3)
>> e[which(rbinom(100,2,.01)==1)]<-NA
>> set.seed(123456)
>> f<-sample(myset3, N, replace = TRUE,probs3)
>> f[which(rbinom(100,2,.01)==1)]<-NA
>> data<-data.frame(group,a=a,b=b,c=c,d=d,e=e,f=f)
>> data["group"]<-lapply(data["group"],function(x) {
>>        x[x %in% 1]<-"Group 1"
>>        x[x %in% 2]<-"Group 2"
>>        x[x %in% 3]<-"Group 3"
>>        x[x %in% 4]<-"Group 4"
>>        return(x)
>> })
>> data$group<-as.factor(data$group)
>> lapply(data,table,exclude=NULL)
>>
>> tables<-lapply(data,function(x){
>>        out<-table(x)
>>        out<-prop.table(out)
>>        out<-round(out,3)*100
>>        return(out)
>> })
>> str(tables[2])
>>
>> # Section 2: Generating a list of tables with percentages to be
>> plotted in barcharts - just run: #
>>
>> listoftables<-list()
>> for(i in 1:(length(data)-1)) {
>>  listoftables[[i]]<-data.frame()
>> }
>> for(i in 1:length(listoftables)) {
>>    total<-table(data[[i+1]])
>>    groups<-table(data[[1]],data[[i+1]])
>>    total.percents<-as.data.frame(t(as.vector(round(total*100/sum(total),1
>>    groups.percents<-as.data.frame(t(apply(groups,1,function(x){
>>      out<-round(x*100/sum(x),1)
>>     return(out)
>>  })))
>>  names(total.percents)<-names(groups.percents)
>>  final.table<-rbind(total.percents,groups.percents)
>>  row.names(final.table)[1]<-"Total"
>>  final.table<-as.matrix(final.table)
>>  listoftables[[i]]<-final.table
>> }
>> names(listoftables)<-names(data)[2:(length(listoftables)+1)]
>>
>>
>> ### Section 3 - building the graph for the

[R] Marginal Effects in ordered logit

2009-05-21 Thread enrico secchi
Hi,
I am running an ordered logistic regression model with an interaction, using
the polr command. I am trying to find a way to calculate the marginal
effects and their significance in R. Does anybody have any suggestion?
Thank you!

Enrico

[[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] Axis Limits in Scatterplot3d

2009-05-21 Thread Alan
Hi,

How do you obtain the limits of the plotting region in a scatterplot3d
plot?  `par('usr')' does not seem to give sensible values, and that
vector only has 4 elements (not the expected 6).

Alan

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


Re: [R] Barchart in lattice - wrong order of groups, data labels on top of each other, and a legend question

2009-05-21 Thread Deepayan Sarkar
On Thu, May 21, 2009 at 12:58 PM, Dimitri Liakhovitski  wrote:

> Deepayan, thank you very much for your response.
> I have a general question. And please remember - I am really just a
> beginner in R.
> Is it truly the case that in order to build quite a basic bar chart
> with value labels attached to it I have to be a true R graphics guru -
> because the only way to do achieve what I am trying to achive is to
> modify the underlying R function (panel.barchart)?
> Really?

That's one way to look at it. The other interpretation is that the
author(s) of the functions you tried to use do not consider what you
are doing "basic".

If you are interested in simpler alternatives, I would suggest something like

barchart(Group ~ Percentage | factor(a), test, origin = 0,
 panel = function(x, y, ...) {
 panel.grid(h = 0, v = -1)
 panel.barchart(x, y, ...)
 ltext(x, y, labels=round(x, 0),
   cex=.7, col="black", font=2, pos=4)
 })

-Deepayan

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


Re: [R] Class for time of day?

2009-05-21 Thread Stavros Macrakis
On Wed, May 20, 2009 at 12:28 PM, Gabor Grothendieck <
ggrothendi...@gmail.com> wrote:

> There is a times class in the chron package.


Perfect!  Just what I was looking for.

On Wed, May 20, 2009 at 12:19 PM, jim holtman  wrote:

> If you want the hours from a POSIXct, here is one way of doing it...
>
> > y <- difftime(x, trunc(x, units='days'), units='hours')
>

Ah, trunc.POSIXt -- I missed that one, thanks.

It depends on what type of computations you want to do with it.  You can
> leave it as POSIXct and carry out a lot of them.  Can you specify what you
> want?
>

I am comparing irregular time series from different days, looking at the
differences in intraday patterns.  So I want to put them on a common 0-24h
scale and then do various kinds of plots and analyses, keeping the
conventional display form (10:30 etc.) when specific times display or
print.  It looks as though chron:::times combined with trunc.POSIXt pretty
much solves my problem, except that `times` ignores the time units:

> as.POSIXct('2009-3-23 12:23')-trunc(as.POSIXct('2009-3-23 12:23'),"day")
Time difference of 12.38333 hours
> times(as.POSIXct('2009-3-23 12:23')-trunc(as.POSIXct('2009-3-23
12:23'),"day"))
Time in days:<<< seems to treat difftimes as raw numbers!!
[1] 12.38333

Obviously I can work around this, but shouldn't `times` give an error when
it encounters an object of unknown class rather than unsafely using its
internal representation?  Of course, better still if `times` converted
correctly

In general, `times` has other inconsistent and peculiar behavior:

times(2) => Time in days: 2Allows specifying multi-day periods, OK
times(1.5) => Time in days: 1.5   Allows specifying fractional multi-day
periods, OK
times(0.5) => "12:00:00"   Inconsistent format compared to times(1.5)
times("18:00:00") + times("18:00:00")  => Time in days: 1.5, OK
times("36:00:00") => error  Why does it allow times(1.5) and
times("18:00:00") + times("18:00:00") to specify 1.5 days, but not 36 hours?
times(-0.5) => -0.5   Why doesn't it print Time in days: -0.5?
times("18:00:00")/times("1:00:00") => Time in days: 18Incorrect
dimensions; meaningless result -- should be dimensionless
times("18:00:00") * times("10:00:00") => 07:30:00 Incorrect dimensions;
meaningless result.
sin(times("18:00:00")) => 16:21:34 Meaningless result -- should be error

It's nice that R has a class system, but if code ignores the class

There is an article on dates and times in R News 4/1.
>

Thanks for the pointer.

  -s

[[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] Changelog for the survival package

2009-05-21 Thread Heinz Tuechler

Dear Terry,

first of all, thank you for your immense work. At the moment, I don't 
have a small reproducible example for the ratetable difficulty I 
have. I will work on it. Maybe the error message I get is of some 
information to you.


Error in match.ratetable(m[, rate], ratetable) :
  Data has a date type variable, but the reference ratetable is not 
a date for variable year


If I want to make str(survexp.ode) that is my ratetable, I get:
str(survexp.ode)
Error in `[.ratetable`(object, seq_len(iv.len)) : Invalid subscript
The same, however, is possible in version 2.34-1^

Try:
str(survexp.us)
Error in `[.ratetable`(object, seq_len(iv.len)) : Invalid subscript

But with unclass() it works
str(unclass(survexp.us))
 num [1:113, 1:2, 1:65] 1.58e-02 1.87e-03 3.01e-04 6.05e-05 1.52e-05 ...
 - attr(*, "dimnames")=List of 3
  ..$ : chr [1:113] "0-1d" "1-7d" "7-28d" "28-365d" ...
  ..$ : chr [1:2] "male" "female"
  ..$ : chr [1:65] "1940" "1941" "1942" "1943" ...
 - attr(*, "dimid")= chr [1:3] "age" "sex" "year"
 - attr(*, "type")= num [1:3] 2 1 4
 - attr(*, "cutpoints")=List of 3
  ..$ : num [1:113] 0 1 7 28 365 ...
  ..$ : NULL
  ..$ : int [1:65] -7305 -6939 -6574 -6209 -5844 -5478 -5113 -4748 
-4383 -4017 ...

 - attr(*, "summary")=function (R)
>

Concerning the legend, I fully aggree with you. It's just that I have 
several syntax files, where I made use of the legend parameters and 
so I noted the change. For these files I rebuilt your old plot.survfit().


Further I appreciate your new function survmean(). At the moment it 
seems to be intended as internal, and not documented in the help. 
Still, I use it to get the old form of the output and to get the 
output as an object. I think, with only right censored data, n.max 
and n.start are not informative.


To underline, I appreciate your changes, it's only a little difficult 
to recognize them correctly by trial and error.


Thanks,
Heinz

At 18:57 21.05.2009, Terry Therneau wrote:
>  Several changes in print.survfit, plot.survfit and seemingly in 
the structure

> of ratetabels effect some of my syntax files.
> Is there somewhere a documentation of these changes, besides the 
code itself?


 I agree, the Changelog.09 file is not as comprehensive as one would like.
Specific comments:

 1. The ratetables were recently changed to accomodate a new 
option.  I thought
that I had made them completely backwards compatable with the old -- 
please let

me know specifics if I overlooked something.
  The routines that make use of the rate tables can now use 
multiple date types,

but they still support the older 'date' class.

  2. My local code and the R code had gotton badly out of sync, I spent a
substantial fraction of my evenings re-merging them for over a 
year.  2/3 of the
changes were disjoint improvments in the two trees, these were easy 
to merge.

The hardest were survfit and its print/plot methods and some summary methods,
where both of us had worked towards the same goal but in not quite 
the same way.
  I had made 3x as many updates to survfit as the R tree, so used 
my (Mayo) code

as the base, almost all the others stayed closer to the R side.
  Feel free to ask me direct questions about any feature or change.  I can't
necessarily promise fast resolution, but will try.

  3. I don't understand putting legend or title options into a plot method,
since a separate call after the plot is so much more flexible.  They 
got pushed

to the bottom of my change list, and then completely forgotton.

  4. In the last few weeks issues with anova.coxph, and
predict.coxph/factors/newdata were raised.  The fixes were added to 
Rforge last

night, and include 2 new test cases to avoid future mishaps.

   Terry T.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 with gsub and date pattern

2009-05-21 Thread Tim Clark

Dear List,

I am having a problem using gsub to remove dates from a date/time string.

For example:

x<-c("5/31/2009 12:34:00","6/1/2009 1:14:00")

I would like to remove the date and have just the time.

I have tried:
gsub("[0-9+]/[0-9+]/[0-9+]","",x)

and various versions.  I think my problem is that the / is a special character 
and is telling it something that I don't mean.  I would appreciate any 
suggestions on how to proceed.

Thanks,

Tim



Tim Clark
Department of Zoology 
University of Hawaii

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


Re: [R] Barchart in lattice - wrong order of groups, data labels on top of each other, and a legend question

2009-05-21 Thread Dimitri Liakhovitski
Thank you very much, Deepayan!

On Thu, May 21, 2009 at 4:49 PM, Deepayan Sarkar
 wrote:
> On Thu, May 21, 2009 at 12:58 PM, Dimitri Liakhovitski  
> wrote:
>
>> Deepayan, thank you very much for your response.
>> I have a general question. And please remember - I am really just a
>> beginner in R.
>> Is it truly the case that in order to build quite a basic bar chart
>> with value labels attached to it I have to be a true R graphics guru -
>> because the only way to do achieve what I am trying to achive is to
>> modify the underlying R function (panel.barchart)?
>> Really?
>
> That's one way to look at it. The other interpretation is that the
> author(s) of the functions you tried to use do not consider what you
> are doing "basic".
>
> If you are interested in simpler alternatives, I would suggest something like
>
> barchart(Group ~ Percentage | factor(a), test, origin = 0,
>         panel = function(x, y, ...) {
>             panel.grid(h = 0, v = -1)
>             panel.barchart(x, y, ...)
>             ltext(x, y, labels=round(x, 0),
>                   cex=.7, col="black", font=2, pos=4)
>         })
>
> -Deepayan
>



-- 
Dimitri Liakhovitski
MarketTools, Inc.
dimitri.liakhovit...@markettools.com

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


Re: [R] help with gsub and date pattern

2009-05-21 Thread Marc Schwartz

On May 21, 2009, at 4:13 PM, Tim Clark wrote:



Dear List,

I am having a problem using gsub to remove dates from a date/time  
string.


For example:

x<-c("5/31/2009 12:34:00","6/1/2009 1:14:00")

I would like to remove the date and have just the time.

I have tried:
gsub("[0-9+]/[0-9+]/[0-9+]","",x)

and various versions.  I think my problem is that the / is a special  
character and is telling it something that I don't mean.  I would  
appreciate any suggestions on how to proceed.


Thanks,

Tim




Switch the '+' to outside the brackets:

> gsub("[0-9]+/[0-9]+/[0-9]+ ","",x)
[1] "12:34:00" "1:14:00"


A few other options:

# Use strsplit
> sapply(strsplit(x, split = " "), "[", 2)
[1] "12:34:00" "1:14:00"


# Return the pattern contained within the parens
# See ?regex
> gsub("^.* (.*)$", "\\1", x)
[1] "12:34:00" "1:14:00"


# Replace the characters up to the space with an empty vector
> gsub("^.* ", "", x)
[1] "12:34:00" "1:14:00"


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] help with gsub and date pattern

2009-05-21 Thread Tim Clark

Thanks for the help and the various options!  Putting the + outside the 
brackets worked, but I like the strsplit option.  Always nice to learn new 
functions!

Aloha,

Tim



--- On Thu, 5/21/09, Marc Schwartz  wrote:

> From: Marc Schwartz 
> Subject: Re: [R] help with gsub and date pattern
> To: "Tim Clark" 
> Cc: r-help@r-project.org
> Date: Thursday, May 21, 2009, 11:34 AM
> On May 21, 2009, at 4:13 PM, Tim
> Clark wrote:
> 
> > 
> > Dear List,
> > 
> > I am having a problem using gsub to remove dates from
> a date/time string.
> > 
> > For example:
> > 
> > x<-c("5/31/2009 12:34:00","6/1/2009 1:14:00")
> > 
> > I would like to remove the date and have just the
> time.
> > 
> > I have tried:
> > gsub("[0-9+]/[0-9+]/[0-9+]","",x)
> > 
> > and various versions.  I think my problem is that
> the / is a special character and is telling it something
> that I don't mean.  I would appreciate any suggestions
> on how to proceed.
> > 
> > Thanks,
> > 
> > Tim
> 
> 
> 
> Switch the '+' to outside the brackets:
> 
> > gsub("[0-9]+/[0-9]+/[0-9]+ ","",x)
> [1] "12:34:00" "1:14:00"
> 
> 
> A few other options:
> 
> # Use strsplit
> > sapply(strsplit(x, split = " "), "[", 2)
> [1] "12:34:00" "1:14:00"
> 
> 
> # Return the pattern contained within the parens
> # See ?regex
> > gsub("^.* (.*)$", "\\1", x)
> [1] "12:34:00" "1:14:00"
> 
> 
> # Replace the characters up to the space with an empty
> vector
> > gsub("^.* ", "", x)
> [1] "12:34:00" "1:14:00"
> 
> 
> 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] Re order variables in a dataframe

2009-05-21 Thread pgseye

Thanks everyone

-- 
View this message in context: 
http://www.nabble.com/Reorder-variables-in-a-dataframe-tp23647222p23660941.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] Naming a random effect in lmer

2009-05-21 Thread Leigh Ann Starcevich
Dear guRus:

I am using lmer for a mixed model that includes a random intercept for a 
set of effects that have the same distribution, Normal(0, sig2b).  This set 
of effects is of variable size, so I am using an as.formula statement to 
create the formula for lmer.  For example, if the set of random effects has 
dimension 8, then the lmer call is:

Zs<- paste("Z",1:mb,sep="")
Trendformula <-as.formula(paste("LogY ~ WYear + (1+WYear|Site) +  (1|", 
paste(paste(Zs,collapse="+"), ")")))
fit2.4a<-lmer(Trendformula, data = testsamp)

which, for mb=8, expands to:

fit1<-lmer(LogY ~ WYear + (1 | Site) + (1 | Year) + (1 | Z1+ Z2 + Z3 + Z4 + 
Z5 + Z6 + Z7 + Z8), data = testsamp)


I have no problems with this.  However, if the set of random effects has a 
dimension of 30, then the lmer call is:

fit2<-lmer(LogY ~ WYear + (1 | Site) + (1 | Year) + (1 | Z1+Z2 + Z3 + Z4 + 
Z5 + Z6 + Z7 + Z8 + Z9 + Z10 + Z11 + Z12 + Z13 + Z14 + Z15 +  Z16 + Z17 + 
Z18 + Z19 + Z20 + Z21 + Z22 + Z23 + Z24 + Z25 + Z26 + Z27 + Z28 + Z29+ 
Z30), data = testsamp)

In this case, I get an error because the name "Z1+Z2 + Z3 + Z4 + Z5 + Z6 + 
Z7 + Z8 + Z9 + Z10 + Z11 + Z12 + Z13 + Z14 + Z15 +  Z16 + Z17 + Z18 + Z19 + 
Z20 + Z21 + Z22 + Z23 + Z24 + Z25 + Z26 + Z27 + Z28 + Z29+ Z30" is too long 
to print in the output.   Is there any way to name the random effect in 
lmer so that the shorter (and more descriptive) name may be used and the 
error avoided?   Or is there a way to combine these into a single variable 
prior to the lmer function call?  In SAS, I am able to parameterize these 
as a Toeplitz structure with bandwidth 1.

Thanks for any help.

Leigh Ann Starcevich
Doctoral student
Oregon State University
Corvallis, Oregon
[[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] vcd package --- change layout of plot

2009-05-21 Thread Prew, Paul
Hello,

I'm trying to use the vcd package to analyze survey data.  Expert judges
ranked possible features for product packaging.  Seven features were
listed, and 19 judges split between 2 cities ranked them.

The following code (1) works, but the side-by-side plots for Cities PX,
SF are shrunk too much.  Stacking PX on top of SF would make for a
better plot.  (I could switch the order of Feature and Rank dimensions,
and go with the default side-by-side, but would prefer not to).

(1)
cotabplot(~ Rank + Feature| Cities, data = Pack.dat, gp = shading_max,
rot_labels = c(90, 0, 0, 0),just_labels = c("left", "left", 
"left", "right"),set_varnames = c(Feature = ""))

Reading the vcd help, I got lost trying to understand the
panel-generating parameters I should use.  My best guess was below (2),
but gave an error message.  Clearly, I don't know what the paneling is
asking for.  This is where I would like some advice, if anyone is
familiar with vcd.

(2)
  Tried to change the layout of trellis plot from horizontal to
vertical
Pack.mos<-mosaic(~Feature + Rank, data = Pack.tab, gp = shading_max,
rot_labels = c(0, 0, 0, 0),just_labels = c("left", "left", "left",
"right"),set_varnames = c(Feature = ""))   
## attempt to create an object for panel argument in cotabplot function

pushViewport(viewport(layout = grid.layout(ncol = 1)))
pushViewport(viewport(layout.pos.row = 1))
## tell vcd to change the default layout, and what to put in the top
plot

cotabplot(~ Feature + Rank | Cities, data = Pack.dat, panel = Pack.mos,
Pack.dat[["PX"]], gp = shading_max, rot_labels = c(0, 0, 0, 0))
## create mosaic plot that's conditional on Cities;  first plot Cities =
PX
## panel argument is an attempt to modify an example in the vcd help
file

popViewport()
## create the graphic

Error:  Cannot pop the top-level viewport (grid and graphics output
mixed?)

# no point in gong on to code the plot for layout.pos.row = 2

> str(Pack.tab)
Error in `[.structable`(x, i, args[[2]]) : subscript out of bounds
> class(Pack.tab)
[1] "structable" "ftable"
> dim(Pack.tab)
[1] 7 2 7

  Cities PX SF
Rank Feature  
1Flexible 2  0
 Integrate.Probes 1  2
 Large/heavy  1  0
 Lockout  0  1
 Recyclable   3  5
 Rigid0  0
 Small/light  2  1
2Flexible 1  6
 Integrate.Probes 2  0
 Large/heavy  1  1
 Lockout  1  0
 Recyclable   2  0
 Rigid1  0
 Small/light  2  2
3Flexible 1  1
 Integrate.Probes 3  0
 Large/heavy  1  1
 Lockout  2  1
 Recyclable   1  3
 Rigid0  0
 Small/light  0  3
4Flexible 3  0
 Integrate.Probes 0  2
 Large/heavy  0  0
 Lockout  2  2
 Recyclable   0  1
 Rigid1  2
 Small/light  3  2
5Flexible 1  1
 Integrate.Probes 1  1
 Large/heavy  0  3
 Lockout  0  2
 Recyclable   2  0
 Rigid3  1
 Small/light  2  1
6Flexible 0  1
 Integrate.Probes 1  3
 Large/heavy  3  2
 Lockout  3  1
 Recyclable   0  0
 Rigid2  2
 Small/light  0  0
7Flexible 1  0
 Integrate.Probes 1  1
 Large/heavy  3  2
 Lockout  1  2
 Recyclable   1  0
 Rigid2  4
 Small/light  0  0



> sessionInfo()
R version 2.9.0 RC (2009-04-10 r48318) 
i386-pc-mingw32
locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

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

[8] methods   base 

other attached packages:
 [1] relimp_1.0-1   vcd_1.2-4  colorspace_1.0-0
MASS_7.2-46   
 [5] RSiteSearch_0.1-5  brew_1.0-3 lme4_0.999375-30
Matrix_0.999375-26
 [9] lattice_0.17-22Rcmdr_1.4-9car_1.2-13

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


If someone can give advice on stacking the two cities' plots, I would be
grateful. 

Thanks, Paul
CONFIDENTIALITY NOTICE: =\ \ This e-mail communication a...{{dropped:12}}

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

2009-05-21 Thread Michael
Could anybody point me to the latest status of the most user-friendly
debugger in R?

How I wish I don't have to stare at my (long) code for ages and stuck...

Thanks!

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


Re: [R] postscript problems (landscape orientation)

2009-05-21 Thread David Scott

On Thu, 21 May 2009, Zeljko Vrba wrote:


On Thu, May 21, 2009 at 02:14:01PM +0200, Peter Dalgaard wrote:


I think the trick is

jade:~/> env | grep GS_
GS_OPTIONS=-dAutoRotatePages=/None


Thanks, I found that myself.  However, when using ps2pdf from Miktex 2.7, I
get the following error:

Unrecoverable error: typecheck in .putdeviceprops

I will try to manually invoke gs or, eventually, just use Distiller.



which I still have on my work login. However, I almost never use PS
these days since it is easier just to create the plot files with the
pdf() device.


Ah, now I remember why I don't use pdflatex: when you re-create the document,
the viewer gets _very_ confused, so I have to close and reopen the file and go
to the page I was viewing.  When I recreate postscript and turn on "Watch file"
in ghostview, I get automatic and quick previews of my work.



Well most people deal with that problem by not using Acrobat to read .pdf 
files. On linux you can use evince or xpdf. On windows just use gsview32. 
Those readers don't lock the .pdf.


I am with Peter and generally go straight to pdf these days. The only 
reason for going through postscript is if you want to use psfrag.


David Scott



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

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics

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


[R] good numerical optimization to use in R?

2009-05-21 Thread Michael
Hi all,

Could anybody point me to a good/robust numerical optimization program
to use in R?

I am doing some MLE fitting. 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] hands-on model selection and statistical data analysis books in R?

2009-05-21 Thread Michael
Hi all,

I am fitting a model to time series of intra-day financial data.

Could anybody point me to some hands-on books about model selection,
model specification test, goodness-of-fit test, feature selection and
statistical time series data analysis? I am looking not for
theoretical or math books, but for guided lab type of books, so that I
could realistically know how to choose the best model, while without
the overfitting. Hopefully it's in R.

Thanks!

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


Re: [R] postscript problems (landscape orientation)

2009-05-21 Thread Ted Harding
On 21-May-09 23:02:28, David Scott wrote:
> Well most people deal with that problem by not using Acrobat to
> read .pdf files. On linux you can use evince or xpdf. On windows
> just use gsview32. Those readers don't lock the .pdf.
> 
> I am with Peter and generally go straight to pdf these days. The only 
> reason for going through postscript is if you want to use psfrag.
> 
> David Scott

Going off at a tangent to the original query, I would say that
this is too limited a view! For one thing, PostScript (in its
Encasulated manifestation) is readily imported and re-scalable
by software which does not import PFF. Also, PS is an editable
plain-text file (even though there may be chunks in hexadecimal
for some graphics -- but it's still ASCII). One thing which I
quite often do is edit the "%%BoundingBox: " line to improve the
framing of the graphic -- and viewing it in ghostscript with
"watch" mode on as one edits, one can easily adjust things to
a satisfactory visual effect.

If you know what you are doing, you can if you wish move things
around, or add or delete things (especially bits of text) by
using any plain-text editor on the PostScript file.

Finally (though this may be a symptom of serious masochsim on
my part), if I download a PDF in which the author has plotted
the data, after I "print to file" in PostScript from Acrobat
Reader I can usually obtain a very close approximation to the
original data values by extracting the PS coordinates of the
plotted points (and axis tick-marks) from the PostScript file.

"The only reason for going through postscript is if you want
to use psfrag" -- or psnup and/or psbook or ... 

Ted.



E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 22-May-09   Time: 00:31:32
-- XFMail --

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


Re: [R] index to select rows of a large matrix

2009-05-21 Thread tsunhin wong
Dear Jim,
Thanks for your suggestion.

I have a follow-up question for fellow R Users that have followed this thread:

*I used to create two lists by some very flexible criteria to compare
from "iData" and pass the two lists to *ANOTHER FUNCTION* that further
decompose the two lists and do some case by case analysis:

comp.lst[[1]] <- subset(iData,(Session==1 & TrialList==2 & BadTrial==0
& Correct==1 & Critical.BT>0))
comp.lst[[2]] <- subset(iData,(Session==2 & TrialList==2 & BadTrial==0
& Correct==1 & Critical.BT>0))

*The function will then do some subject by subject processing:

tmplist <- comp.lst[[1]]
subject <- unique(tmplist$Subject)
Psubjmatrix <- NULL
for(j in 1:length(subj)) { ##divide the list and process per subject in the list
subjtriallist <- subset(tmplist,(Subject==subj[j])) ##divide
the list and process per subject in the list
print(paste("Start working on Subject ",subj[j],sep=""),quote=FALSE)
##The sub-divided list is passed to another function to
extract data from corresponding object
Ptrialmatrix <- SeekObject(subjtriallist,seconds,samplesize,sdmax);
##add rowmean to subject pupil matrix
Psubjmatrix <- cbind(Psubjmatrix, rowMeans(Ptrialmatrix,
na.rm=TRUE, dims=1))
}

*But now, I have a pre-processed the objects and cooked up a
1500x2 matrix, and there is no need to get these objects one by
one for extraction, I may just do the following:

Ptrialmatrix <- PMasterMatrix[subjindex,,drop=FALSE]

*However, on passing the index to the function, I cannot further
sub-divide the list index by Subject.

I have been thinking of passing the criteria to within the function.
But... what smarter thing I can do to make it works?

- John


On Thu, May 21, 2009 at 10:33 AM, jim holtman  wrote:
> Assuming that you get the list of indices into iData for the criteria, then
> you can use that to get the appropriate rows:
>
> indx <- which(iData >5)  # or whatever your criteria is
> DataSeq[indx,, drop=FALSE]  # gives you a subset matrix of just the rows you
> are interested in.
>
> On Thu, May 21, 2009 at 10:10 AM, tsunhin wong  wrote:
>>
>> Dear R Users,
>>
>> I have created a 1500 x 2 data frame - DataSeq. Each of the 1500
>> rows represents a data sequence.
>> I have another data frame iData that stores the information of these
>> 1500 data sequences in the same order, for example, condition, gender,
>> etc.
>>
>> If I use "subset" to select certain groups within iData according to
>> some criteria that I have set, e.g. condition, gender
>> Then how can I used the retrieved subset of iData to point to and
>> retrieve corresponding rows in the DataSeq data.frame for
>> manipulations and analysis?
>>
>> I hope some of you can give me some idea!
>> Thank you very much!!!
>>
>> - John
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>

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


[R] axis in the barplot

2009-05-21 Thread Xiaogang Yang
I use barplot to plot graph, and there is axis of y, but no x, just label,
so where to add x-axis in barplot.

-- 
Xiaogang Yang
Sensorweb Research Laboratory
http://sensorweb.vancouver.wsu.edu/
Washington State University Vancouver

[[alternative HTML version deleted]]

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


Re: [R] help with gsub and date pattern

2009-05-21 Thread Gabor Grothendieck
Here are a few more to add to the list.

x <- c("5/31/2009 12:34:00","6/1/2009 1:14:00")

# 1
read.table(textConnection(x), as.is = TRUE)[, 2]

# 2
format(as.POSIXct(x, format = "%m/%d/%Y %H:%M:%S"), "%H:%M:%S")

# 3
library(gsubfn)
strapply(x, "[0-9]*:..:..", simplify = c)

Also see R News 4/1.


On Thu, May 21, 2009 at 5:34 PM, Marc Schwartz  wrote:
> On May 21, 2009, at 4:13 PM, Tim Clark wrote:
>
>>
>> Dear List,
>>
>> I am having a problem using gsub to remove dates from a date/time string.
>>
>> For example:
>>
>> x<-c("5/31/2009 12:34:00","6/1/2009 1:14:00")
>>
>> I would like to remove the date and have just the time.
>>
>> I have tried:
>> gsub("[0-9+]/[0-9+]/[0-9+]","",x)
>>
>> and various versions.  I think my problem is that the / is a special
>> character and is telling it something that I don't mean.  I would appreciate
>> any suggestions on how to proceed.
>>
>> Thanks,
>>
>> Tim
>
>
>
> Switch the '+' to outside the brackets:
>
>> gsub("[0-9]+/[0-9]+/[0-9]+ ","",x)
> [1] "12:34:00" "1:14:00"
>
>
> A few other options:
>
> # Use strsplit
>> sapply(strsplit(x, split = " "), "[", 2)
> [1] "12:34:00" "1:14:00"
>
>
> # Return the pattern contained within the parens
> # See ?regex
>> gsub("^.* (.*)$", "\\1", x)
> [1] "12:34:00" "1:14:00"
>
>
> # Replace the characters up to the space with an empty vector
>> gsub("^.* ", "", x)
> [1] "12:34:00" "1:14:00"
>
>
> 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] axis in the barplot

2009-05-21 Thread Peter Alspach
Tena koe

Is this the sort of thing you had in mind?

tt <- barplot(sample(1:5))
axis(1, tt, letters[1:5])
 
HTH ...

Peter Alspach

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Xiaogang Yang
> Sent: Friday, 22 May 2009 11:35 a.m.
> To: r-help@r-project.org
> Subject: [R] axis in the barplot
> 
> I use barplot to plot graph, and there is axis of y, but no 
> x, just label, so where to add x-axis in barplot.
> 
> --
> Xiaogang Yang
> Sensorweb Research Laboratory
> http://sensorweb.vancouver.wsu.edu/
> Washington State University Vancouver
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

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

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


Re: [R] Class for time of day?

2009-05-21 Thread Gabor Grothendieck
On Thu, May 21, 2009 at 5:04 PM, Stavros Macrakis  wrote:
> On Wed, May 20, 2009 at 12:28 PM, Gabor Grothendieck
>  wrote:
>>
>> There is a times class in the chron package.
>
> Perfect!  Just what I was looking for.
>
> On Wed, May 20, 2009 at 12:19 PM, jim holtman  wrote:
>>
>> If you want the hours from a POSIXct, here is one way of doing it...
>> > y <- difftime(x, trunc(x, units='days'), units='hours')
>
> Ah, trunc.POSIXt -- I missed that one, thanks.
>
>> It depends on what type of computations you want to do with it.  You can
>> leave it as POSIXct and carry out a lot of them.  Can you specify what you
>> want?
>
> I am comparing irregular time series from different days, looking at the
> differences in intraday patterns.  So I want to put them on a common 0-24h
> scale and then do various kinds of plots and analyses, keeping the
> conventional display form (10:30 etc.) when specific times display or
> print.  It looks as though chron:::times combined with trunc.POSIXt pretty
> much solves my problem, except that `times` ignores the time units:

It uses hours/minutes/seconds for values < 1 day and uses days and fractions
of a day otherwise.

For values and operations that it has not considered it falls back to
the internal
representation.

Most of your examples start to make sense once you realize this.

>
>> as.POSIXct('2009-3-23 12:23')-trunc(as.POSIXct('2009-3-23 12:23'),"day")
> Time difference of 12.38333 hours
>> times(as.POSIXct('2009-3-23 12:23')-trunc(as.POSIXct('2009-3-23
>> 12:23'),"day"))
> Time in days:    <<< seems to treat difftimes as raw numbers!!
> [1] 12.38333
>
> Obviously I can work around this, but shouldn't `times` give an error when
> it encounters an object of unknown class rather than unsafely using its
> internal representation?  Of course, better still if `times` converted
> correctly
>
> In general, `times` has other inconsistent and peculiar behavior:
>
> times(2) => Time in days: 2    Allows specifying multi-day periods, OK
> times(1.5) => Time in days: 1.5   Allows specifying fractional multi-day
> periods, OK
> times(0.5) => "12:00:00"   Inconsistent format compared to times(1.5)
> times("18:00:00") + times("18:00:00")  => Time in days: 1.5, OK
> times("36:00:00") => error  Why does it allow times(1.5) and
> times("18:00:00") + times("18:00:00") to specify 1.5 days, but not 36 hours?
> times(-0.5) => -0.5   Why doesn't it print Time in days: -0.5?
> times("18:00:00")/times("1:00:00") => Time in days: 18    Incorrect
> dimensions; meaningless result -- should be dimensionless
> times("18:00:00") * times("10:00:00") => 07:30:00 Incorrect dimensions;
> meaningless result.
> sin(times("18:00:00")) => 16:21:34 Meaningless result -- should be error
>
> It's nice that R has a class system, but if code ignores the class
>
>> There is an article on dates and times in R News 4/1.
>
> Thanks for the pointer.
>
>   -s
>
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Paste Strings as logical for functions?

2009-05-21 Thread tsunhin wong
Dear R Users,

I have some dynamic selection rules that I want to pass around for my functions:

>rules <- paste(g$TrialList==1 & g$Session==2)
>myfunction <- function(rules) {
>   index <- which(rules)
>   anotherFunction(index)
> }

However, I can't find a way to pass around these selection rules
easily (for subset, for which, etc)
Please let me know if you have some idea.

Thank you very much!

- John

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


Re: [R] Barchart in lattice - wrong order of groups, data labels on top of each other, and a legend question

2009-05-21 Thread Gabor Grothendieck
If you are willing to go down one level and work at the grid level
then you can do it without modifying the panel function.

Below gg.ls$name lists the grid object names.  Within that
list look at the ones that have rect in their name.  Among
those are 5 in success (the 2nd through 6th rect objects).
Similarly look for a text object in that vicinity. That would
be the the third object of those with text in their name.  We
want to reset the positioning of the text in the text object
using the info from the rect objects that form the bars. Thus:

# first run your code as posted, then run this
library(grid)
gg <- grid.grab()
gg.ls <- grid.ls(gg)
# based on gg.ls$name we make the observations above

rect.names <- grep("rect", gg.ls$name, value = TRUE)[2:6]
text.names <- grep("text", gg.ls$name, value = TRUE)[3]

rect.x <- c(sapply(rect.names, function(x) grid.get(x)$x))
rect.height <- c(sapply(rect.names, function(x) grid.get(x)$height))
text.name <- grep("text", gg.ls$name, value = TRUE)[3]

grid.edit(text.name,
x = unit(rect.x, "native"),
y = unit(rect.height+1, "native"))

On Thu, May 21, 2009 at 3:58 PM, Dimitri Liakhovitski  wrote:
> Deepayan, thank you very much for your response.
> I have a general question. And please remember - I am really just a
> beginner in R.
> Is it truly the case that in order to build quite a basic bar chart
> with value labels attached to it I have to be a true R graphics guru -
> because the only way to do achieve what I am trying to achive is to
> modify the underlying R function (panel.barchart)?
> Really?
>
> Dimitri
>
>
> On Tue, May 19, 2009 at 7:53 PM, Deepayan Sarkar
>  wrote:
>> On Mon, May 18, 2009 at 11:47 AM, Dimitri Liakhovitski  
>> wrote:
>>> Hello!
>>> I have a question about my lattice barchart that I am trying to build
>>> in Section 3 below. I can't figure out a couple of things:
>>> 1. When I look at the dataframe "test" that I am trying to plot, it
>>> looks right to me (the group "Total" is always the first out of 5).
>>> However, in the chart it is the last. Why?
>>> 2. How can I make sure the value labels (on y) are not sitting on top
>>> of each other but on top of the respective bar?
>>> 3. Is there any way to make the legend group items horizontally as
>>> opposed to now (vertically - taking up too much space)
>>
>> For 1 and 3, use
>>
>>         auto.key = list(points = FALSE,
>>                         rectangles = TRUE,
>>                         reverse.rows = TRUE,
>>                         columns = 2,
>>                         space = "bottom")
>>
>> From ?xyplot (under 'key'):
>>
>>               'reverse.rows' logical, defaulting to 'FALSE'.  If
>>                    'TRUE', all components are reversed _after_ being
>>                    replicated (the details of which may depend on the
>>                    value of 'rep').  This is useful in certain
>>                    situations, e.g. with a grouped 'barchart' with
>>                    'stack = FALSE' with the categorical variable on
>>                    the vertical axis, where the bars in the plot will
>>                    usually be ordered from bottom to top, but the
>>                    corresponding legend will have the levels from top
>>                    to bottom (unless, of course, 'reverse.rows =
>>                    TRUE').  Note that in this case, unless all columns
>>                    have the same number or rows, they will no longer
>>                    be aligned.
>>
>>               'columns' the number of columns column-blocks the key is
>>                    to be divided into, which are drawn side by side.
>>
>>
>> 2 is hard with a simple custom panel function, because you need to
>> replicate some fairly involved calculations that are performed in
>> panel.barchart. Your best bet is to start with a copy of
>> panel.barchart, and then add calls to panel.text at suitable places.
>>
>> -Deepayan
>>
>>
>>> Thanks a lot!
>>> Dimitri
>>>
>>> ### Section 1: generates my data set "data" - just run: #
>>>
>>> N<-100
>>> myset1<-c(1,2,3,4,5)
>>> probs1<-c(.05,.10,.15,.40,.30)
>>> myset2<-c(0,1)
>>> probs2<-c(.65,.30)
>>> myset3<-c(1,2,3,4,5,6,7)
>>> probs3<-c(.02,.03,.10,.15,.20,.30,.20)
>>>
>>> group<-unlist(lapply(1:4,function(x){
>>>        out<-rep(x,25)
>>>        return(out)
>>> }))
>>> set.seed(1)
>>> a<-sample(myset1, N, replace = TRUE,probs1)
>>> a[which(rbinom(100,2,.01)==1)]<-NA
>>> set.seed(12)
>>> b<-sample(myset1, N, replace = TRUE,probs1)
>>> b[which(rbinom(100,2,.01)==1)]<-NA
>>> set.seed(123)
>>> c<-sample(myset2, N, replace = TRUE,probs2)
>>> set.seed(1234)
>>> d<-sample(myset2, N, replace = TRUE,probs2)
>>> set.seed(12345)
>>> e<-sample(myset3, N, replace = TRUE,probs3)
>>> e[which(rbinom(100,2,.01)==1)]<-NA
>>> set.seed(123456)
>>> f<-sample(myset3, N, replace = TRUE,probs3)
>>> f[which(rbinom(100,2,.01)==1)]<-NA
>>> data<-data.frame(group,a=a,b=b,c=c,d=d,e=e,f=f)
>>> data["group"]<-lapply(data["group"],function(x) {
>>>    

Re: [R] NA when indexing vectors

2009-05-21 Thread Kenneth Roy Cabrera Torres
Maybe you mean:

x[which(x>=2)]


El jue, 21-05-2009 a las 14:34 -0400, Jorge Ivan Velez escribió:
> Hi,
> Try:
> 
> which( x>=2 )
> 
> HTH,
> 
> Jorge
> 
> 
> On Thu, May 21, 2009 at 2:28 PM, Szilard 
> wrote:
> 
> > Hello:
> >
> > Is there a more natural way to get all elements that satisfy a condition
> > when there are NAs in the sample?
> >
> > > x=c(1,2,NA)
> >
> > > x>=2
> > [1] FALSE  TRUENA
> >
> > > x[x>=2]
> > [1]  2 NA ## I would expect here to get just "2"
> >
> > > x[!is.na(x) & x>=2]   ## seems a bit cumbersome
> > [1] 2
> >
> > Thanks,
> > Szilard
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 google for R stuff?

2009-05-21 Thread Kenneth Roy Cabrera Torres

--- Begin Message ---
I use to install the R Site Search Sidebar in firefox.

http://addictedtor.free.fr/rsitesearch/

Unfortunalely you can not install it in new versions
of firefox unlees you disable "checkCompatiblity" and
"checkUpdateSecurity" on firefox (which is not recommendable).
Still I do it and is my favorite search engine when 
I am trying to find any topic in some R package.

I love the R logo in the bottom left side of the firefox browser.
Somebody told me that it is like the "secret" logo the hackers
use on the film "The Net" (1995) with Sandra Bullock.

Have a good R searching.

Kenneth

El mié, 20-05-2009 a las 09:02 -0400, Kynn Jones escribió:
> Hi!  I'm new to R programming, though I've been programming in other
> languages for years.
> 
> One thing I find most frustrating about R is how difficult it is to use
> Google (or any other search tool) to look for answers to my R-related
> questions.  With languages with even slightly more distinctive names like
> Perl, Java, Python, Matlab, OCaml, etc., usually including the name of the
> language in the query is enough to ensure that the top hits are relevant.
>  But this trick does not work for R, because the letter R appears by itself
> in so many pages, that the chaff overwhelms the wheat, so to speak.
> 
> So I'm curious to learn what strategies R users have found to get around
> this annoyance.
> 
> TIA!
> 
> KJ
> 
>   [[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.
--- End Message ---
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   >