Re: [R] how to explain the interaction terms regarding treatmentcontrast of lm model

2009-08-29 Thread zrl
Thank you all for your help.

Daniel,

I want to know if I really understand your answer. I calculated each group
mean and sub mean as below:

 tapply(val,group,mean)
  group1   group2   group3
4.215670 5.664411 7.210819
 tapply(val,sub,mean)
   abcd
4.856927 5.199305 6.183979 6.547655

and
intercept (group=1 and sub=a) is: 3.506216 (see original post table)
average difference between group2 and group1 is: 5.664411 -
4.215670=1.448741
average difference between sub b and sub a is: 5.199305-4.856972=0.342333

therefore, if I understand this right,  the reference level for interaction
between sub=b and group=2  should be the sum of the above numbers, which is:
3.506216+1.448741+0.342333=5.29729

Am I right? Thank you vey much.


On Fri, Aug 28, 2009 at 7:02 PM, Daniel Malter dan...@umd.edu wrote:

 The intercept is group=1, sub=a,

 The interaction between sub=b and group=2 implies that both sub=b and
 group=2 direct effects are included. That is, with the direct effects only
 you are now at: intercept+group2+subb, which means the intercept (group1
 and
 sub=a) + the average difference between group=2 and group=1 + the average
 difference between sub=b and sub=a. This is the reference level for the
 interaction effect between group=2 and sub=b. This is not one-specific
 group
 in your experiment but rather a generic average group (average group=2,
 average sub=b). Your interaction effect now asks the question how much does
 group=2 with sub=b stand out from the average in its group and in its sub.

 To clarify your confusion, you may want to write out the model formula.

 Daniel

 -
 cuncta stricte discussurus
 -

 -Ursprüngliche Nachricht-
 Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
 Auftrag von zrl
 Gesendet: Friday, August 28, 2009 6:49 PM
 An: r-help
 Betreff: [R] how to explain the interaction terms regarding
 treatmentcontrast of lm model

 Dear list,

 I am confused on how to explain the interaction term in the context of
 treatment contrast.

 for example, I have an data frame as below:
  sub  group  val
 1a group1 3.685625
 2a group1 3.407445
 3a group1 4.040920
 4a group1 2.890875
 5b group1 3.853280
 6b group1 4.113585
 7b group1 3.043250
 8b group1 3.800920
 9c group1 5.394305
 10   c group1 5.004290
 11   c group1 4.651435
 12   c group1 4.286650
 13   d group1 4.773440
 14   d group1 3.982200
 15   d group1 5.718690
 16   d group1 4.803815
 .
 45   d group3 8.021240
 46   d group3 7.641685
 47   d group3 7.519445
 48   d group3 9.514580

 then:

 tapply(val,list(group,sub),mean)
  abcd
 group1 3.506216 3.702759 4.834170 4.819536
 group2 4.831503 5.246833 5.930116 6.649191
 group3 6.233062 6.648325 7.787651 8.174238

  summary(lm(val~group*sub))

 Call:
 lm(formula = val ~ group * sub)

 Residuals:
 Min   1Q   Median   3Q  Max
 -1.24378 -0.50184 -0.03726  0.51748  1.34034

 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)3.5062 0.3278  10.696 9.98e-13 ***
 groupgroup21.3253 0.4636   2.859  0.00703 **
 groupgroup32.7268 0.4636   5.882 9.98e-07 ***
 subb   0.1965 0.4636   0.424  0.67411
 subc   1.3280 0.4636   2.865  0.00693 **
 subd   1.3133 0.4636   2.833  0.00751 **
 groupgroup2:subb   0.2188 0.6556   0.334  0.74052
 groupgroup3:subb   0.2187 0.6556   0.334  0.74060
 groupgroup2:subc  -0.2293 0.6556  -0.350  0.72851
 groupgroup3:subc   0.2266 0.6556   0.346  0.73158
 groupgroup2:subd   0.5044 0.6556   0.769  0.44671
 groupgroup3:subd   0.6279 0.6556   0.958  0.34460
 ---
 Signif. codes:  0  ***  0.001  **  0.01  *  0.05  .  0.1 1

 Residual standard error: 0.6556 on 36 degrees of freedom
 Multiple R-squared: 0.8607, Adjusted R-squared: 0.8182
 F-statistic: 20.22 on 11 and 36 DF,  p-value: 3.296e-12


 My question is:
 with treatment contrast in R, Coefficients, groupgroup2,groupgroup3,
 subb,
 subc,subd are the difference from Intercept 3.5062 (reference level for
 intercepts).
 But what is the reference level for the interaction terms? such as
 groupgroup2:subb,groupgroup3:subb,and etc.

 Thanks.

 [[alternative HTML version deleted]]




[[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] unix like commands in R?

2009-08-29 Thread zrl
Thank you Ted.
I did try page(file,method=print), it did behave as less.

I will try the code to modify the profile as well to see how it goes. Thank
you very much.

On Mon, Aug 24, 2009 at 5:32 PM, Ted Harding
ted.hard...@manchester.ac.ukwrote:

 On 24-Aug-09 21:56:06, zrl wrote:
  Dear List:
  I am trying to find a command in R which is like the unix command
  less or more to show the data in a object of R.
  did anyone can help me on this?
 
  Is there a collection of such unix-like commands in R?
 
  Thanks.
 
  -ZRL

 There is a page() command in R -- see '?page'. From your query I take
 it you are in fact using either Linux or Unix (or possible a Mac BSD
 type OS).

 Have a look at  options(pager)  to see what is currently uses.

 I have modified my R setup so that it uses 'less' (on Linux) as
 the pager program.

 I did this in my .Rprofile (in home directory) by putting in the
 lines:


 .xthelp - function() {
tdir - tempdir()
pgr - paste(tdir, /pgr, sep=)
con - file(pgr, w)
cat(#! /bin/bash\n, file=con)
cat(export HLPFIL=`mktemp , tdir, /R_hlp.XX`\n,
sep=, file=con)
cat(cat  $HLPFIL\nxterm -e less $HLPFIL \n, file=con)
close(con)
system(paste(chmod 755 , pgr, sep=))
options(pager=pgr)
 }
 .xthelp()
 rm(.xthelp)


 This opens anything which might be paged in a separate xterm,
 so thatfor instance, all responses to ?. come up in a new
 xterm being paged by 'less'. Likewise, if you page a large object
 (such as a matrix M with 500 rows), using 'page(M), you will
 again see the result paged in 'less' in a separate window.

 This code was suggested by Roger Bivand in response to a query
 of mine back in 2003. The URL is

  http://finzi.psych.upenn.edu/R/Rhelp02/archive/21642.html

 This was an improvement on a previous solution of my own, which
 is also quoted in the above URL.

 Hoping this helps,
 Ted.

 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 24-Aug-09   Time: 23:32:18
 -- XFMail --


[[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] Annotation database

2009-08-29 Thread Sukhbir Rattan
Hi,

I have 15 CEL files of Affymetrix platform from GEO.

Title of experiment is : Ecoli_ASv2 Affymetrix E. coli Antisense Genome
Array.

I am looking for the package available in R for this array for annotation.

I  have already tried doing annotation from packages like org.EcK12.eg.db
but I don't got the success.

Is any other package in the form of database available for E.coli for
Annotation?

By
Sukhbir Singh Rattan

[[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] Annotation database

2009-08-29 Thread David Winsemius


On Aug 29, 2009, at 2:43 AM, Sukhbir Rattan wrote:


Hi,

I have 15 CEL files of Affymetrix platform from GEO.

Title of experiment is : Ecoli_ASv2 Affymetrix E. coli Antisense  
Genome

Array.

I am looking for the package available in R for this array for  
annotation.


I  have already tried doing annotation from packages like  
org.EcK12.eg.db

but I don't got the success.

Is any other package in the form of database available for E.coli for
Annotation?


You're probably on the wrong mailing list, but see if these help:

http://article.gmane.org/gmane.science.biology.informatics.conductor/20614

http://www.bioconductor.org/data/cdfenvs/repos/html/ecoliasv2cdfv1.4.3.html

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Rcmdr installalation under Viata gives a warning. Do I need to do anything?

2009-08-29 Thread Stefan Grosse
On Fri, 28 Aug 2009 21:39:41 -0400 John Sorkin
jsor...@grecc.umaryland.edu wrote:

JS Windows Vista
JS R 2.9.1
JS 
JS When trying to install Rcmdr I get the message shown below. What
JS does it mean, do I need to do anything?
JS 
JS The downloaded packages are in
JS C:\Users\John
JS Sorkin\AppData\Local\Temp\RtmpRCLbhe\downloaded_packages updating
JS HTML package descriptions Warning message:
JS In file.create(f.tg) :
JS   cannot create file
JS 'C:\PROGRA~1\R\R-29~1.1/doc/html/packages.html', reason 'Permission
JS denied'

Vista does not allow normal Users to write into the program folder. So
either you run R with admin rights (right click, then run as
administrator) or you circumvent this by installing R into your User
directory like into 

C:\Users\John Sorkin\R

hth
Stefan

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


Re: [R] CHAID in R

2009-08-29 Thread Achim Zeileis

On Fri, 28 Aug 2009, Arup wrote:


Hi..I am trying to run CHAID in R..I have installed the sofyware Party and
trying to use the function ctree() to carry out the analysis. but I am
getting the following message Error in terms.default(formula, data = data) :
no terms component


Without a simple reproducible example (as the posting guide tells you) 
it's hard to say what went wrong for you.



. I am having some Likert scale variable where I have variables like
Overall satisfaction(Dependent Variable),Product quality, Brand
image,Warranty(Independent variable) etc..


ctree() can handle this situation appropriately, see
   vignette(party, package = party)
for more details and worked examples.


Now can anyone tell me how to run
CHAID in this case..what would be the formula? Thanks in Advance..


CTree is similar in spirit to CHAID but not the same. However, there is 
the CHAID package on R-Forge (as pointed out previously, thanks to Max).


CTree is more flexible and can deal with more types of variables, e.g., it 
would be possible to use linear-by-linear type tests instead of plain 
Chi-squared tests for ordinal variables.


hth,
Z



--
View this message in context: 
http://www.nabble.com/CHAID-in-R-tp25188573p25188573.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] Numeric, 2 ??? as a result of marix???

2009-08-29 Thread Wolfgang Polasek
Strange things are going on in R, if you reshape a matrix in R:
 g=gretldata[1:2,]
 g
   Empfang   Versand  Transit  Inland AuslandSumS
1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
 dim(g)
[1] 2 6
 as.vector(g)
   Empfang   Versand  Transit  Inland AuslandSumS
1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
 gg=matrix(as.vector(g),nrow=1,byrow=TRUE)
 gg
 [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
[1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2

 Help please,the docu on thids is lousy!!!.
Wolfgang

[[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] script navigation in Vista

2009-08-29 Thread Wolfgang Polasek
Why is the option  last changed not working if I open a script from R
under Vista?
Wolfgang

[[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] Resolved: Problem in local ~/.fonts.conf broke symbol font in pdf device (Was: Re: Plotmath, sweave and lattice graphics interaction problem)

2009-08-29 Thread Gavin Simpson
On Sat, 2009-08-29 at 09:04 +1000, Duncan Mackay wrote:
 Hi Gavin
 
 I am running on windows and have no problem

Thanks for confirming that this appears to be peculiar to my system,
Duncan. I've narrowed this down to just the PDF device so nothing to do
with Sweave and / or lattice as the characters are missing with base
graphics also.

I suspect a font issue somewhere on my system. In fact I've just found
the source of the problem now. Under earlier versions of Fedora (9 and
10) I had to use the following ~/.fonts.conf

alias binding=same
   familyZapfDingbats/family
   acceptfamilyDingbats/family/accept
   familySymbol/family
   acceptfamilyStandard Symbols L/family/accept
/alias

The definition for Symbol is what is breaking this font for me on the
pdf device. The suggestion for ~/.fonts.conf in ?pdf,

alias binding=same
   familyZapfDingbats/family
   acceptfamilyDingbats/family/accept
/alias

solves the problem with the symbol font on Fedora 11 for me but still
fixes the pch = 1 issue.

All the best,

Gavin

 
 R version 2.9.2 (2009-08-24)
 i386-pc-mingw32
 
 locale:
 LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MONETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252
 
 attached base packages:
 [1] datasets  utils stats graphics  grDevices 
 grid  methods   base
 
 other attached packages:
 [1] Hmisc_3.6-1   R.oo_1.4.8R.methodsS3_1.0.3 
 foreign_0.8-37chron_2.3-30  MASS_7.2-48   lattice_0.17-25
 
 loaded via a namespace (and not attached):
 [1] cluster_1.12.0
 
 Can forward you my sweave file et al if required
 
 Regards
 
 Duncan Mackay
 Department of Agronomy and Soil Science
 University of New England
 ARMIDALE NSW 2351
 Email home: mac...@northnet.com.au
 
 At 03:10 29/08/2009, you wrote:
 Dear List,
 
 I have hit this problem with using a plotmath expression in an axis
 label on a lattice plot I'm including in a Sweave document. The actual
 document is far too long and boring (unless you are interested in the
 hydrochemistry of upland lakes) to include here, but the following
 minimal example reproduces the problem; basically, the PDF produced by
 Sweave has missing characters in the plotmath label whilst the eps file
 doesn't.
 
 Here is the minimal Rnw document:
 
 \documentclass[a4paper,12pt]{article}
 \usepackage{graphicx,xspace}
 \usepackage[utf8]{inputenc}
 \usepackage[left=1.5cm,top=2cm,bottom=2cm,right=1.5cm]{geometry}
 
 \usepackage{/home/gavin/R/2.9-patched/build/share/texmf/Sweave}
 \setkeys{Gin}{width=1\textwidth}
 
 \begin{document}
 \title{FOO}
 \author{Gavin Simpson}
 
 \maketitle
 
 fig=true=
 require(lattice)
 dat - data.frame(A = runif(10), B = runif(10))
 print(xyplot(A ~ B, data = dat,
   ylab = expression(H^+ ~ (mu*eq ~ L^-1
 @
 
 \end{document}
 
 Note the ylab expression:
 
 ylab = expression(H^+ ~ (mu*eq ~ L^-1))
 
 this produces a ylab like H+ (mueq L-1) when run interactively and on
 the eps file, but the pdf file is missing the parentheses and the mu
 (micro) symbol.
 
 R session info:
 
   sessionInfo()
 R version 2.9.1 Patched (2009-08-07 r49104)
 x86_64-unknown-linux-gnu
 
 locale:
 LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=en_GB.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C
 
 attached base packages:
 [1] tools stats graphics  grDevices utils datasets
 methods
 [8] base
 
 other attached packages:
 [1] lattice_0.17-25
 
 loaded via a namespace (and not attached):
 [1] grid_2.9.1
 
 So I'm running this in a UTF-8 locale. Is it this that is causing the
 problem? Any suggestions as to how to proceed?
 
 Thanks in advance,
 
 G
 
 --
 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
   Dr. Gavin Simpson [t] +44 (0)20 7679 0522
   ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
   Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
   Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
   UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 

Re: [R] setting par(srt) according to plot aspect ratio

2009-08-29 Thread Jim Lemon

Levi Waldron wrote:

For posterity's sake, here is the solution I figured out.  Putting the
following lines after the plot(f) command seems to set the angle correctly:

myasp -
(par(fin)[2]-par(mai)[1]-par(mai)[3])/(par(fin)[1]-par(mai)[2]-par(mai)[4])
(f_angle - atan(myasp)*180/pi)
(g_angle - atan(2*myasp)*180/pi)
  

Hi Levi,
Why not just:

plotpin-par(pin)
myasp-plotpin[2]/plotpin[1]

Jim

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


Re: [R] Numeric, 2 ??? as a result of marix???

2009-08-29 Thread Duncan Murdoch

Wolfgang Polasek wrote:

Strange things are going on in R, if you reshape a matrix in R:
  

g=gretldata[1:2,]
g


   Empfang   Versand  Transit  Inland AuslandSumS
1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
  

dim(g)


[1] 2 6
  

as.vector(g)


   Empfang   Versand  Transit  Inland AuslandSumS
1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
  

gg=matrix(as.vector(g),nrow=1,byrow=TRUE)
gg


 [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
[1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
  
 Help please,the docu on thids is lousy!!!.


If you don't like the documentation, then improve it.  You don't make 
friends by insulting people who provide you with something for free.


Duncan Murdoch

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


Re: [R] script navigation in Vista

2009-08-29 Thread Stefan Grosse
On Sat, 29 Aug 2009 00:07:44 +0200 Wolfgang Polasek
wolfgang.pola...@gmail.com wrote:

WP Why is the option  last changed not working if I open a script
WP from R under Vista?

Because it remembers the changes only of a current session?

You should be a bit more descriptive: which editor? which R? What do
you mean with last changes etc.

hth
Stefan

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


Re: [R] Numeric, 2 ??? as a result of marix???

2009-08-29 Thread Stefan Grosse
On Sat, 29 Aug 2009 00:15:45 +0200 Wolfgang Polasek
wolfgang.pola...@gmail.com wrote:

WP  g=gretldata[1:2,]
WP  g
WPEmpfang   Versand  Transit  Inland AuslandSumS
WP 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
WP 2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
WP  dim(g)
WP [1] 2 6
WP  as.vector(g)
WPEmpfang   Versand  Transit  Inland AuslandSumS
WP 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
WP 2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
WP  gg=matrix(as.vector(g),nrow=1,byrow=TRUE)
WP  gg
WP  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
WP [1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
WP 
WP  Help please,the docu on thids is lousy!!!.

Depending on what you want which is not really clear again, you can use 
?reshape
or maybe also 
?stack

to reshape a data-frame which gretldata supposedly is.

Note that with your as.vector(g) you dont create a vector as:
dat1-data.frame(x=1:3, y=5:7)
v1-as.vector(dat1)
str(v1)
resp.
is.vector(v1)

clearly shows. So you were also not debugging your problem. And you
clearly did not have a look at the lousy documentation as this is
shown in the example in ?as.vector, so don't blame others!

Cheers
Stefan

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


Re: [R] Numeric, 2 ??? as a result of marix???

2009-08-29 Thread Gabor Grothendieck
g does not appear to be a matrix, as described.   Its more
likely a data frame.   If that is the case then as.matrix(g)
will create a matrix from it.

Also depending on what you want to do ?unlist, ?t or ?c
may be of help.  Also try str(g) and dput(g) to see
internals of object as they seem not to be what you
believe them to be.

On Fri, Aug 28, 2009 at 6:15 PM, Wolfgang
Polasekwolfgang.pola...@gmail.com wrote:
 Strange things are going on in R, if you reshape a matrix in R:
 g=gretldata[1:2,]
 g
   Empfang   Versand  Transit  Inland Ausland    SumS
 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
 2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
 dim(g)
 [1] 2 6
 as.vector(g)
   Empfang   Versand  Transit  Inland Ausland    SumS
 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
 2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
 gg=matrix(as.vector(g),nrow=1,byrow=TRUE)
 gg
     [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
 [1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2

  Help please,the docu on thids is lousy!!!.
 Wolfgang

        [[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] linear model with interaction / segments

2009-08-29 Thread Markus Gesmann

Dear R-help,

Suppose I have the following data:

df=data.frame(x=1:10, y=c(1,2,3,4,5,12,14,16,18,20))
plot(y~x, df, t=b)

How can I fit a model which estimates the slopes between x = 1-5, 5-6,  
and 6-10?


Adding the factor f:

df$f -  gl(2,5)

Allows me to fit a linear model with interaction

lm(y ~ x:f, data=df)

which gives me the slope of 1 and 2 between 1-5, and 6-10  
respectively, however it can not cope with the change from 5 to 6.


I would appreciate if someone could point me into the right direction.

Many thanks

Markus

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


Re: [R] Google's R Style Guide

2009-08-29 Thread Esmail

Duncan Murdoch wrote:

On 8/28/2009 8:59 AM, Esmail wrote:

Perhaps most of you have already seen this?

   http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html

Comments/Critiques?


The rules are mostly reasonable, though they aren't the ones followed in 
the R source.  One bad rule is the one on curly braces:


An opening curly brace should never go on its own line; a closing curly 
brace should always go on its own line.


The problem is the second part.  If the closing brace is followed by an 
else clause, the else should go on the same line as the brace, or things 
will parse differently when pasted than they do in a function.  F


Excellent point, thanks, this has caused me some problems in the
past too.

Esmail

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


Re: [R] Google's R Style Guide

2009-08-29 Thread Esmail

(Ted Harding) wrote:

On 28-Aug-09 12:59:24, Esmail wrote:

Perhaps most of you have already seen this?
  
http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html


Comments/Critiques?



I think it is grossly over-prescriptive. For example:
  function names have initial capital letters and no dots
is violated throughout R itself.


Thanks Ted, the way I look at these is as recommendations that
I can choose to follow .. if something strikes me as silly I will
happily ignore it ;-)

Best,
Esmail

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


Re: [R] Google's R Style Guide

2009-08-29 Thread Esmail

Kingsford Jones wrote:

A few thoughts:




...



-- It's nice that people have made these guides available


Agreed .. it helps those relatively new to the language (and possible
other language biases) get their orientation.

Cheers,
Esmail

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


Re: [R] Google's R Style Guide

2009-08-29 Thread Esmail

Barry Rowlingson wrote:

On Fri, Aug 28, 2009 at 5:11 PM, hadley wickhamh.wick...@gmail.com wrote:


In my view, that's the purpose of indenting - you see scope from
indenting.


 *cough* python *cough*


:-)

(my favorite language at the moment)

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

2009-08-29 Thread Gad Abraham

Hi,

More of a statistical question, I'm trying to understand the formulation 
of the one-sample two-sided Kolmogorov-Smirnov statistic in 
stats::ks.test(), testing against a uniform distribution.


Basically, it boils down to:

x - rnorm(100)

n - length(x)
z - punif(sort(x)) - (0:(n - 1)) / n
max(z, 1 / n - z)

which is equivalent to the textbook definition

n - length(x)
z - punif(sort(x))
Dplus - max(sapply(1:n, function(i) i / n - z[i]))
Dminus - max(sapply(1:n, function(i) z[i] - (i - 1) / n))
max(Dplus, Dminus)

(See, e.g., 
http://www.itl.nist.gov/div898/handbook/eda/section3/eda35g.htm, and 
Durbin (1971) ``Distribution theory for tests based on the sample 
distribution function'', p. 6)


Why does the definition of Dminus have an i-1 in the numerator instead 
of i? I have a hunch it's got to do with right-continuity of the ecdf, 
but perhaps someone can shed some light on it.


Thanks,
Gad


--
Gad Abraham
MEng Student, Dept. CSSE and NICTA
The University of Melbourne
Parkville 3010, Victoria, Australia
email: gabra...@csse.unimelb.edu.au
web: http://www.csse.unimelb.edu.au/~gabraham

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

2009-08-29 Thread Jack Tanner
In R 2.9.2,

 URLdecode(c(a%20b, b%20c))
[1] a b
Warning message:
In charToRaw(URL) : argument should be a character vector of length 1
all but the first element will be ignored

Could URLdecode be modified to actually process all elements of the vector, not
just the first?

Thanks in advance

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


Re: [R] RFE: vectorize URLdecode

2009-08-29 Thread Gabor Grothendieck
Here is a workaround

URLdecode.vec - Vectorize(URLdecode)

# test it out
x - c(a%20b, b%20c)
URLdecode.vec(x)


On Sat, Aug 29, 2009 at 10:31 AM, Jack Tanneri...@hotmail.com wrote:
 In R 2.9.2,

 URLdecode(c(a%20b, b%20c))
 [1] a b
 Warning message:
 In charToRaw(URL) : argument should be a character vector of length 1
 all but the first element will be ignored

 Could URLdecode be modified to actually process all elements of the vector, 
 not
 just the first?

 Thanks in advance

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


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


Re: [R] Best R text editors?

2009-08-29 Thread Zhiliang Ma
Emacs + ESS


On Thu, Aug 27, 2009 at 12:43 PM, Jonathan
Greenberggreenb...@ucdavis.edu wrote:
 Quick informal poll: what is everyone's favorite text editor for working
 with R?  I'd like to hear from people who are using editors that have some
 level of direct R interface (e.g. Tinn-R, Komodo+SciViews).  Thanks!

 --j

 --

 Jonathan A. Greenberg, PhD
 Postdoctoral Scholar
 Center for Spatial Technologies and Remote Sensing (CSTARS)
 University of California, Davis
 One Shields Avenue
 The Barn, Room 250N
 Davis, CA 95616
 Cell: 415-794-5043
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307

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

2009-08-29 Thread Max Kuhn
Perhaps this is obvious, but Ive never understood why this is the
general convention:

 An opening curly brace should never go on its own line;

I tend to do this:

f - function()
{
  if (TRUE)
{
  cat(TRUE!!\n)
} else {
  cat(FALSE!!\n)
}
}

(I don't usually put one-liners in if/else blocks; here I would have
used ifelse)

I haven't seen many others format code in this way. Is there an
objective reason for this (such as the rule for the trailing }) or
is this just aesthetics?

Thanks,

Max

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

2009-08-29 Thread tzygmund mcfarlane
Hi,

I would like to compute a goodness-of-fit statistic for one data
series against a t-distribution, and obtain the quantiles of the
distribution of the statistic with given degrees of freedom. I wonder
if this is implemented in a package.

I know that the critical values have to be computed for every
distribution, and this requires numerical integration typically. I
would prefer if I could get script or code implementing this rather
than published critical values.

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] Anderson-Darling (one sample)

2009-08-29 Thread stephen sefick
Do you know how to calculate what you want?  Why not write a function-
to do it and contribute to CRAN.

On Sat, Aug 29, 2009 at 10:07 AM, tzygmund
mcfarlanetzygm...@googlemail.com wrote:
 Hi,

 I would like to compute a goodness-of-fit statistic for one data
 series against a t-distribution, and obtain the quantiles of the
 distribution of the statistic with given degrees of freedom. I wonder
 if this is implemented in a package.

 I know that the critical values have to be computed for every
 distribution, and this requires numerical integration typically. I
 would prefer if I could get script or code implementing this rather
 than published critical values.

 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.




-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

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


Re: [R] Google's R Style Guide

2009-08-29 Thread hadley wickham
 An opening curly brace should never go on its own line;

 I tend to do this:

 f - function()
 {
  if (TRUE)
    {
      cat(TRUE!!\n)
    } else {
      cat(FALSE!!\n)
    }
 }

 (I don't usually put one-liners in if/else blocks; here I would have
 used ifelse)

 I haven't seen many others format code in this way. Is there an
 objective reason for this (such as the rule for the trailing }) or
 is this just aesthetics?

It's probably just aesthetics.  I don't like it because it increases
the number of lines without much real benefit - indenting already
gives you all the hints you need.

Hadley

-- 
http://had.co.nz/

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


Re: [R] Google's R Style Guide

2009-08-29 Thread Uwe Ligges



Max Kuhn wrote:

Perhaps this is obvious, but Ive never understood why this is the
general convention:


An opening curly brace should never go on its own line;


I tend to do this:

f - function()
{
  if (TRUE)
{
  cat(TRUE!!\n)
} else {
  cat(FALSE!!\n)
}
}

(I don't usually put one-liners in if/else blocks; here I would have
used ifelse)



... where you certainly know that ifelse evaluates both cases (if and 
else) and hence might be less efficient for scalar valued problems?


Uwe Ligges



I haven't seen many others format code in this way. Is there an
objective reason for this (such as the rule for the trailing }) or
is this just aesthetics?

Thanks,

Max

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

2009-08-29 Thread Corrado
I do not understand why one should use a S3 preferentially on a S4 class, if 
S4 is more rigorous.

(The premiss is I am a newbie with OO programming in R, and would like to 
understand what is the proper way to OO program in R )

Regards



On Saturday 29 August 2009 16:23:39 hadley wickham wrote:
  An opening curly brace should never go on its own line;
 
  I tend to do this:
 
  f - function()
  {
   if (TRUE)
 {
   cat(TRUE!!\n)
 } else {
   cat(FALSE!!\n)
 }
  }
 
  (I don't usually put one-liners in if/else blocks; here I would have
  used ifelse)
 
  I haven't seen many others format code in this way. Is there an
  objective reason for this (such as the rule for the trailing }) or
  is this just aesthetics?

 It's probably just aesthetics.  I don't like it because it increases
 the number of lines without much real benefit - indenting already
 gives you all the hints you need.

 Hadley



-- 
Corrado Topi

Global Climate Change  Biodiversity Indicators
Area 18,Department of Biology
University of York, York, YO10 5YW, UK
Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk

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


Re: [R] how to index a list with a string?

2009-08-29 Thread Uwe Ligges



Peter Alspach wrote:

Tena koe

Try either
L[foo()]
or
L[[foo()]]

These return subtly (or not so subtly depending on your point of view)
different results.


which is quite important, hence read the documentation. [] returns a 
list of length 1 (or a vector of length 1 of type list) where [[]] 
returns the value of the corresponding list element.
This also means that mutpiple indices are interpreted recursively in 
[[]] but will select the corresponding list elements in [].



Best,
Uwe Ligges




HTH 

Peter Alspach


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

Sent: Thursday, 27 August 2009 3:35 p.m.
To: r-help@r-project.org
Subject: [R] how to index a list with a string?

Hi, everybody. I have a list obj L, sth like

$`aaa`
[1] 5753

if the string 'aaa' is a returned value of a function foo(). 
what is the right syntax form of L$foo()


I'm new to R, thanks in advance.

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

and provide commented, minimal, self-contained, reproducible code.



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


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


Re: [R] Google's R Style Guide

2009-08-29 Thread Philippe Grosjean

Max Kuhn wrote:

Perhaps this is obvious, but Ive never understood why this is the
general convention:


An opening curly brace should never go on its own line;


I tend to do this:

f - function()
{
  if (TRUE)
{
  cat(TRUE!!\n)
} else {
  cat(FALSE!!\n)
}
}

(I don't usually put one-liners in if/else blocks; here I would have
used ifelse)

I haven't seen many others format code in this way. Is there an
objective reason for this (such as the rule for the trailing }) or
is this just aesthetics?


I think the problem is not much putting the opening brace after 
function(), or after if (...), like you do. The problem is putting the 
else at a new line like in:


if (TRUE) {
cat(TRUE!!\n)
}
else
{
cat(FALSE!!\n)
}

When you source this code, the first part until the first closing brace 
is considered complete by the R parser, and then, 'else' is considered 
as the begining of a new command, which is a syntax error:


 if (TRUE) {
+ cat(TRUE!!\n)
+ }
TRUE!!
 else
Error: syntax error
 {
+ cat(FALSE!!\n)
+ }
FALSE!!

If you put the same code in a function, you got the expected behaviour:

 f - function () {
+ if (TRUE) {
+ cat(TRUE!!\n)
+ }
+ else
+ {
+ cat(FALSE!!\n)
+ }
+ }
 f()  # No syntax error!
TRUE!!

Thus, this is technical reason for NOT putting else on another line.
For the rest, I share Hadley's feeling that you consumes too much 
lines and I tend to prefer the regular R syntax you got when you 
source your code.

Best,

Philippe



Thanks,

Max

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

2009-08-29 Thread David Winsemius


On Aug 29, 2009, at 7:56 AM, Markus Gesmann wrote:


Dear R-help,

Suppose I have the following data:

df=data.frame(x=1:10, y=c(1,2,3,4,5,12,14,16,18,20))
plot(y~x, df, t=b)

How can I fit a model which estimates the slopes between x = 1-5,  
5-6, and 6-10?


Adding the factor f:

df$f -  gl(2,5)

Allows me to fit a linear model with interaction

lm(y ~ x:f, data=df)

which gives me the slope of 1 and 2 between 1-5, and 6-10  
respectively, however it can not cope with the change from 5 to 6.


Can you be a bit more mathematically precise, ... and less  
anthropomorphic,  in explaining what you mean by cannot cope? When I  
look at the plot of fitted values I fail to see any coping  
deficiencies, at least with my understanding regarding what you were  
expecting  about which I am very much guessing at this point. Did  
you want only two regression lines that share a joinpoint at x=5.5?




I would appreciate if someone could point me into the right direction.

Many thanks

Markus


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] cannot upgrade to R 2.9.1 in Ubuntu

2009-08-29 Thread Dirk Eddelbuettel

Luis,

I missed this email earlier.  Consider using r-sig-debian for Debian / Ubuntu
question (but you need to subscribe before you can post).

On 7 August 2009 at 13:27, Luis Ridao Cruz wrote:
| R-help,
| 
| At the moment the R version installed on my machine is 2.8.1. (Ubuntu 9.04)
| I wish to upgrade to  R 2.9.1.
| 
| I did:
| $ sudo apt-get upgrade
| 
| ..but R is not upgraded although the sources.list file is updated with:
| 
| deb http://cran.ii.uib.no/bin/linux/ubuntu jaunty/

By force of habit, I usually do 'apt-get update; apt-get dist-upgrade'.  I
can never remember where upgrade and dist-upgrade differ.  Make sure you run
'apt-get update' first though.

One useful check is 'apt-cache policy r-base-core' where apt will tell you
which versions from which repos it knows to be available and how it ranks
them (equally by default; you can change that with 'pinning').

Hth, Dirk

| 
| When I run from the terminal I still get:
| 
| $ R
| R version 2.8.1 (2008-12-22)
| Copyright (C) 2008 The R Foundation for Statistical Computing
| ISBN 3-900051-07-0
| 
| R is free software and comes with ABSOLUTELY NO WARRANTY.
| You are welcome to redistribute it under certain conditions.
| Type 'license()' or 'licence()' for distribution details.
| 
|   Natural language support but running in an English locale
| ..
| ..
| 
| 
| Thanks in advance
| 
| __
| R-help@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-help
| PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
| and provide commented, minimal, self-contained, reproducible code.

-- 
Three out of two people have difficulties with fractions.

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


Re: [R] linear model with interaction / segments

2009-08-29 Thread Gavin Simpson
On Sat, 2009-08-29 at 12:56 +0100, Markus Gesmann wrote:
 Dear R-help,
 
 Suppose I have the following data:
 
 df=data.frame(x=1:10, y=c(1,2,3,4,5,12,14,16,18,20))
 plot(y~x, df, t=b)
 
 How can I fit a model which estimates the slopes between x = 1-5, 5-6,  
 and 6-10?

Does the segmented package do what you want?

G

 
 Adding the factor f:
 
 df$f -  gl(2,5)
 
 Allows me to fit a linear model with interaction
 
 lm(y ~ x:f, data=df)
 
 which gives me the slope of 1 and 2 between 1-5, and 6-10  
 respectively, however it can not cope with the change from 5 to 6.
 
 I would appreciate if someone could point me into the right direction.
 
 Many thanks
 
 Markus
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

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


Re: [R] Google's R Style Guide

2009-08-29 Thread spencerg
 S3 is very easy to change;  S4 is very difficult.  This provides 
advantages and disadvantages for both.  Some people swear by one and 
curse the other -- from both sides. 



 S4 is newer, and I have had problems in the past finding out what 
S4 methods are available and finding acceptable documentation more 
generally.  The methods function quickly identifies all installed S3 
methods for an object of a particular class and all classes for which a 
given generic function has S3 methods.  The help page for methods now 
says, See Also: ... For S4, 'showMethods', 'Methods'.  I very much 
appreciate the work of whomever added this See Also, because the next 
time I want to find S4 methods, it will make it easier for me to do so.  
Chambers (1998) Programming with Data (Springer) described many things 
that did not work in any version of S to which I've had access.  
Chambers (2008) Software for Data Analysis (Springer) is better but 
still includes many things that I could not get to work without writing 
the author. 



 I use S3 routinely, and I've tried multiple times to learn more 
about S4 methods without yet achieving a critical mass that would allow 
me to use them.  S-Plus and R have been my primary tool for well over 15 
years. 



 Hope this helps.
 Spencer


Corrado wrote:
I do not understand why one should use a S3 preferentially on a S4 class, if 
S4 is more rigorous.


(The premiss is I am a newbie with OO programming in R, and would like to 
understand what is the proper way to OO program in R )


Regards



On Saturday 29 August 2009 16:23:39 hadley wickham wrote:
  

An opening curly brace should never go on its own line;


I tend to do this:

f - function()
{
 if (TRUE)
   {
 cat(TRUE!!\n)
   } else {
 cat(FALSE!!\n)
   }
}

(I don't usually put one-liners in if/else blocks; here I would have
used ifelse)

I haven't seen many others format code in this way. Is there an
objective reason for this (such as the rule for the trailing }) or
is this just aesthetics?
  

It's probably just aesthetics.  I don't like it because it increases
the number of lines without much real benefit - indenting already
gives you all the hints you need.

Hadley





  



--
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567

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


Re: [R] adding factor scores back to an incomplete dataset...

2009-08-29 Thread Mark Difford

Hi David, Phil,

Phil Spector wrote:
 David - 
 Here's the easiest way I've been able to come up with.

Easiest? You are making unnecessary work for yourselves and seem not to
understand the purpose of ?naresid (i.e. na.action = na.exclude). Why not
take the simple route that I gave, which really is R's + factanal's route.
Using Phil's data as example:

##
dat = data.frame(matrix(rnorm(100),20,5)) 
dat[3,4] = NA 
dat[12,3] = NA

scrs - factanal(~X1+X2+X3+X4+X5, data=dat,factors=2,scores='regression',
 na.action=na.exclude)$scores
TrueDat - merge(dat,scrs,by=0,all.x=TRUE,sort=FALSE)
TrueDat

Regards, Mark.


David G. Tully wrote:
 
 Thanks, Prof Spector. Your first solution works well for me.
 
 Phil Spector wrote:
 David -
Here's the easiest way I've been able to come up with. I'll provide 
 some sample data to make things clearer (hint, hint):

 dat = data.frame(matrix(rnorm(100),20,5))
 dat[3,4] = NA
 dat[12,3] = NA
 scrs = factanal(na.omit(dat),factors=2,scores='regression')$scores
 rownames(scrs) = rownames(na.omit(dat))
 newdat = merge(dat,scrs,by=0,all.x=TRUE,sort=FALSE)

 This will result in the observations with missing values being
 at the end of the data frame.  If you want the original order
 (assuming default row names), you could use

 newdat[order(as.numeric(newdat$Row.names)),]

 A somewhat more complicated approach is, in some sense, more direct:

 dat$Factor1 = NA
 dat$Factor2 = NA
 dat[rownames(na.omit(dat[,-c(6,7)])),c('Factor1','Factor2')] = 
 +
 factanal(na.omit(dat[,-c(6,7)]),factors=2,scores='regression')$scores

 The order of the data is preserved.
 - Phil Spector
  Statistical Computing Facility
  Department of Statistics
  UC Berkeley
  spec...@stat.berkeley.edu








 On Tue, 25 Aug 2009, David G. Tully wrote:

 I am sure there is a simple way to do the following, but i haven't 
 been able to find it. I am hoping a merciful soul on R-help could 
 point me in the right direction.

 I am doing a factor analysis on survey data with missing values. to 
 do this, I run:

 FA1-factanal(na.omit(DATA), factors = X, rotation = 'oblimin', 
 scores = 'regression')

 Now that I have my factors and factor scores, I want to add those 
 scores back to my original dataset so I can plot factor scores by 
 demographics. However, when I try to add the scores back to the 
 original data frame, the variables are of different lengths.

 Is there a way to subset from my original data set that will work 
 with factanal() and preserve the original rows or that will allow me 
 to append the factor scores back onto the original dataset with the 
 proper rows and NAs where there could be no data?

 Again, I apologize if I am missing something basic. I am a self 
 taught R user and couldn't find an answer to this question.

 Thanks in advance,
  David

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

 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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/adding-factor-scores-back-to-an-incomplete-dataset...-tp25140959p25204698.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] Numeric, 2 ??? as a result of marix???

2009-08-29 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Wolfgang Polasek
 Sent: Friday, August 28, 2009 3:16 PM
 To: r-help@r-project.org
 Subject: [R] Numeric, 2 ??? as a result of marix???
 
 Strange things are going on in R, if you reshape a matrix in R:
  g=gretldata[1:2,]
  g
Empfang   Versand  Transit  Inland AuslandSumS
 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
 2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
  dim(g)
 [1] 2 6
  as.vector(g)
Empfang   Versand  Transit  Inland AuslandSumS
 1 787844.0 1307176.6 223395.4 1474726 16199.1 3809341
 2 421473.1  306445.4 448801.2 1779402 14445.6 2970567
  gg=matrix(as.vector(g),nrow=1,byrow=TRUE)
  gg
  [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
 [1,] Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
 

This last printout is how R prints a matrix whose contents
are a list.  Rouughly, if a list element has length 1 its value
is printed; otherwise its type and, usually, length are printed.
E.g.,

 z-matrix(list(one=1, two=exp(0:1), three=c(i,ii,iii),
four=quote(log(x))), nrow=2)
 z
 [,1]  [,2]   
[1,] 1 Character,3
[2,] Numeric,2 Expression 

When you see a printout that you cannot interepret, try using the str()
function to print the object and you may be able to make sense of it.

 str(z)
List of 4
 $ : num 1
 $ : num [1:2] 1 2.72
 $ : chr [1:3] i ii iii
 $ : language log(x)
 - attr(*, dim)= int [1:2] 2 2

matrix(data.frame(...)) strips the attributes from the data.frame,
making
it a list, then attaches dimensions to the list, making an object like
'z'
above.  as.matrix(data.frame()) makes a matrix that is roughly
equivalent
to the data.frame input.

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

  Help please,the docu on thids is lousy!!!.
 Wolfgang
 
   [[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] Google's R Style Guide

2009-08-29 Thread diegol


Max Kuhn wrote:
 
 Perhaps this is obvious, but Ive never understood why this is the
 general convention:
 
 An opening curly brace should never go on its own line;
 
 I tend to do this:
 
 f - function()
 {
   if (TRUE)
 {
   cat(TRUE!!\n)
 } else {
   cat(FALSE!!\n)
 }
 }
 

I favor your approach. BUT I add one more level of indentation. Your
function would look like:

f - function()
  {
if (TRUE)
  {
cat(TRUE!!\n)
  } else {
cat(FALSE!!\n)
  }
  }

This way I quickly identify the beginning of the function, which is the one
line at the top of the expression AND sticking to the left margin.
In your code you use this same indentation in the if/else construct. I find
it also useful for the function itself.

-
~~
Diego Mazzeo
Actuarial Science Student
Facultad de Ciencias Económicas
Universidad de Buenos Aires
Buenos Aires, Argentina
-- 
View this message in context: 
http://www.nabble.com/Google%27s-R-Style-Guide-tp25189544p25204937.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] Within factor random factor

2009-08-29 Thread Juliet Hannah
Let's say that location defined a group, and observations may
be more similar in a group. You could account for this similarity
with the following model.

model1 -lme(X~CorP,random=~1|location,data=mydata,method=ML)

This fits a random intercept model grouped by location. This would
assume that the slope of the regression of X on CorP is the same by
group, but the group means differ.

CorP  defines the fixed part of the model.

 random=  ~1 defines the random part (in this case just an intercept).

The last part specifies the estimation method.

 I would recommend reading through Pinheiro and Bates. Brady West's
Linear Mixed Models also has nice examples. It is difficult (for me)
to assess your analysis. For example, I can see how location and
subject would be random if you had repeated measures on subjects
within location. These concepts take some time to understand.  I would
recommend working on this problem with someone experienced in this. In
your studying, if you come across specific questions about nlme or
lme4, there is a mixed model mailing list that is very helpful. One
more note, your response takes values between 0 and 1, so you would
have to make sure the residuals are behaving ok (read up on
diagnostics).

Best,

Juliet


2009/8/26 細田弘吉 khos...@med.kobe-u.ac.jp:
 Hi,
 I am quite new to R and trying to analyze the following data.  I have 28
 controls and 25 patients.  I measured X values of 4 different locations
 (A,B,C,D) in the brain image of each subject.  And X ranges from 0 to 1.
 I think control or patient is a between subject factor and location is
 a within subject factor.  So,

 controls: 28
 patients: 25 (unbalanced data set)
 respone measure: X values (ranging 0 to 1)
 fixed factor: control vs. patient (between subject factor)
 random factor: location (level: A,B,C,D ;no order) (within subject factor)
 random factor: subjectID 1-53

 My data looks like this;

 CorPX   locationsubjectID
 control 0.708   A   1
 control 0.648   A   2
 patient 0.638   C   3
 control 0.547   D   4
 patient 0.632   B   5
 control 0.723   C   6
 ...

 I want to know
 (a) if there is a significant difference between controls and patients
 in X values.
 (b) where (A,B,C,D?) the difference is between controls and patients in
 X values.  (There may be an interaction)

 I constructed linear mixed model with lme as followings;

 (1) model1 - lme(X ~ CorP*location, random= ~ 1| subjectID, mydata)

 (2) model2 - lme(X ~ CorP*location, random= ~ location| subjectID, mydata)

 I am not familiar with lme syntax.  I'm just wondering which formula
 [(1) or (2)] is appropriate for my model to know answers of (a) and (b)
 questions.  Or may be both of the formulas are wrong.

 I would appreciate it very much if somebody could help me.

 Sincerely,

 Kohkichi Hosoda

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

2009-08-29 Thread Ted Harding
On 29-Aug-09 17:51:54, diegol wrote:
 Max Kuhn wrote:
 Perhaps this is obvious, but Ive never understood why this is the
 general convention:
 
 An opening curly brace should never go on its own line;
 
 I tend to do this:
 
 f - function()
 {
   if (TRUE)
 {
   cat(TRUE!!\n)
 } else {
   cat(FALSE!!\n)
 }
 }
 
 I favor your approach. BUT I add one more level of indentation.
 Your function would look like:
 
 f - function()
   {
 if (TRUE)
   {
 cat(TRUE!!\n)
   } else {
 cat(FALSE!!\n)
   }
   }
 
 This way I quickly identify the beginning of the function, which is
 the one line at the top of the expression AND sticking to the left
 margin.
 In your code you use this same indentation in the if/else construct.
 I find it also useful for the function itself.

When I want to rely on indentation and vertical alignments to keep
track of program structure, I would tend to write the above like

  f -
  function()
  { if (TRUE)
{
  cat(TRUE!!\n) 
} else
{
  cat(FALSE!!\n)
}
  }

so that an opening { is aligned with the keyword it is associated
with, and then at the end of the block so also is the closing }.

However, in this case (if I keep all the {...} for the sake of
structure) I would also tend to save on lines with

  f -
  function()
  { if (TRUE)
{ cat(TRUE!!\n)  } else
{ cat(FALSE!!\n) }
  }

which is still clear enough for me. This probably breaks most
guidelines! But in practice it depends on what it is, and on
how readily I find I can read it.

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 29-Aug-09   Time: 19:26:51
-- 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] RODBC: how to set the data-source?

2009-08-29 Thread Oliver Bandel
Dumblauskas, Jerry jerry.dumblauskas at credit-suisse.com writes:

 
 OK
 
 Is your PostGres server on the same Linux box you are running R on?
 Sample values
 Server  = 169.49.30.69 (localhost host means you are on the same
 box)
 Port= 2700 (make sure your port is correct)
 
 Also, I am not seeing your id and password
 
 I use the signature
 CONNREAD - odbcConnect(READDBID, uid = READDBUSER, pwd = READDBPWD,
 believeNRows=FALSE)
 
 So for you this would be
 channel - odbcConnect(rtestdb, uid=rtest, pwd=???,
 believeNRows=FALSE)

As I do all stuff locally I have not configures for necessity of login
username/passwd.
So i assume I can omit it. With psql I don't need one.
??? means my password I assume...

Well, I have configured it, so I maybe need it?
With psql not, but I have set it. I think it will not be checked from the db.

Why did you make uid=rtest?
rtest is the name of the database.
I use oliver as db-login-name.



 
 The alloc error means you are close...
 
 Make sure you can connect to your DB outside of R as well

With psql I can login.
And I need no passwd.
Maybe it's different for the R-connection, instead of starting psql from the
shell? But I don't think so.

Ciao,
   Oliver

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


Re: [R] RODBC: how to set the data-source?

2009-08-29 Thread Oliver Bandel
Dumblauskas, Jerry jerry.dumblauskas at credit-suisse.com writes:
[...]
 The alloc error means you are close...
[...]

Ah, ok, I see...

...then you are right that Driver has to be the path to
the shared library. :-)


Oliver

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

2009-08-29 Thread njhuang86

Hey guys,

I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1, 2, 3, 1,
2, 3... with the '1, 2, 3' repeated over 10 times.

Also, is there a simple method to generate 1, 1, 1, 2, 2, 2, 3, 3, 3?

Anyways, any help with be greatly appreciated!
-- 
View this message in context: 
http://www.nabble.com/Sequence-generation-tp25205593p25205593.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] Sequence generation

2009-08-29 Thread RIOS,ALFREDO ARTURO


I think should work

rep(c(1,2,3),10)


Alfredo


On Sat Aug 29 15:14:15 EDT 2009, njhuang86 njhuan...@yahoo.com 
wrote:




Hey guys,

I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1, 
2, 3, 1,

2, 3... with the '1, 2, 3' repeated over 10 times.

Also, is there a simple method to generate 1, 1, 1, 2, 2, 2, 3, 
3, 3?


Anyways, any help with be greatly appreciated!
-- View this message in context: 
http://www.nabble.com/Sequence-generation-tp25205593p25205593.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.







--
RIOS,ALFREDO ARTURO

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] memisc/mtable: show only estimates (one line)

2009-08-29 Thread Frederik Elwert
Hello!

mtable from memisc package shows estimates and standard error by
default. I wanted to show only the estimates. Therefore, I created a new
template:

setCoefTemplate(simple=c(est=($est:#)($p:*)))

But this leads to the following error when used:

 mtable(berk0,berk1,berk2, coef.style=simple)
Error in dim(ans) - newdims : 
  dims [product 1] do not match the length of object [2]

Did I make a mistake? Or is it not possible to show only estimates (or,
rather, have only one element in a template) with memisc?

Thanks,
Frederik



 8

library(memisc)

# Models from mtable example
berkeley - aggregate(Table(Admit,Freq)~.,data=UCBAdmissions)

berk0 - glm(cbind(Admitted,Rejected)~1,data=berkeley,family=binomial)
berk1 -
glm(cbind(Admitted,Rejected)~Gender,data=berkeley,family=binomial)
berk2 - glm(cbind(Admitted,Rejected)~Gender
+Dept,data=berkeley,family=binomial)

# Create one-line style
setCoefTemplate(simple=c(est=($est:#)($p:*)))

mtable(berk0,berk1,berk2, coef.style=simple)

8

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


Re: [R] Sequence generation

2009-08-29 Thread David Winsemius


On Aug 29, 2009, at 3:14 PM, njhuang86 wrote:



Hey guys,

I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1, 2,  
3, 1,

2, 3... with the '1, 2, 3' repeated over 10 times.


As noted earlier

rep(1:3, 10)



Also, is there a simple method to generate 1, 1, 1, 2, 2, 2, 3, 3, 3?


?gl

the gl function will return a factor and it can be converted to a  
vector:


 gl(10, 3)
 [1] 1  1  1  2  2  2  3  3  3  4  4  4  5  5  5  6  6  6  7  7  7   
8  8  8  9  9  9  10 10 10

Levels: 1 2 3 4 5 6 7 8 9 10
 as.numeric(gl(10,3))
 [1]  1  1  1  2  2  2  3  3  3  4  4  4  5  5  5  6  6  6  7  7  7   
8  8  8  9  9  9 10 10 10


Or you can cobble something together like:
 floor(1 + 0:29 / 3)
 [1]  1  1  1  2  2  2  3  3  3  4  4  4  5  5  5  6  6  6  7  7  7   
8  8  8  9  9  9 10 10 10


which depends on the higher precedence of the : operator over  
infix-+ and /.


?Syntax

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Sequence generation

2009-08-29 Thread Barry Rowlingson
On Sat, Aug 29, 2009 at 8:14 PM, njhuang86njhuan...@yahoo.com wrote:

 Hey guys,

 I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1, 2, 3, 1,
 2, 3... with the '1, 2, 3' repeated over 10 times.

rep(1:3,10)  # rep repeats its first argument according to the number
in its second argument

 Also, is there a simple method to generate 1, 1, 1, 2, 2, 2, 3, 3, 3?

 The second argument can be a vector, so what you want here is:

 rep(1:3,c(3,3,3))

 but you can create the second vector here also using rep! Hence:

 rep(1:3,rep(3,3))

Barry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] RODBC: missing files? (Re: RODBC: how to set the data-source?)

2009-08-29 Thread Oliver Bandel
Hello,


I stracet the R session when trying to connect to the database.


Strange, that /etc/odbc.ini first should be opened with Append-mode:


open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES (Permission
denied)
open(/etc/odbc.ini, O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=259, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7f305ae91000
read(3, [rtestdb]\nDescription = rtest..., 4096) = 259


also strange: the file will be read many, many times.
I did not pasted it here, but /etc/odbc.ini and /etc/passwd
are read very often.

I assume for each entry in /etc/passwd until the one that os looked for,
/etc/odbc.ini is opened once...
...maybe I should test this hypothesis... looks strange.





The next stuff also looks strange: as if there is a problem because of a missing
locale-stuff?


mprotect(0x7f30565eb000, 4096, PROT_READ) = 0
open(/usr/share/locale/de_DE.UTF-8/LC_MESSAGES/libc.mo, O_RDONLY) = -1 ENOENT
(No such file or directory)
open(/usr/share/locale/de_DE.utf8/LC_MESSAGES/libc.mo, O_RDONLY) = -1 ENOENT
(No such file or directory)
open(/usr/share/locale/de_DE/LC_MESSAGES/libc.mo, O_RDONLY) = -1 ENOENT (No
such file or directory)
open(/usr/share/locale/de.UTF-8/LC_MESSAGES/libc.mo, O_RDONLY) = -1 ENOENT (No
such file or directory)
open(/usr/share/locale/de.utf8/LC_MESSAGES/libc.mo, O_RDONLY) = -1 ENOENT (No
such file or directory)
open(/usr/share/locale/de/LC_MESSAGES/libc.mo, O_RDONLY) = -1 ENOENT (No such
file or directory)
open(/usr/share/locale-langpack/de_DE.UTF-8/LC_MESSAGES/libc.mo, O_RDONLY) =
-1 ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de_DE.utf8/LC_MESSAGES/libc.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de_DE/LC_MESSAGES/libc.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de.UTF-8/LC_MESSAGES/libc.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de.utf8/LC_MESSAGES/libc.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de/LC_MESSAGES/libc.mo, O_RDONLY) = -1 ENOENT
(No such file or directory)
open(/usr/share/locale/de_DE.UTF-8/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1 ENOENT
(No such file or directory)
open(/usr/share/locale/de_DE.utf8/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1 ENOENT
(No such file or directory)
open(/usr/share/locale/de_DE/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1 ENOENT (No
such file or directory)
open(/usr/share/locale/de.UTF-8/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1 ENOENT
(No such file or directory)
open(/usr/share/locale/de.utf8/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1 ENOENT (No
such file or directory)
open(/usr/share/locale/de/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1 ENOENT (No such
file or directory)
open(/usr/share/locale-langpack/de_DE.UTF-8/LC_MESSAGES/RODBC.mo, O_RDONLY) =
-1 ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de_DE.utf8/LC_MESSAGES/RODBC.mo, O_RDONLY) =
-1 ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de_DE/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de.UTF-8/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de.utf8/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de/LC_MESSAGES/RODBC.mo, O_RDONLY) = -1 ENOENT
(No such file or directory)
semop(294920, 0x7fff62e9c110, 2)= 0
semop(294920, 0x7fff62e9c130, 1)= 0
open(/usr/share/locale/de_DE.UTF-8/LC_MESSAGES/R-RODBC.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale/de_DE.utf8/LC_MESSAGES/R-RODBC.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale/de_DE/LC_MESSAGES/R-RODBC.mo, O_RDONLY) = -1 ENOENT (No
such file or directory)
open(/usr/share/locale/de.UTF-8/LC_MESSAGES/R-RODBC.mo, O_RDONLY) = -1 ENOENT
(No such file or directory)
open(/usr/share/locale/de.utf8/LC_MESSAGES/R-RODBC.mo, O_RDONLY) = -1 ENOENT
(No such file or directory)
open(/usr/share/locale/de/LC_MESSAGES/R-RODBC.mo, O_RDONLY) = -1 ENOENT (No
such file or directory)
open(/usr/share/locale-langpack/de_DE.UTF-8/LC_MESSAGES/R-RODBC.mo, O_RDONLY)
= -1 ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de_DE.utf8/LC_MESSAGES/R-RODBC.mo, O_RDONLY) =
-1 ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de_DE/LC_MESSAGES/R-RODBC.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de.UTF-8/LC_MESSAGES/R-RODBC.mo, O_RDONLY) =
-1 ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de.utf8/LC_MESSAGES/R-RODBC.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de/LC_MESSAGES/R-RODBC.mo, O_RDONLY) = -1
ENOENT (No such file or directory)
open(/usr/share/locale-langpack/de_DE.UTF-8/LC_MESSAGES/R.mo, O_RDONLY) = -1
ENOENT (No such file 

Re: [R] RODBC: missing files? (Re: RODBC: how to set the data-source?)

2009-08-29 Thread Oliver Bandel
Oliver Bandel oliver at first.in-berlin.de writes:

[...]
 I assume for each entry in /etc/passwd until the one that os looked for,
 /etc/odbc.ini is opened once...
 ...maybe I should test this hypothesis... looks strange.
[...]

No, my loginname is in line 31 of /etc/passwd.

oli...@siouxsie:~$ grep -n etc\/odbc.ini LOG 
4006:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4024:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4042:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4310:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4311:open(/etc/odbc.ini, O_RDONLY) = 3
4326:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4327:open(/etc/odbc.ini, O_RDONLY) = 3
4342:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4343:open(/etc/odbc.ini, O_RDONLY) = 3
4358:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4359:open(/etc/odbc.ini, O_RDONLY) = 3
4374:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4375:open(/etc/odbc.ini, O_RDONLY) = 3
4390:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4391:open(/etc/odbc.ini, O_RDONLY) = 3
4406:open(/etc/odbc.ini, O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES
(Permission denied)
4407:open(/etc/odbc.ini, O_RDONLY) = 3
oli...@siouxsie:~$ grep -c etc\/odbc.ini LOG 
17


Looks nevertheless quite strange.

Ciao,
   Oliver

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


Re: [R] Google's R Style Guide

2009-08-29 Thread Duncan Murdoch

On 29/08/2009 12:03 PM, Corrado wrote:
I do not understand why one should use a S3 preferentially on a S4 class, if 
S4 is more rigorous.


As Spencer said, most people use either one or the other.  I think it's 
generally a bad idea to mix them (there are strange semantics if you do 
that), so using just one is a good idea.


Which do you use?  If you're a programmer working in a group, whatever 
the rest of the group uses.  It appears from the style guide that at 
Google that's S3.  That would be my choice too, but there are lots of 
people who are very successful with S4.


Now I'm tempted to try to guess what character traits would make someone 
prefer S4, but I think I'd only get into trouble ;-).


Duncan Murdoch



(The premiss is I am a newbie with OO programming in R, and would like to 
understand what is the proper way to OO program in R )


Regards



On Saturday 29 August 2009 16:23:39 hadley wickham wrote:

An opening curly brace should never go on its own line;

I tend to do this:

f - function()
{
 if (TRUE)
   {
 cat(TRUE!!\n)
   } else {
 cat(FALSE!!\n)
   }
}

(I don't usually put one-liners in if/else blocks; here I would have
used ifelse)

I haven't seen many others format code in this way. Is there an
objective reason for this (such as the rule for the trailing }) or
is this just aesthetics?

It's probably just aesthetics.  I don't like it because it increases
the number of lines without much real benefit - indenting already
gives you all the hints you need.

Hadley






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


Re: [R] Best R text editors?

2009-08-29 Thread Tal Galili
Great question to put up here :)

My preferences:
1) notepad++ with NPPToR
2) tinn-R (was leading for a long time, but recently I decided to go with
notepad++ )
3) JGR / RCMDR (although RCMDR can be connected with the previous ones - and
I wish it would get more developed)

With the rest I didn't have experience in.

Jedit - I am still waiting for Romain (from
http://romainfrancois.blog.free.fr/) to release his connection of R to Jedit
(What he showed me in useR 2009, was better then anything else I have seen
until then)


Best,
Tal Galili








On Thu, Aug 27, 2009 at 10:43 PM, Jonathan Greenberg
greenb...@ucdavis.eduwrote:

 Quick informal poll: what is everyone's favorite text editor for working
 with R?  I'd like to hear from people who are using editors that have some
 level of direct R interface (e.g. Tinn-R, Komodo+SciViews).  Thanks!

 --j

 --

 Jonathan A. Greenberg, PhD
 Postdoctoral Scholar
 Center for Spatial Technologies and Remote Sensing (CSTARS)
 University of California, Davis
 One Shields Avenue
 The Barn, Room 250N
 Davis, CA 95616
 Cell: 415-794-5043
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307

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




-- 
--


My contact information:
Tal Galili
Phone number: 972-50-3373767
FaceBook: Tal Galili
My Blogs:
http://www.r-statistics.com/
http://www.talgalili.com
http://www.biostatistics.co.il

[[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] Google's R Style Guide

2009-08-29 Thread John Sorkin
For my money, and perspective as one who has written a compiler, this reflects 
a failing of the R parser. Both

if (TRUE) {
 cat(TRUE!!\n)
}
else
{
 cat(FALSE!!\n)
}

and


if (TRUE) 
  {
 cat(TRUE!!\n)
  }
else
  {
 cat(FALSE!!\n)
  }

are easy to read, and should be accepted as a valid if . . . . else statement.

John


John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

 Philippe Grosjean phgrosj...@sciviews.org 8/29/2009 12:12 PM 
Max Kuhn wrote:
 Perhaps this is obvious, but Ive never understood why this is the
 general convention:
 
 An opening curly brace should never go on its own line;
 
 I tend to do this:
 
 f - function()
 {
   if (TRUE)
 {
   cat(TRUE!!\n)
 } else {
   cat(FALSE!!\n)
 }
 }
 
 (I don't usually put one-liners in if/else blocks; here I would have
 used ifelse)
 
 I haven't seen many others format code in this way. Is there an
 objective reason for this (such as the rule for the trailing }) or
 is this just aesthetics?

I think the problem is not much putting the opening brace after 
function(), or after if (...), like you do. The problem is putting the 
else at a new line like in:

if (TRUE) {
 cat(TRUE!!\n)
}
else
{
 cat(FALSE!!\n)
}

When you source this code, the first part until the first closing brace 
is considered complete by the R parser, and then, 'else' is considered 
as the begining of a new command, which is a syntax error:

  if (TRUE) {
+ cat(TRUE!!\n)
+ }
TRUE!!
  else
Error: syntax error
  {
+ cat(FALSE!!\n)
+ }
FALSE!!

If you put the same code in a function, you got the expected behaviour:

  f - function () {
+ if (TRUE) {
+ cat(TRUE!!\n)
+ }
+ else
+ {
+ cat(FALSE!!\n)
+ }
+ }
  f()  # No syntax error!
TRUE!!

Thus, this is technical reason for NOT putting else on another line.
For the rest, I share Hadley's feeling that you consumes too much 
lines and I tend to prefer the regular R syntax you got when you 
source your code.
Best,

Philippe


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

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}

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


Re: [R] Google's R Style Guide

2009-08-29 Thread hadley wickham
But in interactive use the R parser is constrained to work a line at a
time (unless it could predict what you were going to type next ;)

Hadley

On Sat, Aug 29, 2009 at 5:05 PM, John Sorkinjsor...@grecc.umaryland.edu wrote:
 For my money, and perspective as one who has written a compiler, this 
 reflects a failing of the R parser. Both

 if (TRUE) {
     cat(TRUE!!\n)
 }
 else
 {
     cat(FALSE!!\n)
 }

 and


 if (TRUE)
  {
     cat(TRUE!!\n)
  }
 else
  {
     cat(FALSE!!\n)
  }

 are easy to read, and should be accepted as a valid if . . . . else statement.

 John


 John David Sorkin M.D., Ph.D.
 Chief, Biostatistics and Informatics
 University of Maryland School of Medicine Division of Gerontology
 Baltimore VA Medical Center
 10 North Greene Street
 GRECC (BT/18/GR)
 Baltimore, MD 21201-1524
 (Phone) 410-605-7119
 (Fax) 410-605-7913 (Please call phone number above prior to faxing)

 Philippe Grosjean phgrosj...@sciviews.org 8/29/2009 12:12 PM 
 Max Kuhn wrote:
 Perhaps this is obvious, but Ive never understood why this is the
 general convention:

 An opening curly brace should never go on its own line;

 I tend to do this:

 f - function()
 {
   if (TRUE)
     {
       cat(TRUE!!\n)
     } else {
       cat(FALSE!!\n)
     }
 }

 (I don't usually put one-liners in if/else blocks; here I would have
 used ifelse)

 I haven't seen many others format code in this way. Is there an
 objective reason for this (such as the rule for the trailing }) or
 is this just aesthetics?

 I think the problem is not much putting the opening brace after
 function(), or after if (...), like you do. The problem is putting the
 else at a new line like in:

 if (TRUE) {
     cat(TRUE!!\n)
 }
 else
 {
     cat(FALSE!!\n)
 }

 When you source this code, the first part until the first closing brace
 is considered complete by the R parser, and then, 'else' is considered
 as the begining of a new command, which is a syntax error:

   if (TRUE) {
 +     cat(TRUE!!\n)
 + }
 TRUE!!
   else
 Error: syntax error
   {
 +     cat(FALSE!!\n)
 + }
 FALSE!!

 If you put the same code in a function, you got the expected behaviour:

   f - function () {
 +     if (TRUE) {
 +         cat(TRUE!!\n)
 +     }
 +     else
 +     {
 +         cat(FALSE!!\n)
 +     }
 + }
   f()  # No syntax error!
 TRUE!!

 Thus, this is technical reason for NOT putting else on another line.
 For the rest, I share Hadley's feeling that you consumes too much
 lines and I tend to prefer the regular R syntax you got when you
 source your code.
 Best,

 Philippe


 Thanks,

 Max

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

 Confidentiality Statement:
 This email message, including any attachments, is for ...{{dropped:15}}

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


Re: [R] Google's R Style Guide

2009-08-29 Thread Duncan Murdoch

On 29/08/2009 6:05 PM, John Sorkin wrote:

For my money, and perspective as one who has written a compiler, this reflects 
a failing of the R parser. Both

if (TRUE) {
 cat(TRUE!!\n)
}
else
{
 cat(FALSE!!\n)
}

and


if (TRUE) 
  {

 cat(TRUE!!\n)
  }
else
  {
 cat(FALSE!!\n)
  }

are easy to read, and should be accepted as a valid if . . . . else statement.


And if you enter

if (FALSE) {
 cat(TRUE!!\n)
}

at the console, how long should it wait before it decides the else isn't 
coming?


Duncan Murdoch

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


Re: [R] how to generate a random correlation matrix with restrictions

2009-08-29 Thread Kingsford Jones
Thanks Ravi -- with my limited linear algebra skills I was assuming
invertible symmetric was sufficient (rather than just necessary) for
positive definiteness.  So, the open challenge is to generate a pd
matrix of dimension 100 with r_ij = 1 if i=j else -1 r_ij 1, with
about 10% of the elements .9.

I tried for a bit without luck, but I can offer another way to
generate a pd matrix:

ev - runif(100) # choose some positive eigenvalues
U - svd(matrix(runif(1), nc=100))$u  # an orthogonal matrix
pdM - U %*% diag(ev) %*% t(U)


Kingsford



On Fri, Aug 28, 2009 at 9:41 PM, Ravi Varadhanrvarad...@jhmi.edu wrote:
 Hi Kingsford,

 There is more structure to a correlation matrix than that meets the eye!  
 Your method will produce a matrix R that looks like a correlation matrix, 
 but beware - it is an impostor!

 You can obtain a valid correlation matrix, Q, from the impostor R by using 
 the `nearPD' function in the Matrix package, which finds the positive 
 definite matrix Q that is nearest to R.  However, note that when R is far 
 from a positive-definite matrix, this step may give a Q that does not have 
 the desired property.

 require(Matrix)

 R - matrix(runif(16), ncol=4)

 R - (R * lower.tri(R)) + t(R * lower.tri(R))

 diag(R) - 1

 eigen(R)$val

 Q - nearPD(R, posd.tol=1.e-04)$mat

 eigen(Q)$val

 max(abs(Q - R))  # maximum discrepancy between R and Q

 Another easy way to produce a valid correlation matrix is:

 R - matrix(runif(36), ncol=6)

 RtR - R %*% t(R)

 Q - cov2cor(RtR)

 But this does not have the property that the correlations are uniformly 
 distributed.

 Hope this helps,
 Ravi.

 

 Ravi Varadhan, Ph.D.
 Assistant Professor,
 Division of Geriatric Medicine and Gerontology
 School of Medicine
 Johns Hopkins University

 Ph. (410) 502-2619
 email: rvarad...@jhmi.edu


 - Original Message -
 From: Kingsford Jones kingsfordjo...@gmail.com
 Date: Friday, August 28, 2009 10:12 pm
 Subject: Re: [R] how to generate a random correlation matrix with       
 restrictions
 To: Ning Ma pnin...@gmail.com
 Cc: r-help@r-project.org


 Ahh -- Mark Leeds just pointed out off-list that it was supposed to be
 a correlation matrix.

 Perhaps

 R - matrix(runif(1), ncol=100)
 R - (R * lower.tri(R)) + t(R * lower.tri(R))
 diag(R) - 1

 These are of course uniformly distributed positive correlations.

 Kingsford


 On Fri, Aug 28, 2009 at 7:36 PM, Kingsford
 Joneskingsfordjo...@gmail.com wrote:
   R - matrix(runif(1), ncol=100)
 
  hth,
 
  Kingsford Jones
 
  On Fri, Aug 28, 2009 at 7:26 PM, Ning Mapnin...@gmail.com wrote:
  Hi,
 
  How can I generate a random 100x100 correlation matrix, R={r_ij},
  where about 10% of r_ij are greater than 0.9
 
  Thanks in advance.
 
  __
  R-help@r-project.org mailing list
 
  PLEASE do read the posting guide
  and provide commented, minimal, self-contained, reproducible code.
 
 

 __
 R-help@r-project.org mailing list

 PLEASE do read the posting guide
 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] Sequence generation

2009-08-29 Thread Greg Snow
Or just use the 'each' argument to seq.

-- 
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 Barry Rowlingson
 Sent: Saturday, August 29, 2009 1:50 PM
 To: njhuang86
 Cc: r-help@r-project.org
 Subject: Re: [R] Sequence generation
 
 On Sat, Aug 29, 2009 at 8:14 PM, njhuang86njhuan...@yahoo.com wrote:
 
  Hey guys,
 
  I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1, 2,
 3, 1,
  2, 3... with the '1, 2, 3' repeated over 10 times.
 
 rep(1:3,10)  # rep repeats its first argument according to the number
 in its second argument
 
  Also, is there a simple method to generate 1, 1, 1, 2, 2, 2, 3, 3, 3?
 
  The second argument can be a vector, so what you want here is:
 
  rep(1:3,c(3,3,3))
 
  but you can create the second vector here also using rep! Hence:
 
  rep(1:3,rep(3,3))
 
 Barry
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] lrm in Design

2009-08-29 Thread loch1

Hello everybody,
I am trying to do a logistic regression model with lrm() from the design
package. I am comparing to groups with different medical outcome which can
either be good or bad. In the help file it says that lrm codes al
responses to 0,1,2,3, etc. internally and does so in alphabetical order. I
would guess this means bad=0 and good=1.

My question: I am trying to figure out the connection between my factors and
my response. Which probability is being calculated that of good or bad (1 or
0, respectively).

I'm not sure whether I made clear what I was trying to say but will be very
grateful for all help.
-- 
View this message in context: 
http://www.nabble.com/lrm-in-Design-tp25206737p25206737.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] std.error

2009-08-29 Thread Jim Lemon

Mcdonald, Grant wrote:

dear sir,

i am trying to calculate the standard error of my data (x),

i have tried se(x, na.rm=TRUE)
and std.error(x)

neither have worked and i cannot find an alternative


  

Hi Grant,
There is a convenience function std.error that calculates the 
conventional standard error of the mean in the plotrix package. Make 
sure that it does the calculation that you want.


Jim

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


Re: [R] std.error

2009-08-29 Thread Bill.Venables
Standard error usually means the estimated standard deviation of a parameter 
estimate, e.g. the sample mean.

Perhaps you mean the estimated standard deviation of the data.  If so

sdev - sd(x, na.rm = TRUE)

If you want the standard error of the mean there are several ways of doing it.  
Perhaps the simplest is

seMean - sd(x, na.rm=TRUE)/sqrt(length(na.omit(x)))

missing values complicate the issue just a little.

Bill Venables.

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Mcdonald, Grant [grant.mcdonal...@imperial.ac.uk]
Sent: 29 August 2009 04:50
To: r-help@R-project.org
Subject: [R] std.error

dear sir,

i am trying to calculate the standard error of my data (x),

i have tried se(x, na.rm=TRUE)
and std.error(x)

neither have worked and i cannot find an alternative


sorry to bother with such a basic problem
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 generate a random correlation matrix with restrictions

2009-08-29 Thread Ravi Varadhan
Yes, Kingsford.  This problem does not appear to be trival.  I am not sure if 
there is any literature on this.  I have seen a paper by Davies and Higham (BIT 
2000) on Stable generation of correlation matrices.  There is also a paper by 
Harry Joe on generating correlation matrices with given partial correlation 
structure.  I am not sure if these papers would be helpful for this problem.  
Of course, one can readily cook up an ad-hoc, trial-error procedure to generate 
the type of matrices that Ning wants.

By the way, the easiest way to generate a PD matrix is:

N - 10
amat - matrix(rnorm(N*N), N, N)
A - amat %*% t(amat)  # A is PD 

Best,
Ravi



Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Kingsford Jones kingsfordjo...@gmail.com
Date: Saturday, August 29, 2009 7:43 pm
Subject: Re: [R] how to generate a random correlation matrix with restrictions
To: Ravi Varadhan rvarad...@jhmi.edu
Cc: Ning Ma pnin...@gmail.com, r-help@r-project.org


 Thanks Ravi -- with my limited linear algebra skills I was assuming
  invertible symmetric was sufficient (rather than just necessary) for
  positive definiteness.  So, the open challenge is to generate a pd
  matrix of dimension 100 with r_ij = 1 if i=j else -1 r_ij 1, with
  about 10% of the elements .9.
  
  I tried for a bit without luck, but I can offer another way to
  generate a pd matrix:
  
  ev - runif(100) # choose some positive eigenvalues
  U - svd(matrix(runif(1), nc=100))$u  # an orthogonal matrix
  pdM - U %*% diag(ev) %*% t(U)
  
  
  Kingsford
  
  
  
  On Fri, Aug 28, 2009 at 9:41 PM, Ravi Varadhanrvarad...@jhmi.edu wrote:
   Hi Kingsford,
  
   There is more structure to a correlation matrix than that meets the 
 eye!  Your method will produce a matrix R that looks like a 
 correlation matrix, but beware - it is an impostor!
  
   You can obtain a valid correlation matrix, Q, from the impostor R 
 by using the `nearPD' function in the Matrix package, which finds 
 the positive definite matrix Q that is nearest to R.  However, note 
 that when R is far from a positive-definite matrix, this step may give 
 a Q that does not have the desired property.
  
   require(Matrix)
  
   R - matrix(runif(16), ncol=4)
  
   R - (R * lower.tri(R)) + t(R * lower.tri(R))
  
   diag(R) - 1
  
   eigen(R)$val
  
   Q - nearPD(R, posd.tol=1.e-04)$mat
  
   eigen(Q)$val
  
   max(abs(Q - R))  # maximum discrepancy between R and Q
  
   Another easy way to produce a valid correlation matrix is:
  
   R - matrix(runif(36), ncol=6)
  
   RtR - R %*% t(R)
  
   Q - cov2cor(RtR)
  
   But this does not have the property that the correlations are 
 uniformly distributed.
  
   Hope this helps,
   Ravi.
  
   
  
   Ravi Varadhan, Ph.D.
   Assistant Professor,
   Division of Geriatric Medicine and Gerontology
   School of Medicine
   Johns Hopkins University
  
   Ph. (410) 502-2619
   email: rvarad...@jhmi.edu
  
  
   - Original Message -
   From: Kingsford Jones kingsfordjo...@gmail.com
   Date: Friday, August 28, 2009 10:12 pm
   Subject: Re: [R] how to generate a random correlation matrix with   
     restrictions
   To: Ning Ma pnin...@gmail.com
   Cc: r-help@r-project.org
  
  
   Ahh -- Mark Leeds just pointed out off-list that it was supposed 
 to be
   a correlation matrix.
  
   Perhaps
  
   R - matrix(runif(1), ncol=100)
   R - (R * lower.tri(R)) + t(R * lower.tri(R))
   diag(R) - 1
  
   These are of course uniformly distributed positive correlations.
  
   Kingsford
  
  
   On Fri, Aug 28, 2009 at 7:36 PM, Kingsford
   Joneskingsfordjo...@gmail.com wrote:
 R - matrix(runif(1), ncol=100)
   
hth,
   
Kingsford Jones
   
On Fri, Aug 28, 2009 at 7:26 PM, Ning Mapnin...@gmail.com wrote:
Hi,
   
How can I generate a random 100x100 correlation matrix, R={r_ij},
where about 10% of r_ij are greater than 0.9
   
Thanks in advance.
   
__
R-help@r-project.org mailing list
   
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
   
   
  
   __
   R-help@r-project.org mailing list
  
   PLEASE do read the posting guide
   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] lrm in Design

2009-08-29 Thread Gabor Grothendieck
See:
https://stat.ethz.ch/pipermail/r-help/2009-July/204192.html

and also other posts in that thread.

On Sat, Aug 29, 2009 at 6:02 PM, loch1l...@gmx.li wrote:

 Hello everybody,
 I am trying to do a logistic regression model with lrm() from the design
 package. I am comparing to groups with different medical outcome which can
 either be good or bad. In the help file it says that lrm codes al
 responses to 0,1,2,3, etc. internally and does so in alphabetical order. I
 would guess this means bad=0 and good=1.

 My question: I am trying to figure out the connection between my factors and
 my response. Which probability is being calculated that of good or bad (1 or
 0, respectively).

 I'm not sure whether I made clear what I was trying to say but will be very
 grateful for all help.
 --
 View this message in context: 
 http://www.nabble.com/lrm-in-Design-tp25206737p25206737.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] Infinite != NaN?

2009-08-29 Thread Michael Hannon
Greetings.  I somehow had the impression that an infinite number, as obtained 
by dividing by zero, for instance, would be flagged as both missing (NA) and 
not a number (NaN).  It appears that I was wrong on both counts, although the 
is.finite function correctly returns FALSE in such a case.  Please see the 
appended for some details.  I guess that the bottom line is that R works the 
way it works, but if you can add anything that will further instruct me, I'd 
appreciate it.

Thanks.

-- Mike


 y - 2/0

 y
[1] Inf

 is.na(y)
[1] FALSE

 is.nan(y)
[1] FALSE

 is.finite(y)
[1] FALSE

 z - log(-1)
Warning message:
In log(-1) : NaNs produced

 z
[1] NaN

 is.nan(z)
[1] TRUE

 is.na(z)
[1] TRUE

-

R version 2.9.2 (2009-08-24)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

-

$ uname -a
Linux xxx.localdomain 2.6.29.6-217.2.16.fc11.x86_64 #1 SMP Mon Aug 24 
17:17:40 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

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


Re: [R] Infinite != NaN?

2009-08-29 Thread David Winsemius

It is not clear that you have read the help page that arise with:

 ?Inf

Note:

In R, basically all mathematical functions (including basic  
Arithmetic), are supposed to work properly with +/- Inf and NaN as  
input or output.


The basic rule should be that calls and relations with Infs really are  
statements with a proper mathematical limit.


Also:

 Inf+Inf
[1] Inf
 Inf-Inf
[1] NaN
 -2/0
[1] -Inf
 Inf*Inf
[1] Inf
 Inf*(-Inf)
[1] -Inf

On Aug 29, 2009, at 9:58 PM, Michael Hannon wrote:

Greetings.  I somehow had the impression that an infinite number, as  
obtained by dividing by zero, for instance, would be flagged as both  
missing (NA) and not a number (NaN).  It appears that I was  
wrong on both counts, although the is.finite function correctly  
returns FALSE in such a case.  Please see the appended for some  
details.  I guess that the bottom line is that R works the way it  
works, but if you can add anything that will further instruct me,  
I'd appreciate it.




So I suppose the obvious further instruction is to read the help pages.


Thanks.

-- Mike



y - 2/0



y

[1] Inf


is.na(y)

[1] FALSE


is.nan(y)

[1] FALSE


is.finite(y)

[1] FALSE


z - log(-1)

Warning message:
In log(-1) : NaNs produced


z

[1] NaN


is.nan(z)

[1] TRUE


is.na(z)

[1] TRUE

-




David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] RFE: vectorize URLdecode

2009-08-29 Thread Horner, Jeff
Not sure if your context is rapache, but if so urlEncode() and urlDecode() are 
available to you and are vectorized:

http://biostat.mc.vanderbilt.edu/rapache/manual.html#urlEncode

Best,

Jeff


-Original Message-
From: r-help-boun...@r-project.org on behalf of Jack Tanner
Sent: Sat 8/29/2009 9:31 AM
To: r-h...@stat.math.ethz.ch
Subject: [R] RFE: vectorize URLdecode
 
In R 2.9.2,

 URLdecode(c(a%20b, b%20c))
[1] a b
Warning message:
In charToRaw(URL) : argument should be a character vector of length 1
all but the first element will be ignored

Could URLdecode be modified to actually process all elements of the vector, not
just the first?

Thanks in advance

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


[[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] aggregating irregular time series

2009-08-29 Thread R_help Help
Hi,

I have a couple of aggregation operations that I don't know how to
accomplish. Let me give an example. I have the following irregular
time series

time  x
10:00:00.02120
10:00:00.22420
10:00:01.00219
10:00:02:94820

1) For each entry time, I'd like to get sum of x for the next 2
seconds (excluding itself). Using the above example, the output should
be

timesumx
10:00:00.02139
10:00:00.22419
10:00:01.44220
10:00:02:948 0

2) For each i-th of x in the series, what's the first passage time to
x[i]-1. I.e. the output should be

time   firstPassgeTime
10:00:00.0210.981
10:00:00.2240.778
10:00:01.442NA
10:00:02:948NA

Is there any shortcut function that allows me to do the above? Thank you.

adschai

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] POSIX time conversion doesn't display digit

2009-08-29 Thread R_help Help
Hi,

I have the following string that I converted to a POSIXct:

 a - 2009-08-24 10:00:00.213
 a.p - strptime(a,%Y-%m-%d %H:%M:%OS)
 as.double(as.POSIXct(a.p))
[1] 1251122400

I can't seem to get the decimal fraction of .213 out by casting to
double or numeric. Is there anyway to make sure that POSIXct spits
that out? Thank you.

adschai

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