Re: [R] read.spss (package foreign) and SPSS 15.0 files

2007-04-05 Thread Prof Brian Ripley

On Thu, 5 Apr 2007, Michael Conklin wrote:

Not being the developer I cannot answer definitively but, as a frequent 
user of SPSS files I can give you my experience.


1) The unrecognized coding is perhaps due to the locale of the SPSS 
installation. I have had success reading in files from version 15 but 
often encounter that error when the file was created with data that 
included some foreign language. I often receive survey files that were 
administered in a non-English language and that is when I usually see 
the error.


That is what is surmised in this recent R-devel thread:

https://stat.ethz.ch/pipermail/r-devel/2007-April/045238.html

although it may also happen in an English locale (since after all Windows 
uses codepage 1252, not ASCII, for American 'English').


The next release of package foreign will give a warning (rather than an 
error) with an unrecognized encoding and recognize a few more.


2) My experience with the "Warning - unrecognized record type" message 
is that it has no effect whatsoever on the data file.


3) Others on the list have noted that you are safer exporting POR files 
instead of SAV files from SPSS. Both are read by the read.spss function.


The R Data Import/Export manual recommends an open format such as .csv.
(Look like John Kane has yet to read it )  R does have quite extensive 
facilities for dealing with encodings in text files.




Hope that helps.



Michael Conklin
Chief Methodologist - Advanced Analytics
MarketTools, Inc.


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Kane
Sent: Thursday, April 05, 2007 7:45 PM
To: RINNER Heinrich; r-help@stat.math.ethz.ch
Subject: Re: [R] read.spss (package foreign) and SPSS 15.0 files


--- RINNER Heinrich <[EMAIL PROTECTED]>
wrote:


Hello,

does anyone have experience with reading SPSS
Version 15.0 files into R (version 2.4.1, WinXP)?

I have long been sucessfully reading SPSS files with
read.spss from the wonderful foreign package, but
somehow after upgrading from SPSS14 to SPSS15 I seem
to have problems.

Trying a simple example, where test.sav is a SPSS
15.0 data file consisting of x1=c(1,2,3) and
x2=c("a","b","c"), I get this:

read.spss(file = "C:\\temp\\test.sav")

Fehler in read.spss(file = "C:\\temp\\test.sav") :
error reading system-file header
Zusätzlich: Warning message:
C:\temp\test.sav: File-indicated character
representation code (Unknown) is not ASCII

version infos:
R version 2.4.1 (under WinXP)
foreign version 0.8-18

Has anyone experienced the same, and can give a
solution here (possibly other than "downgrade to
SPSS14.0" ;-))?

Regards,
Heinrich.


Heck. I'd be happy to get an answer to what is
happening here:

mac <- spss.get("H:/ONTH/Raw.data/Follow.sav")

Warning message:
H:/ONTH/Raw.data/Follow.sav: Unrecognized record type
7, subtype 16 encountered in system file

I have taken to exporting the file to a delimited
format and reading it into R since I cannot trust the
R import.



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] translating sas proc mixed to lme()

2007-04-05 Thread toby909
Hi All

I am trying to translate a proc mixed into a lme() syntax. It seems that I was 
able to do it for part of the model, but a few things are still different.

It is a 2-level bivariate model (some call it a pseudo-3-level model).

PROC MIXED DATA=psdata.bivar COVTEST METHOD = ml;
CLASS cluster_ID individual_id variable_id ;
MODEL y = Dp Dq / SOLUTION NOINT;
RANDOM Dp Dq / SUBJECT = cluster_ID TYPE=UN G GCORR;
REPEATED variable_id / SUBJECT = individual_ID(cluster_ID) TYPE=UN R RCORR;
RUN;

Here is my try:

dta = sqlQuery(odbcConnect("sasodbc", believeNRows=FALSE), "select * from 
psdata.bivar")
v = lme(Y~Dp+Dq-1, data=dta, random=~Dp+Dq-1|cluster_ID, method="ML", 
weights=varIdent(form=~1|Dp), corr=corCompSymm(, ~1|cluster_ID/individual_id))

Below is the data if you want to try, and also the outputs that I got from sas 
and R. What is different is the denominator DF for the F test for significance 
of the fixed effects.

Thanks for your hints.

Toby







DATA bivar;
INPUT cluster_ID individual_id variable_id $ Y;
CARDS;
1 1 P 11.1
1 1 Q 20.6
1 2 P 13.3
1 2 Q 16.0
1 3 P 14.3
1 3 Q 15.1
2 4 P 18.6
2 4 Q 8.9
2 5 P 19.2
2 5 Q 7.3
2 6 P 21.5
2 6 Q 3.6
3 7 P 10.4
3 7 Q 2.7
3 8 P 11.1
3 8 Q 3.2
3 9 P 12.8
3 9 Q 5.0
;
run;
data psdata.bivar;
set bivar;
IF variable_ID eq "P" then Dp = 1; else Dp = 0;
IF variable_ID eq "Q" then Dq = 1; else Dq = 0;
run;




The SAS System
16:26 Friday, March 30, 2007   1

The Mixed Procedure

  Model Information

Data Set WORK.BIVAR
Dependent Variable   Y
Covariance Structure Unstructured
Subject Effects  cluster_ID,
 individua(cluster_I)
Estimation MethodML
Residual Variance Method None
Fixed Effects SE Method  Model-Based
Degrees of Freedom MethodContainment


 Class Level Information

ClassLevelsValues

cluster_ID31 2 3
individual_id 91 2 3 4 5 6 7 8 9
variable_id   2P Q


Dimensions

Covariance Parameters 6
Columns in X  2
Columns in Z Per Subject  2
Subjects  3
Max Obs Per Subject   6


  Number of Observations

Number of Observations Read  18
Number of Observations Used  18
Number of Observations Not Used   0


 Iteration History

IterationEvaluations-2 Log Like   Criterion

0  1   109.94855540
1  187.30141251  0.


   Convergence criteria met.


   Estimated R Matrix for
  individua(cluster_I) 1 1

RowCol1Col2

   1  2.1822 -2.4739
   2 -2.4739  5.8522


   Estimated R Correlation
 Matrix for
  individua(cluster_I) 1 1

RowCol1Col2

   1  1. -0.6923
   2 -0.6923  1.


Estimated G Matrix

  cluster_
RowEffectID  Col1Col2

   1Dp112.4667 -2.3250
   2Dq1-2.3250 32.1414


  Estimated G Correlation Matrix

  cluster_
RowEffectID  Col1Col2

   1Dp1 1. -0.1161
   2Dq1-0.1161  1.


Covariance Parameter Estimates

Standard Z
Cov ParmSubject Estimate   Error
ValuePr Z

UN(1,1) cluster_ID   12.4667 10.7811  1.16
0.1238
UN(2,1) cluster_ID   -2.3250 12.3933 -0.19
0.8512
UN(2,2) cluster_ID   32.1414 27.8589  1.15
0.1243
UN(1,1) individua(cluster_I)  2.1822  1.2599  1.73
0.0416
UN(2,1) individua(cluster_I) -2.4739  1.7744 -1.39
0.1633
UN(2,2) individua(cluster_I)  5.8522  3.3788  1.73
0.0416


   Fit Statistics

-2 Log Likelihood87.3
AIC (smaller is better) 103.3
AICC (smaller is better)119.3
BIC (smaller is better)  96.1


  Null Model Likelihood Ratio Test

DFChi-Square  Pr > ChiSq

 5 22.65  0.0004


 Solution for Fixed Effects

  Standard
EffectEstimate   Error  DFt ValuePr > |t|

Dp 14.7000  2.0971   2   7.01  0.0198
Dq  9.1556  3.3711   2   2.72  0.1130


   Type 3 Tests of Fixed Effects

   Num Den
Effect  DF  DFF ValuePr > F

Dp   1   2  49.130.0198
Dq   1   2   7.380.1130







 > summary(v)
Linear mixed-effects model fit by maximum likelihood
  Data: dta
AIC  BIClogLik
   103.3014 110.4244 -43.65071

Random effects:
  Formula: ~Dp + Dq - 1 | cluste

Re: [R] read.spss (package foreign) and SPSS 15.0 files

2007-04-05 Thread Michael Conklin
Not being the developer I cannot answer definitively but, as a frequent user of 
SPSS files I can give you my experience.

1) The unrecognized coding is perhaps due to the locale of the SPSS 
installation. I have had success reading in files from version 15 but often 
encounter that error when the file was created with data that included some 
foreign language. I often receive survey files that were administered in a 
non-English language and that is when I usually see the error.

2) My experience with the "Warning - unrecognized record type" message is that 
it has no effect whatsoever on the data file.

3) Others on the list have noted that you are safer exporting POR files instead 
of SAV files from SPSS. Both are read by the read.spss function.

Hope that helps.



Michael Conklin
Chief Methodologist - Advanced Analytics
MarketTools, Inc.


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Kane
Sent: Thursday, April 05, 2007 7:45 PM
To: RINNER Heinrich; r-help@stat.math.ethz.ch
Subject: Re: [R] read.spss (package foreign) and SPSS 15.0 files


--- RINNER Heinrich <[EMAIL PROTECTED]>
wrote:

> Hello,
> 
> does anyone have experience with reading SPSS
> Version 15.0 files into R (version 2.4.1, WinXP)?
> 
> I have long been sucessfully reading SPSS files with
> read.spss from the wonderful foreign package, but
> somehow after upgrading from SPSS14 to SPSS15 I seem
> to have problems.
> 
> Trying a simple example, where test.sav is a SPSS
> 15.0 data file consisting of x1=c(1,2,3) and
> x2=c("a","b","c"), I get this:
> > read.spss(file = "C:\\temp\\test.sav")
> Fehler in read.spss(file = "C:\\temp\\test.sav") : 
> error reading system-file header
> Zusätzlich: Warning message:
> C:\temp\test.sav: File-indicated character
> representation code (Unknown) is not ASCII 
> 
> version infos:
> R version 2.4.1 (under WinXP)
> foreign version 0.8-18
> 
> Has anyone experienced the same, and can give a
> solution here (possibly other than "downgrade to
> SPSS14.0" ;-))?
> 
> Regards,
> Heinrich.

 Heck. I'd be happy to get an answer to what is
happening here:
> mac <- spss.get("H:/ONTH/Raw.data/Follow.sav")
Warning message:
H:/ONTH/Raw.data/Follow.sav: Unrecognized record type
7, subtype 16 encountered in system file

I have taken to exporting the file to a delimited
format and reading it into R since I cannot trust the
R import.

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


Re: [R] MANOVA with repeated measurements

2007-04-05 Thread John Fox
Dear Mark,

Take a look at the Anova() function in the car package. There's an example
of a repeated-measures MANOVA in ?Anova (the last example). Also see
?anova.mlm.

I hope this helps,
 John


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Mark 
> E. Olszewski
> Sent: Thursday, April 05, 2007 5:03 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] MANOVA with repeated measurements
> 
> Hello,
> 
> I have a question regarding performing manova.  I have an 
> experiment where I want to measure 10 output variables for 3 
> different measurement methods.  Since each of the methods 
> requires some user interaction, I would also like to include 
> repeated measures for each of the output variables to include 
> intraobserver variability in the design.  
> 
> How can I perform such a repeated-measures manova using R?  I 
> think I have found how to perform the non-repeated version of 
> this experiment based on previous posts, but I am having 
> trouble generalizing to the repeated-measures version (maybe 
> I am just too tired today).
> 
> Thanks in advance,
> 
> Mark
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] lm() intercept at the end, rather than at the beginning

2007-04-05 Thread Gabor Grothendieck
Try this.  It captures the output of x and sets idx to the line numbers
of the coefficients, rearranging their order in the next line and printing
them out in the line after that.

my.print.summary.lm <- function(x, ...) {
out <- capture.output(x)
idx <- seq(grep("Intercept", out), grep("---", out)-1)
out[idx] <- out[c(idx[-1], idx[1])]
for(lin in replace(out, idx, out[rev(idx)])) cat(lin, "\n")
invisible(x)
}
z <- summary(lm(conc ~ uptake, CO2))
my.print.summary.lm(z)  



On 4/5/07, Dimitri Szerman <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I wonder if someone has already figured out a way of making
>
> summary(mylm)   # where mylm is an object of the class lm()
>
> to print the "(Intercept)" at  the last line, rather than the first
> line of the output. I don't know about, say, biostatistics, but in
> economics the intercept is usually the least interesting of the
> parameters of a regression model. That's why, say, Stata prints by
> default the intercept at the end. Just a suggestion for
> R-developers...
>
> Thanks,
> Dimitri
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] changing existing graphs optimally

2007-04-05 Thread John Kane

--- hadley wickham <[EMAIL PROTECTED]> wrote:

> On 4/5/07, Greg Snow
> <[EMAIL PROTECTED]> wrote:
> > Using traditional and lattice(trellis) graphics,
> the usual approach is
> > to have your plotting commands in a script file
> (under windows you can
> > use the one with the GUI, in linux/unix you can
> have a text editor open
> > with the script).  Then either run the commands by
> copy/paste or using
> > the source function.  Then when you see something
> tha you would like to
> > change, just do the edits and rerun the code.
> >
> > The ggplot package has some functionality for
> first specifying the data
> > that you want plotted, then how you want it
> plotted, then the command to
> > actually create the plot.  You can then modify how
> you want it plotted
> > and replot again.
> 
> Yes, the current version of ggplot can this,
> although it's not very
> well exposed to the user.  The current development
> version uses the
> idea of plot modification extensively, and it's also
> very easy to take
> the same plot specification and use it with a
> different data set.
> 
> Hadley

Well,  back to ggplot! I had forgotten this aspect of
ggplot and was mucking about with plot. With any luck
you've save me a lot of time.

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


Re: [R] read.spss (package foreign) and SPSS 15.0 files

2007-04-05 Thread John Kane

--- RINNER Heinrich <[EMAIL PROTECTED]>
wrote:

> Hello,
> 
> does anyone have experience with reading SPSS
> Version 15.0 files into R (version 2.4.1, WinXP)?
> 
> I have long been sucessfully reading SPSS files with
> read.spss from the wonderful foreign package, but
> somehow after upgrading from SPSS14 to SPSS15 I seem
> to have problems.
> 
> Trying a simple example, where test.sav is a SPSS
> 15.0 data file consisting of x1=c(1,2,3) and
> x2=c("a","b","c"), I get this:
> > read.spss(file = "C:\\temp\\test.sav")
> Fehler in read.spss(file = "C:\\temp\\test.sav") : 
> error reading system-file header
> Zusätzlich: Warning message:
> C:\temp\test.sav: File-indicated character
> representation code (Unknown) is not ASCII 
> 
> version infos:
> R version 2.4.1 (under WinXP)
> foreign version 0.8-18
> 
> Has anyone experienced the same, and can give a
> solution here (possibly other than "downgrade to
> SPSS14.0" ;-))?
> 
> Regards,
> Heinrich.

 Heck. I'd be happy to get an answer to what is
happening here:
> mac <- spss.get("H:/ONTH/Raw.data/Follow.sav")
Warning message:
H:/ONTH/Raw.data/Follow.sav: Unrecognized record type
7, subtype 16 encountered in system file

I have taken to exporting the file to a delimited
format and reading it into R since I cannot trust the
R import.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] lm() intercept at the end, rather than at the beginning

2007-04-05 Thread Dimitri Szerman
Hi,

I wonder if someone has already figured out a way of making

summary(mylm)   # where mylm is an object of the class lm()

to print the "(Intercept)" at  the last line, rather than the first
line of the output. I don't know about, say, biostatistics, but in
economics the intercept is usually the least interesting of the
parameters of a regression model. That's why, say, Stata prints by
default the intercept at the end. Just a suggestion for
R-developers...

Thanks,
Dimitri

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


Re: [R] Reasons to Use R

2007-04-05 Thread John Kane

--- Lorenzo Isella <[EMAIL PROTECTED]> wrote:

>
> (4)finally, a list of the advantages for using R
> over commercial
> statistical packages. The money-saving in itself is
> not a reason good
> enough and some people are scared by the lack of
> professional support,
> though this mailing list is simply wonderful.
>
Given that I can do as much if not more with R (in
most cases) than with commercial software, as an
independent consultant,  'cost' is a very significant
factor. 

A very major advantage of R is the money-saving.  Have
a look at
http://www.spss.com/stores/1/Software_Full_Version_C2.cfm

 and convince me that cost ( for an independent
contractor) is not a good reason.

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


Re: [R] creating a data frame from a list

2007-04-05 Thread Bert Gunter
Dmitri:

As you apparently have not received a reply

IMHO, one of the glories of R is the ease with which you can create de novo
solutions for little problems like this yourself. While there may be more
efficient,robust, and elegant solutions already available, it can frequently
be considerably more time consuming to find and figure them out, as you
appear to have experienced. (And once outside base R and standard packages,
documentation can be problematic).

Anyway, whether you agree with that propoganda or not, here is a little
function (no claim for elegance or efficiency!) that does what you want, I
think:

makeFrame<-function(xlist)
{
allnames <- sort(unique(unlist(sapply(xlist,names
data.frame(lapply(xlist,function(y,an)structure(y[match(an,names(y))],
names=NULL),
an=allnames),row.names=allnames)
}

##test it

> lst
$a
A B 
1 8 

$b
A B C 
2 3 0 

$c
B D 
2 0 

> makeFrame(lst)
   a  b  c
A  1  2 NA
B  8  3  2
C NA  0 NA
D NA NA  0
 

Cheers,

Bert Gunter
Genentech Nonclinical Statistics
South San Francisco, CA 94404
650-467-7374



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Dimitri Szerman
Sent: Thursday, April 05, 2007 11:58 AM
To: R-Help
Subject: [R] creating a data frame from a list

Dear all,

A few months ago, I asked for your help on the following problem:

I have a list with three (named) numeric vectors:

> lst = list(a=c(A=1,B=8) , b=c(A=2,B=3,C=0), c=c(B=2,D=0) )
> lst
$a
A B
1 8

$b
A B C
2 3 0

$c
B D
2 0

Now, I'd love to use this list to create the following data frame:

> dtf = data.frame(a=c(A=1,B=8,C=NA,D=NA),
+  b=c(A=2,B=3,C=0,D=NA),
+  c=c(A=NA,B=2,C=NA,D=0) )

> dtf
   ab c
A   1   2  NA
B   8   3 2
C NA   0  NA
D NA NA0

That is, I wish to "merge" the three vectors in the list into a data frame
by their "(row)"names.

And I got the following answer:

library(zoo)
z <- do.call(merge, lapply(lst, function(x) zoo(x, names(x
rownames(z) <- time(z)
coredata(z)

However, it does not seem to be working. Here's what I get when I try it:

> lst = list(a=c(A=1,B=8) , b=c(A=2,B=3,C=0), c=c(B=2,D=0) )
> library(zoo)
> z <- do.call(merge, lapply(lst, function(x) zoo(x, names(x
Error in if (freq > 1 && identical(all.equal(freq, round(freq)),
TRUE)) freq <- round(freq) :
missing value where TRUE/FALSE needed
In addition: Warning message:
NAs introduced by coercion

and z was not created.

Any ideas on what is going on here?
Thank you,
Dimitri

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Logistic/Cox regression: Parameter estimates directly from model matrix

2007-04-05 Thread Kaspar Rufibach
Hi out there

Is there a way to get the estimated coefficients in a logistic / Cox
regression without having to specify a 'formula' but by only giving the
model matrix?

Example for Cox regression:

## predictors
n <- 50
q1 <- rnorm(n)
q2 <- rgamma(n, 2, 2)
Z <- cbind(q1, q2)

## response
ttf <- rexp(n)
tf <- round(runif(n))

## compute estimates
res <- coxph(Surv(ttf, tf) ~ q1 + q2)
r <- res$coef

My goal is to have a function

estFromModelMatrix <- function(tf, ttf, Z){

  /* do something meaningful using built-in functions */

  return(r)}

I have written such functions myself using LL - maximization from
scratch, but these are slower than the built-in functions. Since I
intend to do some simulations (where I specify the model matrix, but not
want to give a 'formula' manually for each simulation scenario), it
would be nice to have a function estFromModelMatrix().

I searched the help extensively, but did not find a way to do this.

Hope I was clear enough, any help is appreciated!
Kaspar Rufibach


-- 
__
Kaspar Rufibach
Department of Statistics -- Sequoia Hall
390 Serra Mall
Stanford University
Stanford, CA 94305-4065

mailto:[EMAIL PROTECTED]
skype:kasparrufibach
http://www.stanford.edu/~kasparr

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


Re: [R] binom.test() query

2007-04-05 Thread Duncan Murdoch
On 4/5/2007 5:35 PM, (Ted Harding) wrote:
> Hi Folks,
> The recent correspondence about "strange fisher.test result",
> and especially Peter Dalgaard's reply on Tue 03 April 2007
> (which I want to investigate further) led me to take a close
> look at the code for binom.test().
> 
> I now have a query!
> 
> The code for the two-sided case computes the p-value as follows:
> 
>   if (p == 0) (x == 0)
>   else
> if (p == 1) (x == n) 
> else {
>   relErr <- 1 + 1e-07
>   d <- dbinom(x, n, p)
>   m <- n * p 
>   if (x == m) 1
>   else
> ## PVAL if x < m
> if (x < m) {
>   i <- seq(from = ceiling(m), to = n)
>   y <- sum(dbinom(i, n, p) <= d * relErr)
>## here:
>   pbinom(x,n,p) + pbinom(n-y,n,p,lower=FALSE)
> }
> ## PVAL if x > m:
> else {
>   i <- seq(from = 0, to = floor(m))
>   y <- sum(dbinom(i, n, p) <= d * relErr)
>## here:
>   pbinom(y-1,n,p) + pbinom(x-1,n,p,lower=FALSE)
> }
>   }
> }
> 
> The case "x < m" will do for my query (since it is the same
> for the case "x > m").
> 
> If I understand the code correctly, when x (the observed binomial
> number) is less than m (its expected value on the null hypothesis
> being tested), then the p-value is the total probability in the
> lower tail, from 0 to x inclusive, plus a "bit".
> 
> The "bit" is the probability in the upper tail of those value
> from (n-y) to n, where y is the number of values of i greater
> than or equal to (if m is an integer) m such that
> 
>dbinom(i,n,p) <= d*(1 + 1e-07) = dbinom(x,n,p)*(1 + 1e-07).
> 
> or, in other words, ignoring the "1e-07", the values of i
> which have binomial probability (on the NH) less than or equal
> to the probability of x.
> 
> So, for x < m = n*p, the lower-tail contribution to the p-value
> is the probability that X <= x, while the upper-tail contribution
> is the probability that (X >= m)&(dbinom(X,n,p) <= dbinom(x,n,p)).
> 
> Now that is not so asymmetric as it looks, since for x < m = n*p
> the values of dbinom(i,n,p) decrease as i decreases for i < x,
> so in fact the left=hand tail is similarly the probability
> that (X <= m)&(dbinom(X,n,p) <= dbinom(x,n,p)). In effect, therefore,
> ignoring the "1e-07", we are simply calculating the probability
> of "dbinom(X,n,p) <= dbinom(x,n,p)" overall.
> 
> But what is the purpose of the "1e-07"? I can see that it might
> cause a miscalculation if the real intention is to simply sum
> the probabilties dbinom(X,n,p) which are less than or equal to
> dbinom(x,n,p).


I think you're looking at the deparsed binom.test.  For tricky things 
like this, it's sometimes worth looking at the source

(which in this case is in 
https://svn.r-project.org/R/trunk/src/library/stats/R/binom.test.R)

and has the comment:

## Do
##   d <- dbinom(0 : n, n, p)
##   sum(d[d <= dbinom(x, n, p)])
## a bit more efficiently ...
## Note that we need a little fuzz.

So I expect the answer to your question is that the 1e-7 is there to 
avoid rounding error causing you to incorrectly leaving out an exactly 
equal probability.

As to whether the difference in your example below matters, I'd say not. 
  With discrete distributions you don't have a right to expect 
continuous p-values, so having a decision go the wrong way in a manually 
constructed nasty example is always going to be a possibility.  Exactly 
equal probabilities will happen when p=0.5, and that's a more important 
case to get right than p=0.3527785166.

Duncan Murdoch

> 
> For example (and I'm being a bit mischievous here, but I'm
> theoretically entitled to be):
> 
>p<-0.3527785166
>n<-20
>x<-(4:10)
>print(cbind(x,dbinom(x,n,p)),digits=10)
> 
>   x  
> [1,]  4 0.07114577135
> [2,]  5 0.12409328342
> [3,]  6 0.16909761793
> [4,]  7 0.18433877225
> [5,]  8 0.16327483787
> [6,]  9 0.11866078116
> [7,] 10 0.07114577154
> 
> Now I run the standard binom.test():
> 
> x<-4 ; n<-20 ; p<-0.3527785166 ; binom.test(x,n,p)$p.value
> [1] 0.2405347
> 
> 
> Next, I modify the code for binom.test so that relErr <- 1
> (instead of 1 + 1e-07), and I call this new function
> binom.test.0 and run it on the same data:
> 
> binom.test.0(x,n,p)$p.value
> [1] 0.1693889
> 
> The difference is the value of dbinom(10,n,p) = 0.07114577...
> 
> So the "1e-07" has done its dirty work -- it has added 40% to
> my p-value! Admittedly it wasn't particularly significant to
> start with, at 0.17 (in round numbers); but it's much less so
> at 0.24, and if I wanted I'm sure I could construct a really
> "significant" example!
> 
> Anyway, I dare say the factor (1 + 1e-07) is there as a precaution
> against some possible numerical mishap (though I can't see what
> it might be), but the fa

[R] binom.test() query

2007-04-05 Thread Ted Harding
Hi Folks,
The recent correspondence about "strange fisher.test result",
and especially Peter Dalgaard's reply on Tue 03 April 2007
(which I want to investigate further) led me to take a close
look at the code for binom.test().

I now have a query!

The code for the two-sided case computes the p-value as follows:

  if (p == 0) (x == 0)
  else
if (p == 1) (x == n) 
else {
  relErr <- 1 + 1e-07
  d <- dbinom(x, n, p)
  m <- n * p 
  if (x == m) 1
  else
## PVAL if x < m
if (x < m) {
  i <- seq(from = ceiling(m), to = n)
  y <- sum(dbinom(i, n, p) <= d * relErr)
   ## here:
  pbinom(x,n,p) + pbinom(n-y,n,p,lower=FALSE)
}
## PVAL if x > m:
else {
  i <- seq(from = 0, to = floor(m))
  y <- sum(dbinom(i, n, p) <= d * relErr)
   ## here:
  pbinom(y-1,n,p) + pbinom(x-1,n,p,lower=FALSE)
}
  }
}

The case "x < m" will do for my query (since it is the same
for the case "x > m").

If I understand the code correctly, when x (the observed binomial
number) is less than m (its expected value on the null hypothesis
being tested), then the p-value is the total probability in the
lower tail, from 0 to x inclusive, plus a "bit".

The "bit" is the probability in the upper tail of those value
from (n-y) to n, where y is the number of values of i greater
than or equal to (if m is an integer) m such that

   dbinom(i,n,p) <= d*(1 + 1e-07) = dbinom(x,n,p)*(1 + 1e-07).

or, in other words, ignoring the "1e-07", the values of i
which have binomial probability (on the NH) less than or equal
to the probability of x.

So, for x < m = n*p, the lower-tail contribution to the p-value
is the probability that X <= x, while the upper-tail contribution
is the probability that (X >= m)&(dbinom(X,n,p) <= dbinom(x,n,p)).

Now that is not so asymmetric as it looks, since for x < m = n*p
the values of dbinom(i,n,p) decrease as i decreases for i < x,
so in fact the left=hand tail is similarly the probability
that (X <= m)&(dbinom(X,n,p) <= dbinom(x,n,p)). In effect, therefore,
ignoring the "1e-07", we are simply calculating the probability
of "dbinom(X,n,p) <= dbinom(x,n,p)" overall.

But what is the purpose of the "1e-07"? I can see that it might
cause a miscalculation if the real intention is to simply sum
the probabilties dbinom(X,n,p) which are less than or equal to
dbinom(x,n,p).

For example (and I'm being a bit mischievous here, but I'm
theoretically entitled to be):

   p<-0.3527785166
   n<-20
   x<-(4:10)
   print(cbind(x,dbinom(x,n,p)),digits=10)

  x  
[1,]  4 0.07114577135
[2,]  5 0.12409328342
[3,]  6 0.16909761793
[4,]  7 0.18433877225
[5,]  8 0.16327483787
[6,]  9 0.11866078116
[7,] 10 0.07114577154

Now I run the standard binom.test():

x<-4 ; n<-20 ; p<-0.3527785166 ; binom.test(x,n,p)$p.value
[1] 0.2405347


Next, I modify the code for binom.test so that relErr <- 1
(instead of 1 + 1e-07), and I call this new function
binom.test.0 and run it on the same data:

binom.test.0(x,n,p)$p.value
[1] 0.1693889

The difference is the value of dbinom(10,n,p) = 0.07114577...

So the "1e-07" has done its dirty work -- it has added 40% to
my p-value! Admittedly it wasn't particularly significant to
start with, at 0.17 (in round numbers); but it's much less so
at 0.24, and if I wanted I'm sure I could construct a really
"significant" example!

Anyway, I dare say the factor (1 + 1e-07) is there as a precaution
against some possible numerical mishap (though I can't see what
it might be), but the fact that it can make such a difference in
special cases means that I think we need to know what it's doing
and why -- just in case we don't need whatever it's supposed
to be there for.

After all, if I were going to use the values of dbinom(x,n,p)
as the ordering of the sample space for the test, I'd simply
get PVAL as

sum(dbinom(which(dbinom((0:n),n,p)<=dbinom(x,n,p))-1,n,p))
[1] 0.1693889

(as above!).

Comments?

With thanks,
Ted.


E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 05-Apr-07   Time: 22:29:21
-- XFMail --

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] MANOVA with repeated measurements

2007-04-05 Thread Mark E. Olszewski
Hello,

I have a question regarding performing manova.  I have an experiment where I 
want to measure 10 output variables for 3 different measurement methods.  Since 
each of the methods requires some user interaction, I would also like to 
include repeated measures for each of the output variables to include 
intraobserver variability in the design.  

How can I perform such a repeated-measures manova using R?  I think I have 
found how to perform the non-repeated version of this experiment based on 
previous posts, but I am having trouble generalizing to the repeated-measures 
version (maybe I am just too tired today).

Thanks in advance,

Mark

[[alternative HTML version deleted]]

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


Re: [R] Indexing in anova summary output of the form: summary(aov(y ~ x1, Error = (x1/x2)))

2007-04-05 Thread Michael D. Rennie

Hi, there

Sorry- I excluded some example code in the haste of my original e-mail. 
Please find it included below. Note, however, that the elements in the 
list in the summary output appear to be the anova tables themselves- 
what I need to do is get inside the anova tables (execute the code below 
to see what I mean...)


Thanks again,

Mike

#example code to illustrate my inability to get at a mean square in 
anova output from

# models of the form summary(aov(y ~ x1 + Error(x1/x2)))

y<-rnorm(30,10)
x1<-rep(1:2, each=15)
x2<-rep(1:3, each=1, times=10)

dat<-data.frame(y, x1, x2)
dat

ex.aov<-aov(y ~ x1 + Error(x1/x2))

ex.sum<-summary(ex.aov)
ex.sum

#gets you the first list in the element, which is anova output for x1 
caluclated with nested factor x2 in x1


ex.sum[1]

ex.sum[1]$Error #this is equivalent to...

ex.sum[[1]]

# since ex.sum is a list composed of anova tables, apparently the 
element in the list
#is the anova table itself. The question is, how do you get at the 
elements in each table

#(i.e., Mean Square?)


Prof Brian Ripley wrote:

The output is of class "summary.anovalist" so (hint, hint) it is a list.

Try [[ ]] to get list elements.

Without a reproducible example (see the footer and the posting guide) 
it is not possible to show you working code.



On Thu, 5 Apr 2007, Michael D. Rennie wrote:



Hi, there

I'm trying to get the value of the Mean Square from the ANOVA model 
summary that comes from specifying the error term, and am wondering 
if one can actually do this ( I know it's possible when using 
anova(lm) objects and the like, but I'm having a tough time with it 
under this framework). There does appear to be some indexing in the 
output of this type, but perhaps not enough to obtain single values? 
Here's what I've been able to do so far with some example code:



density.aov<-aov(density ~ substrate + Error(substrate/tile))

anov1<-(summary(density.aov))
print(anov1)


Error: substrate
Df Sum Sq Mean Sq
substrate  2 1282.4   641.2

Error: substrate:tile
Df  Sum Sq Mean Sq F value Pr(>F)
Residuals 27 225.700   8.359 Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 60 640.00   10.67

anov1[1]

$`Error: substrate`
Df Sum Sq Mean Sq
substrate  2 1282.4   641.2


anov1[2]

$`Error: substrate:tile`
Df  Sum Sq Mean Sq F value Pr(>F)
Residuals 27 225.700   8.359 And, I can get


anov1[1]$Error

Df Sum Sq Mean Sq
substrate  2 1282.4   641.2

a<-anov1[1]$Error

and then tried to get at elements in that, trying things like

a$Mean

or

a[,2]

but all return

Error:  incorrect number of dimensions

probably because


length(a)

[1] 1

Does anyone have any reccomendations on how to go any further here?

Cheers,

Mike






--
Michael D. Rennie
Ph.D. Candidate
University of Toronto at Mississauga
3359 Missisagua Rd. N. 
Mississauga, ON L5L 1C6

Ph: 905-828-5452 Fax: 905-828-3792
www.utm.utoronto.ca/~w3rennie

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


[R] creating a data frame from a list

2007-04-05 Thread Dimitri Szerman
Dear all,

A few months ago, I asked for your help on the following problem:

I have a list with three (named) numeric vectors:

> lst = list(a=c(A=1,B=8) , b=c(A=2,B=3,C=0), c=c(B=2,D=0) )
> lst
$a
A B
1 8

$b
A B C
2 3 0

$c
B D
2 0

Now, I'd love to use this list to create the following data frame:

> dtf = data.frame(a=c(A=1,B=8,C=NA,D=NA),
+  b=c(A=2,B=3,C=0,D=NA),
+  c=c(A=NA,B=2,C=NA,D=0) )

> dtf
   ab c
A   1   2  NA
B   8   3 2
C NA   0  NA
D NA NA0

That is, I wish to "merge" the three vectors in the list into a data frame
by their "(row)"names.

And I got the following answer:

library(zoo)
z <- do.call(merge, lapply(lst, function(x) zoo(x, names(x
rownames(z) <- time(z)
coredata(z)

However, it does not seem to be working. Here's what I get when I try it:

> lst = list(a=c(A=1,B=8) , b=c(A=2,B=3,C=0), c=c(B=2,D=0) )
> library(zoo)
> z <- do.call(merge, lapply(lst, function(x) zoo(x, names(x
Error in if (freq > 1 && identical(all.equal(freq, round(freq)),
TRUE)) freq <- round(freq) :
missing value where TRUE/FALSE needed
In addition: Warning message:
NAs introduced by coercion

and z was not created.

Any ideas on what is going on here?
Thank you,
Dimitri

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


Re: [R] Indexing in anova summary output of the form: summary(aov(y ~ x1, Error = (x1/x2)))

2007-04-05 Thread Prof Brian Ripley
The output is of class "summary.anovalist" so (hint, hint) it is a list.

Try [[ ]] to get list elements.

Without a reproducible example (see the footer and the posting guide) it 
is not possible to show you working code.


On Thu, 5 Apr 2007, Michael D. Rennie wrote:

>
> Hi, there
>
> I'm trying to get the value of the Mean Square from the ANOVA model summary 
> that comes from specifying the error term, and am wondering if one can 
> actually do this ( I know it's possible when using anova(lm) objects and the 
> like, but I'm having a tough time with it under this framework). There does 
> appear to be some indexing in the output of this type, but perhaps not enough 
> to obtain single values? Here's what I've been able to do so far with some 
> example code:
>
>> density.aov<-aov(density ~ substrate + Error(substrate/tile))
>>
>> anov1<-(summary(density.aov))
>> print(anov1)
>
> Error: substrate
> Df Sum Sq Mean Sq
> substrate  2 1282.4   641.2
>
> Error: substrate:tile
> Df  Sum Sq Mean Sq F value Pr(>F)
> Residuals 27 225.700   8.359 
> Error: Within
> Df Sum Sq Mean Sq F value Pr(>F)
> Residuals 60 640.00   10.67 
>> anov1[1]
> $`Error: substrate`
> Df Sum Sq Mean Sq
> substrate  2 1282.4   641.2
>
>> anov1[2]
> $`Error: substrate:tile`
> Df  Sum Sq Mean Sq F value Pr(>F)
> Residuals 27 225.700   8.359 
> And, I can get
>
>> anov1[1]$Error
> Df Sum Sq Mean Sq
> substrate  2 1282.4   641.2
>
> a<-anov1[1]$Error
>
> and then tried to get at elements in that, trying things like
>
> a$Mean
>
> or
>
> a[,2]
>
> but all return
>
> Error:  incorrect number of dimensions
>
> probably because
>
>> length(a)
> [1] 1
>
> Does anyone have any reccomendations on how to go any further here?
>
> Cheers,
>
> Mike
>
>

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

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Indexing in anova summary output of the form: summary(aov(y ~ x1, Error = (x1/x2)))

2007-04-05 Thread Michael D. Rennie


Hi, there

I'm trying to get the value of the Mean Square from the ANOVA model 
summary that comes from specifying the error term, and am wondering if 
one can actually do this ( I know it's possible when using anova(lm) 
objects and the like, but I'm having a tough time with it under this 
framework). There does appear to be some indexing in the output of this 
type, but perhaps not enough to obtain single values? Here's what I've 
been able to do so far with some example code:


> density.aov<-aov(density ~ substrate + Error(substrate/tile))
>
> anov1<-(summary(density.aov))
> print(anov1)

Error: substrate
 Df Sum Sq Mean Sq
substrate  2 1282.4   641.2

Error: substrate:tile
 Df  Sum Sq Mean Sq F value Pr(>F)
Residuals 27 225.700   8.359  


Error: Within
 Df Sum Sq Mean Sq F value Pr(>F)
Residuals 60 640.00   10.67


> anov1[1]
$`Error: substrate`
 Df Sum Sq Mean Sq
substrate  2 1282.4   641.2

> anov1[2]
$`Error: substrate:tile`
 Df  Sum Sq Mean Sq F value Pr(>F)
Residuals 27 225.700   8.359   


And, I can get

> anov1[1]$Error
 Df Sum Sq Mean Sq
substrate  2 1282.4   641.2

a<-anov1[1]$Error

and then tried to get at elements in that, trying things like

a$Mean

or

a[,2]

but all return

Error:  incorrect number of dimensions

probably because

> length(a)
[1] 1

Does anyone have any reccomendations on how to go any further here?

Cheers,

Mike

--
Michael D. Rennie
Ph.D. Candidate
University of Toronto at Mississauga
3359 Missisagua Rd. N. 
Mississauga, ON L5L 1C6

Ph: 905-828-5452 Fax: 905-828-3792
www.utm.utoronto.ca/~w3rennie

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


Re: [R] about systemfit

2007-04-05 Thread John Fox
Dear Martin,

Note that the F-test provided by linear.hypothesis() in the car package
appears to agree with the Wald test provided by both linear.hypothesis() and
waldtest.systemfit(), while ftest.systemfit() gives a much smaller p-value
and an F that's even larger than the Wald chisquare. This suggests to me
that the first place to look for a problem is in ftest.systemfit().

Regards,
 John


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Martin Ivanov
> Sent: Thursday, April 05, 2007 1:02 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] about systemfit
> 
> Thank you very much for your responsiveness. Here are the 
> tests that show the same results, as they must:
> 
> linear.hypothesis(model=adfResulm,hypothesis.matrix=Rrestr10,t
> est="Chisq"):
>  Res.Df RSS  Df Sum of Sq  Chisq Pr(>Chisq)
> 1127  7.3782
> 2137  7.6848 -10   -0.3066 5.2769  0.872
> 
> waldtest.systemfit(object=adfResu,R.restr=Rrestr10):
> 
> Wald-test for linear parameter restrictions in equation systems
> Wald-statistic: 5.277
> degrees of freedom: 10
> p-value: 0.8719 
> 
> So the Chisq test with linear.hypothesis from car and the 
> waldtest.systemfit give the same output. But the  F test with 
> linear.hypothesis from car and ftest.systemfit give 
> absolutely different results, as I demonstrated in my first 
> post. I have no idea why.
> 
> Regards,
> Martin
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] changing existing graphs optimally

2007-04-05 Thread hadley wickham
On 4/5/07, Greg Snow <[EMAIL PROTECTED]> wrote:
> Using traditional and lattice(trellis) graphics, the usual approach is
> to have your plotting commands in a script file (under windows you can
> use the one with the GUI, in linux/unix you can have a text editor open
> with the script).  Then either run the commands by copy/paste or using
> the source function.  Then when you see something tha you would like to
> change, just do the edits and rerun the code.
>
> The ggplot package has some functionality for first specifying the data
> that you want plotted, then how you want it plotted, then the command to
> actually create the plot.  You can then modify how you want it plotted
> and replot again.

Yes, the current version of ggplot can this, although it's not very
well exposed to the user.  The current development version uses the
idea of plot modification extensively, and it's also very easy to take
the same plot specification and use it with a different data set.

Hadley

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


Re: [R] Extent of time zone vulerability for POSIX date and time classes

2007-04-05 Thread Tim Bergsma
Gabor,

The out.fmt approach seems optimal. Thank you!

Tim.

Gabor Grothendieck wrote:
> There are several ways:
> 
> 1. the default number of year digits is set by the chron.year.abb option.
> The R News article mentions this in the Avoiding Errors section but
> does suggest you not set it.
> 
> options(chron.year.abb = FALSE)
> chron(1)
> 
> 2. Alternately, define:
> 
> out.fmt <- function(x) with( month.day.year(x),
> sprintf("%02.f/%02.f/%04.f", month, day, year))
> 
> # Now any of these will work:
> x <- chron(1:5)
> out.fmt(x)
> 
> # or
> 
> x <- chron(1:5)
> chron(x, out.format = out.fmt)
> 
> # or
> 
> x <- chron(1:5, out.format = out.fmt)
> x
> 
> 
> On 4/5/07, Tim Bergsma <[EMAIL PROTECTED]> wrote:
>> Gabor,
>>
>> thanks for the feedback. I like the idea of coercing the system time
>> zone, and sticking with strptime/strftime.  The balance would probably
>> tip in favor of chron, however, if I could get the format correct.
>> Apparently the default is two-digit year:
>>
>> library(chron)
>> chron(1)
>> [1] 01/02/70
>>
>> chron(1,format="m/d/y")
>> [1] 01/02/70
>>
>> But I need four digit year, so I try:
>>
>> chron(1,format="m/d/")
>> [1] Jan/02/1970
>>
>> Now, month has switched to character!  I don't know of a format
>> convention that gets it back to numeric (although conventions are
>> documented for forcing to character).  Comment?
>>
>> Regards,
>>
>> Tim.
>>
>>
>> Gabor Grothendieck wrote:
>> > If you use
>> >
>> > Sys.putenv(TZ = "GMT")
>> >
>> > at the beginning of your session then local time zone and GMT time
>> > zone will be the same so you should not have a problem.  This was
>> > not possible, at least on Windows, at the time the R News article
>> > was written.
>> >
>> >
>> >
>> >
>> >
>> > On 4/5/07, Tim Bergsma <[EMAIL PROTECTED]> wrote:
>> >> Hi.
>> >>
>> >> I frequently convert date and time data to and from character
>> >> representations.  I'm frustrated with chron, because 'seconds' are
>> >> required to create a time object (my input data never has seconds).
>> >
>> > You could use paste:
>> >
>> >  times(paste("12:30", 0, sep = ":"))
>> >
>> > and make it into a function if you use it a lot.
>> >
>> >> More importantly, I cannot make chron print the format 12/30/2006 
>> (which
>> >> my output data requires).
>> >
>> > That is the default output format so you don't have to specify 
>> anything.
>> > Its
>> > only with POSIX that its not the default.  For example:
>> >
>> >> library(chron)
>> >> x <- chron("12/30/2006")
>> >> x
>> > [1] 12/30/06
>> >
>> >>
>> >> I really like the format flexibility of strftime() and strptime(), but
>> >> of course am paranoid about timezone issues.  After reading the 
>> standard
>> >> reference several times
>> >> (http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf), I am 
>> tempted to
>> >> conclude that if I never specify timezones, and never use Sys.time(),
>> >> the vulnerabilities do not pertain.
>> >
>> > That won't protect you but this would let you use POSIX safely:
>> >
>> > http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg83508.html
>> >
>> >>
>> >> To the point: if I'm merely converting to and from character data that
>> >> does not represent time zones, is there still a time zone 
>> vulnerability
>> >> with strftime() and strptime()?
>> >>
>> >> Thanks in advance,
>> >>
>> >> Tim Bergsma, PhD
>> >> Metrum Research Group, LLC
>> >>
>> >>
>> >> #example
>> >> strftime(
>> >>   strptime(
>> >> "30-Dec-06 23:30",
>> >> format="%d-%b-%y %H:%M"
>> >>   ),
>> >>   format="%m/%d/%Y %H:%M"
>> >> )
>> >> [1] "12/30/2006 23:30"
>> >>
>> >> __
>> >> R-help@stat.math.ethz.ch mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] package for Matlab

2007-04-05 Thread Henrik Bengtsson
On 4/5/07, Tobias Verbeke <[EMAIL PROTECTED]> wrote:
> Schmitt, Corinna wrote:
> > Hallo,
> >
> > does a package for Matlab exist in R?
> >
> To read and write MAT files, there is the R.matlab package:
>
> http://cran.r-project.org/src/contrib/Descriptions/R.matlab.html
>
> This package also enables bidirectional communication
> between R and Matlab.

A clarification:  The R.matlab package is *one-directional* in the
sense that you can call Matlab code from R (and get results back).
You cannot call R code from Matlab using R.matlab.

Cheers

Henrik


>
> An alternative package with similar functionality (but not on CRAN
> and according to its home page not yet functional on platforms other
> than UNIX) is RMatlab
>
> http://www.omegahat.org/RMatlab/
>
> To ease translation of Matlab code, there is the matlab package:
>
> http://cran.r-project.org/src/contrib/Descriptions/matlab.html
>
> HTH,
> Tobias
> > If yes, where can I find it and how can I install it under R?
> >
> > Thanks, Corinna
> >
> > __
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
>
> --
>
> Tobias Verbeke - Consultant
> Business & Decision Benelux
> Rue de la révolution 8
> 1000 Brussels - BELGIUM
>
> +32 499 36 33 15
> [EMAIL PROTECTED]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Extent of time zone vulerability for POSIX date and time classes

2007-04-05 Thread Gabor Grothendieck
There are several ways:

1. the default number of year digits is set by the chron.year.abb option.
The R News article mentions this in the Avoiding Errors section but
does suggest you not set it.

options(chron.year.abb = FALSE)
chron(1)

2. Alternately, define:

out.fmt <- function(x) with( month.day.year(x),
sprintf("%02.f/%02.f/%04.f", month, day, year))

# Now any of these will work:
x <- chron(1:5)
out.fmt(x)

# or

x <- chron(1:5)
chron(x, out.format = out.fmt)

# or

x <- chron(1:5, out.format = out.fmt)
x


On 4/5/07, Tim Bergsma <[EMAIL PROTECTED]> wrote:
> Gabor,
>
> thanks for the feedback. I like the idea of coercing the system time
> zone, and sticking with strptime/strftime.  The balance would probably
> tip in favor of chron, however, if I could get the format correct.
> Apparently the default is two-digit year:
>
> library(chron)
> chron(1)
> [1] 01/02/70
>
> chron(1,format="m/d/y")
> [1] 01/02/70
>
> But I need four digit year, so I try:
>
> chron(1,format="m/d/")
> [1] Jan/02/1970
>
> Now, month has switched to character!  I don't know of a format
> convention that gets it back to numeric (although conventions are
> documented for forcing to character).  Comment?
>
> Regards,
>
> Tim.
>
>
> Gabor Grothendieck wrote:
> > If you use
> >
> > Sys.putenv(TZ = "GMT")
> >
> > at the beginning of your session then local time zone and GMT time
> > zone will be the same so you should not have a problem.  This was
> > not possible, at least on Windows, at the time the R News article
> > was written.
> >
> >
> >
> >
> >
> > On 4/5/07, Tim Bergsma <[EMAIL PROTECTED]> wrote:
> >> Hi.
> >>
> >> I frequently convert date and time data to and from character
> >> representations.  I'm frustrated with chron, because 'seconds' are
> >> required to create a time object (my input data never has seconds).
> >
> > You could use paste:
> >
> >  times(paste("12:30", 0, sep = ":"))
> >
> > and make it into a function if you use it a lot.
> >
> >> More importantly, I cannot make chron print the format 12/30/2006 (which
> >> my output data requires).
> >
> > That is the default output format so you don't have to specify anything.
> > Its
> > only with POSIX that its not the default.  For example:
> >
> >> library(chron)
> >> x <- chron("12/30/2006")
> >> x
> > [1] 12/30/06
> >
> >>
> >> I really like the format flexibility of strftime() and strptime(), but
> >> of course am paranoid about timezone issues.  After reading the standard
> >> reference several times
> >> (http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf), I am tempted to
> >> conclude that if I never specify timezones, and never use Sys.time(),
> >> the vulnerabilities do not pertain.
> >
> > That won't protect you but this would let you use POSIX safely:
> >
> > http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg83508.html
> >
> >>
> >> To the point: if I'm merely converting to and from character data that
> >> does not represent time zones, is there still a time zone vulnerability
> >> with strftime() and strptime()?
> >>
> >> Thanks in advance,
> >>
> >> Tim Bergsma, PhD
> >> Metrum Research Group, LLC
> >>
> >>
> >> #example
> >> strftime(
> >>   strptime(
> >> "30-Dec-06 23:30",
> >> format="%d-%b-%y %H:%M"
> >>   ),
> >>   format="%m/%d/%Y %H:%M"
> >> )
> >> [1] "12/30/2006 23:30"
> >>
> >> __
> >> R-help@stat.math.ethz.ch mailing list
> >> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting multiple curves with lattice graphs

2007-04-05 Thread Karen Chiswell
Thanks for two nice & simple solutions.

I did not know about recordPlot() or replayPlot(). 
Unfortunately these do not give me quite what I want
because I need (for use in another function) an object
of class "lattice".  I should have mentioned this part
earlier!

However, your first solution using xyplot() works and
I think it is a bit better than what I'm currently
using.

Thanks!
Karen

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

> Try this:
> 
> x <- 1:100
> xyplot(dnorm(x, 50, 10) + dnorm(x, 55, 12) +
> dnorm(x, 60, 15) ~ x, type = "l")
> 
> By the way, you can save classic graphics, at least
> on windows, like this:
> 
> ### your code
> parms <-
>
data.frame(ID=c(1,2,3),mu=c(50,55,60),sigma=c(10,12,15))
>
curve(dnorm(x,mean=parms$mu[1],sd=parms$sigma[1]),from=0,
> to=150, ylab="density", col="red")
>
curve(dnorm(x,mean=parms$mu[2],sd=parms$sigma[2]),from=0,
> to=150, ylab="density", col="blue", add=TRUE)
>
curve(dnorm(x,mean=parms$mu[3],sd=parms$sigma[3]),from=0,
> to=150, ylab="density", col="forestgreen", add=TRUE)
> ###
> 
> myplot <- recordPlot()
> title("Title A")
> 
> # replay the plot with Title B
> replayPlot(myplot)
> title("Title B")
> 
> 
> 
> On 4/5/07, Karen Chiswell <[EMAIL PROTECTED]>
> wrote:
> > Hi List,
> >
> > I would like to plot multiple curves (parametric
> > density curves) in one plot.
> >
> > For example:
> > # parameters for three normal density curves
> > parms =
> >
>
data.frame(ID=c(1,2,3),mu=c(50,55,60),sigma=c(10,12,15))
> >
> > # I can easily draw three normal density curves
> using
> > curve():
> >
>
curve(dnorm(x,mean=parms$mu[1],sd=parms$sigma[1]),from=0,
> > to=150, ylab="density", col="red")
> >
>
curve(dnorm(x,mean=parms$mu[2],sd=parms$sigma[2]),from=0,
> > to=150, ylab="density", col="blue", add=TRUE)
> >
>
curve(dnorm(x,mean=parms$mu[3],sd=parms$sigma[3]),from=0,
> > to=150, ylab="density", col="forestgreen",
> add=TRUE)
> >
> > but I would like to use lattice graphics (even
> though
> > I only want one panel) because I want to save the
> > resulting plot in an object.
> >
> > I could create a dataframe that contains the
> values I
> > want to plot, and then plot using xyplot().  For
> > example,
> >
> > x = seq(from=0, to=150, length=100)
> > plot.df = data.frame(ID=rep(parms$ID,each=100),
> >
>
x=rep(x,3),mu=rep(parms$mu,each=100),sigma=rep(parms$sigma,each=100))
> > plot.df$d =
> > dnorm(plot.df$x,mean=plot.df$mu,sd=plot.df$sigma)
> >
> > require(lattice)
> > p=xyplot(d~x, data=plot.df, groups=ID, type="l")
> >
> > However...  is there a more elegant/efficient way
> to
> > do this?  I have tried using the panel.curve panel
> > function (with xyplot() and histogram()), but I am
> not
> > very experienced with using panel functions (or R
> > actually), and I haven't had any success with this
> > yet.
> >
> > Many thanks for any suggestions,
> > Karen
> >
> > ---
> > Karen Chiswell
> > Department of Statistics
> > North Carolina State University
> > ---
> >
> >
> >
> >
> >
>

> > It's here! Your new message!
> > Get new email alerts with the free Yahoo! Toolbar.
> >
> > __
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained,
> reproducible code.
> >
> 



 

The fish are biting.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] about systemfit

2007-04-05 Thread Martin Ivanov
Thank you very much for your responsiveness. Here are the tests that show the 
same results, as they must:

linear.hypothesis(model=adfResulm,hypothesis.matrix=Rrestr10,test="Chisq"):
 Res.Df RSS  Df Sum of Sq  Chisq Pr(>Chisq)
1127  7.3782
2137  7.6848 -10   -0.3066 5.2769  0.872

waldtest.systemfit(object=adfResu,R.restr=Rrestr10):

Wald-test for linear parameter restrictions in equation systems
Wald-statistic: 5.277 
degrees of freedom: 10 
p-value: 0.8719 

So the Chisq test with linear.hypothesis from car and the waldtest.systemfit 
give the same output. But the  F test with linear.hypothesis from car and 
ftest.systemfit give absolutely different results, as I demonstrated in my 
first post. I have no idea why.

Regards,
Martin

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Reasons to Use R

2007-04-05 Thread Joel J. Adamson
Lorenzo Isella writes:

 > (4)finally, a list of the advantages for using R over commercial
 > statistical packages.

Here's my entry on the list, as this was a topic of conversation over
lunch: it's better than the proprietary statistical software I use
most of the time.  By better I mean that the language is consistent,
the features are all well-documented and none of it appears to have
been rushed out onto the market.  The proprietary software that I use
most of the time at work seems hurriedly cobbled together and R (nor LaTeX nor
Emacs nor Linux nor...) doesn't give me that feeling.

 > The money-saving in itself is not a reason good
 > enough

Interesting ;)  I know what you mean -- it may even make them
suspicious.

Joel
-- 
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA  02114
(617) 643-1432
(303) 880-3109





The information transmitted in this electronic communication is intended only 
for the person or entity to whom it is addressed and may contain confidential 
and/or privileged material. Any review, retransmission, dissemination or other 
use of or taking of any action in reliance upon this information by persons or 
entities other than the intended recipient is prohibited. If you received this 
information in error, please contact the Compliance HelpLine at 800-856-1983 
and properly dispose of this information.

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


Re: [R] about systemfit

2007-04-05 Thread John Fox
Dear Martin,

I'll address only part of your question, which is how to get the code for
linear.hypothesis() in the car package: linear.hypothesis() is an S3 generic
function with several methods:

> library(car)
> methods("linear.hypothesis")
[1] linear.hypothesis.default* linear.hypothesis.glm*
[3] linear.hypothesis.lm*  linear.hypothesis.mlm*

   Non-visible functions are asterisked

So the function has methods for glm, lm, and mlm objects, along with a
default method, which, as explained in ?linear.hypothesis, should work with
models for which coef() and vcov() methods exist.

To see linear.hypothesis.default(), which isn't exported from the car
namespace, you can, e.g., type

 car:::linear.hypothesis.default

I'm not sure why you get different results for the F-test but similar
results for the Wald test. Which F-test seems to square with the Wald test
(you don't show the Wald tests)?

I hope this helps,
 John


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Martin Ivanov
> Sent: Thursday, April 05, 2007 11:28 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] about systemfit
> 
> Hello. I am still a newbie in R. Excuse me if I am asking 
> something obvious. My efforts to get an answer through 
> browsing the mailing archives failed. I want to perform an 
> augmented Dickey-Fuller test and to obtain AIC and BIC and to 
> be able to impose some linear restrictions on the ADF 
> regression so as to decide the correct order of 
> autoregression. However I could find no obvious way to impose 
> linear restrictions or to obtain AIC from the the result of 
> ADF.test from uroot. That is why I turned to systemfit. I ran 
> the ADF regression with systemfit and obtained the same 
> coefficient estimates as through ADF.test (as it had to be). 
> Unfortunately I could not find how to extract AIC from the 
> result of systemfit, so I evaluated the ADF regression by lm. 
> So far so good. However the results of ftest.systemfit and 
> linear.hypothesis from the "car" package are very different, 
> while the results from waldtest.systemfit and 
> linear.hypothesis coincide. I have no explanation for this 
> issue a  nd I could not see the code of linear.hypothesis. 
> When I type "linear.hypothesis" I get:
> function (model, ...)
> UseMethod("linear.hypothesis")
> 
> 
> but when I type "ftest.systemfit", I do see the actual code. Why? 
> Anyway, here are the results in more detail:
> 
> eqns<-list(eq = y ~ trend+ x1 + x[,1] + x[,2] + x[,3] + x[,4] 
> + x[,5] + x[,6] + x[,7] + x[,8] + x[,9] + x[,10] + x[,11] + 
> x[,12] + x[,13]
> 
> Rrestr10<-matrix(0,10,16);Rrestr10[1,16]=Rrestr10[2,15]=Rrestr
10[3,14]=Rrestr10[4,13]=Rrestr10[5,12]=Rrestr10[6,11]=Rrestr10[7,10]=Rrestr1
0[8,9]=Rrestr10[9,8]=Rrestr10[10,7]=1
> 
> adfResc<-systemfit(method="OLS",eqns=eqns,R.restr=Rrestr10)
> 
> adfResu<-systemfit(method="OLS",eqns=eqns)
> 
> adfResulm<-lm(formula=eqns$eq)
> 
> ftest.systemfit( object=adfResu, R.restr=Rrestr10) :
> 
> F-test for linear parameter restrictions in equation systems
> F-statistic: 9.083
> degrees of freedom of the numerator: 10 degrees of freedom of 
> the denominator: 127
> p-value: 3.449e-11 
> 
> linear.hypothesis(model=adfResulm,hypothesis.matrix=Rrestr10,t
> est="F"):
> 
>  Res.Df RSS  Df Sum of Sq  F Pr(>F)
> 1127  7.3782
> 2137  7.6848 -10   -0.3066 0.5277  0.868
> 
> As I said, the results of
> the chisquare test with linear.hypothesis and the 
> waldtest.systemfit coincide.
> I have one more problem. This is the output of lrtest.systemfit:
> lrtest.systemfit(resultc=adfResc,resultu=adfResu)
> 
> Likelihood-Ratio-test for parameter restrictions in equation systems
> LR-statistic:  
> degrees of freedom: 
> p-value:  
> 
> Why do I get empty values?
> In summary, I need to understand why the two ftests give 
> different results; why lrtest.systemfit gives empty output; 
> is there some way to extract AIC and BIC from object of class 
> systemfit or from the result of ADF.test.
> 
> Excuse me if I am asking something too obvious, but I am 
> really at a loss.
> 
> Any suggestions on any of the above questions will be welcomed.
> 
> Regards,
> Martin
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducibl

Re: [R] Extent of time zone vulerability for POSIX date and time classes

2007-04-05 Thread Tim Bergsma
Gabor,

thanks for the feedback. I like the idea of coercing the system time 
zone, and sticking with strptime/strftime.  The balance would probably 
tip in favor of chron, however, if I could get the format correct. 
Apparently the default is two-digit year:

library(chron)
chron(1)
[1] 01/02/70

chron(1,format="m/d/y")
[1] 01/02/70

But I need four digit year, so I try:

chron(1,format="m/d/")
[1] Jan/02/1970

Now, month has switched to character!  I don't know of a format 
convention that gets it back to numeric (although conventions are 
documented for forcing to character).  Comment?

Regards,

Tim.


Gabor Grothendieck wrote:
> If you use
> 
> Sys.putenv(TZ = "GMT")
> 
> at the beginning of your session then local time zone and GMT time
> zone will be the same so you should not have a problem.  This was
> not possible, at least on Windows, at the time the R News article
> was written.
> 
> 
> 
> 
> 
> On 4/5/07, Tim Bergsma <[EMAIL PROTECTED]> wrote:
>> Hi.
>>
>> I frequently convert date and time data to and from character
>> representations.  I'm frustrated with chron, because 'seconds' are
>> required to create a time object (my input data never has seconds).
> 
> You could use paste:
> 
>  times(paste("12:30", 0, sep = ":"))
> 
> and make it into a function if you use it a lot.
> 
>> More importantly, I cannot make chron print the format 12/30/2006 (which
>> my output data requires).
> 
> That is the default output format so you don't have to specify anything. 
> Its
> only with POSIX that its not the default.  For example:
> 
>> library(chron)
>> x <- chron("12/30/2006")
>> x
> [1] 12/30/06
> 
>>
>> I really like the format flexibility of strftime() and strptime(), but
>> of course am paranoid about timezone issues.  After reading the standard
>> reference several times
>> (http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf), I am tempted to
>> conclude that if I never specify timezones, and never use Sys.time(),
>> the vulnerabilities do not pertain.
> 
> That won't protect you but this would let you use POSIX safely:
> 
> http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg83508.html
> 
>>
>> To the point: if I'm merely converting to and from character data that
>> does not represent time zones, is there still a time zone vulnerability
>> with strftime() and strptime()?
>>
>> Thanks in advance,
>>
>> Tim Bergsma, PhD
>> Metrum Research Group, LLC
>>
>>
>> #example
>> strftime(
>>   strptime(
>> "30-Dec-06 23:30",
>> format="%d-%b-%y %H:%M"
>>   ),
>>   format="%m/%d/%Y %H:%M"
>> )
>> [1] "12/30/2006 23:30"
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transform distance constraints into a 2D-map

2007-04-05 Thread Emmanuel Levy
Dear All,

Thank you for your replies. That will definitly get me started.

Ted: I said optimize because I suppose that an exact solution does
not necessarily exists sometimes.

Best,

Emmanuel



On 4/5/07, Ted Harding <[EMAIL PROTECTED]> wrote:
> On 05-Apr-07 13:05:29, Emmanuel Levy wrote:
> > Dear all,
> >
> > Could you please point me out to a function or set of functions
> > that would allow me to optimize positions on the 2D map of points
> > for which I are distance contrainted?
> >
> > for example, if I have:
> > a   b   c
> > a 0.0 0.5 0.7
> > b 0.5 0.0 0.3
> > c 0.7 0.3 0.0
> >
> > I would like to obtain (x,y) coordinates to plot A,B,C so that the
> > distance constraints are satisfied. i.e. a is 0.5 far from b, and o.7
> > far from c. etc ...
> >
> > Many thanks for your help,
> >
> > Best,
> >
> > Emmanuel
>
> Probably any of the multidimensional scaling functions variously
> available would do (it is not clear what you mean by "optimize",
> though). In your example above, an exact solution exists.
>
> For example
>
> library(MASS)
> D<-matrix(c(0.0, 0.5, 0.7, 0.5, 0.0, 0.3, 0.7, 0.3, 0.0),nrow=3)
> rownames(D)<-c("a","b","c")
> colnames(D)<-c("a","b","c")
>
> P<-isoMDS(D)$points
> plot(P[,1],P[,2],pch="+",col="blue")
>
> P
> ##  [,1][,2]
> ## a  0.39114338  0.03809598
> ## b -0.08358748 -0.11884547
> ## c -0.30755590  0.08074949
>
> dist(P)
> ##  a   b
> ## b  0.5
> ## c  0.7 0.3
>
> The last result shows that the distances betweem the three points
> in the 3 rows of P are as desired: a<->b=0.5, a<->c=0.7, b<->c=0.3
>
> Hoping this helps!
> Ted.
>
> 
> E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
> Fax-to-email: +44 (0)870 094 0861
> Date: 05-Apr-07   Time: 16:29:49
> -- XFMail --
>

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


Re: [R] Reasons to Use R

2007-04-05 Thread Schmitt, Corinna
Dear Mr. Isella,

I just started my PhD Thesis. I need to work with R. Good sources are 
Bioconductor (www.bioconductor.org). It is a DB based on R-programming.
Another institute which has good experiences with R is the HKI in Jena, 
Germany. Perhaps you can contact Mrs. Radke to get more information or speakers 
for your workshop. Both parties are mainly for bioinformatics methods but 
perhaps can help you.

A good reason to use R is that computations are much quicker and you can 
import/export from many other programs or languages files.

Happy Easter,
C.Schmitt

**
Corinna Schmitt, Dipl.Inf.(Bioinformatik)
Fraunhofer Institut für Grenzflächen- & Bioverfahrenstechnik
Nobelstrasse 12, B 3.24
70569 Stuttgart
Germany

phone: +49 711 9704044 
fax: +49 711 9704200
e-mail: [EMAIL PROTECTED]
http://www.igb.fraunhofer.de

 

-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Lorenzo Isella
Gesendet: Donnerstag, 5. April 2007 17:02
An: r-help@stat.math.ethz.ch
Betreff: [R] Reasons to Use R

Dear All,
The institute I work for is organizing an internal workshop for High
Performance Computing (HPC).
I am planning to attend it and talk a bit about fluid dynamics, but
there is also quite a lot of interest devoted to data post-processing
and management of huge data sets.
A lot of people are interested in image processing/pattern recognition
and statistic applied to geography/ecology, but I would like not to
post this on too many lists.
The final aim of the workshop is  understanding hardware requirements
and drafting a list of the equipment we would like to buy. I think
this could be the venue to talk about R as well.
Therefore, even if it is not exactly a typical mailing list question,
I would like to have suggestions about where to collect info about:
(1)Institutions (not only academia) using R
(2)Hardware requirements, possibly benchmarks
(3)R & clusters, R & multiple CPU machines, R performance on different hardware.
(4)finally, a list of the advantages for using R over commercial
statistical packages. The money-saving in itself is not a reason good
enough and some people are scared by the lack of professional support,
though this mailing list is simply wonderful.

Kind Regards

Lorenzo Isella

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] about systemfit

2007-04-05 Thread Martin Ivanov
Hello. I am still a newbie in R. Excuse me if I am asking something obvious. My 
efforts to get an answer through browsing the mailing archives failed. I want 
to perform an augmented Dickey-Fuller test and to obtain AIC and BIC and to be 
able to impose some linear restrictions on the ADF regression so as to decide 
the correct order of autoregression. However I could find no obvious way to 
impose linear restrictions or to obtain AIC from the the result of ADF.test 
from uroot. That is why I turned to systemfit. I ran the ADF regression with 
systemfit and obtained the same coefficient estimates as through ADF.test (as 
it had to be). Unfortunately I could not find how to extract AIC from the 
result of systemfit, so I evaluated the ADF regression by lm. So far so good. 
However the results of ftest.systemfit and linear.hypothesis from the "car" 
package are very different, while the results from waldtest.systemfit and 
linear.hypothesis coincide. I have no explanation for this issue a
 nd I could not see the code of linear.hypothesis. When I type 
"linear.hypothesis" I get:
function (model, ...) 
UseMethod("linear.hypothesis")


but when I type "ftest.systemfit", I do see the actual code. Why? 
Anyway, here are the results in more detail:

eqns<-list(eq = y ~ trend+ x1 + x[,1] + x[,2] + x[,3] + x[,4] + x[,5] + x[,6] + 
x[,7] + x[,8] + x[,9] + x[,10] + x[,11] + x[,12] + x[,13]

Rrestr10<-matrix(0,10,16);Rrestr10[1,16]=Rrestr10[2,15]=Rrestr10[3,14]=Rrestr10[4,13]=Rrestr10[5,12]=Rrestr10[6,11]=Rrestr10[7,10]=Rrestr10[8,9]=Rrestr10[9,8]=Rrestr10[10,7]=1

adfResc<-systemfit(method="OLS",eqns=eqns,R.restr=Rrestr10)

adfResu<-systemfit(method="OLS",eqns=eqns)

adfResulm<-lm(formula=eqns$eq)

ftest.systemfit( object=adfResu, R.restr=Rrestr10) :

F-test for linear parameter restrictions in equation systems
F-statistic: 9.083 
degrees of freedom of the numerator: 10 
degrees of freedom of the denominator: 127 
p-value: 3.449e-11 

linear.hypothesis(model=adfResulm,hypothesis.matrix=Rrestr10,test="F"):

 Res.Df RSS  Df Sum of Sq  F Pr(>F)
1127  7.3782
2137  7.6848 -10   -0.3066 0.5277  0.868

As I said, the results of 
the chisquare test with linear.hypothesis and the waldtest.systemfit coincide.
I have one more problem. This is the output of lrtest.systemfit:
lrtest.systemfit(resultc=adfResc,resultu=adfResu)

Likelihood-Ratio-test for parameter restrictions in equation systems
LR-statistic:  
degrees of freedom: 
p-value:  

Why do I get empty values?
In summary, I need to understand why the two ftests give different results; why 
lrtest.systemfit gives empty output; is there some way to extract AIC and BIC 
from object of class systemfit or from the result of ADF.test.

Excuse me if I am asking something too obvious, but I am really at a loss.

Any suggestions on any of the above questions will be welcomed.

Regards,
Martin

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


Re: [R] Running MCMCpack

2007-04-05 Thread Duncan Murdoch
On 4/5/2007 10:22 AM, Thomas Christin wrote:
> Hi there,
> 
>  
> 
> I am running MCMCpack (MCMCirt1d model) on some files (26 items x about 800
> – 1200 individuals).
> 
>  
> 
> I have a problem. When I am working on “big” files, the R program crashes.
> 
>  
> 
> More precisely I got the following Microsoft Warning: 
> 
>  
> 
> ***
> 
> Microsoft Visual C++ Runtime Library
> 
> Runtime Error!
> 
> Program: C:\Program Files\R\R-2.4.1\bin\Rgui.exe
> 
>  
> 
> This application has requested the Runtime to terminate it in an unusual
> way. Please contact the application’s support team for more information.

That message doesn't really give enough information to tell anything. 
Could you please do the following:

1.  Try the current alpha release of 2.5.0.  There have been patches to 
2.4.1 that may have fixed the bug, if it's an R bug and not an MCMCpack bug.

2.  If you still get the crashes, put together a minimal example to 
trigger them.  For example, generate random data of the right size and 
give a minimal set of commands that cause the crash.  If I can reproduce 
the crash I can probably locate the cause, but without that it's nearly 
hopeless.

Duncan Murdoch
> 
> ***
> 
> I click on OK and R close down.
> 
>  
> 
> Do you know how I could help my R program to run MCMC on my files?
> (memory.limit is already set to (4*1024-1))
> 
>  
> 
> Many thanks and best greetings from Zurich (sorry, my german is rather
> poor).
> 
> Thomas
> 
>  
> 
> Adresse / Address
> 
>  
> 
> Thomas Christin
> 
> Institut für Politikwissenschaft
> 
> Universität Zürich
> 
> Hirschengraben 56
> 
> 8001 Zürich
> 
> Tel. (+41) 44 634 51 56
> 
> Fax. (+41) 44 634 50 98
> 
> Email :   [EMAIL PROTECTED]
> 
> URL: http://www.ipz.unizh.ch/mitarbeiter/interne/christin.php
> 
>  
> 
> 
>   [[alternative HTML version deleted]]
> 
> 
> 
> 
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Transform distance constraints into a 2D-map

2007-04-05 Thread Ted Harding
On 05-Apr-07 13:05:29, Emmanuel Levy wrote:
> Dear all,
> 
> Could you please point me out to a function or set of functions
> that would allow me to optimize positions on the 2D map of points
> for which I are distance contrainted?
> 
> for example, if I have:
> a   b   c
> a 0.0 0.5 0.7
> b 0.5 0.0 0.3
> c 0.7 0.3 0.0
> 
> I would like to obtain (x,y) coordinates to plot A,B,C so that the
> distance constraints are satisfied. i.e. a is 0.5 far from b, and o.7
> far from c. etc ...
> 
> Many thanks for your help,
> 
> Best,
> 
> Emmanuel

Probably any of the multidimensional scaling functions variously
available would do (it is not clear what you mean by "optimize",
though). In your example above, an exact solution exists.

For example

library(MASS)
D<-matrix(c(0.0, 0.5, 0.7, 0.5, 0.0, 0.3, 0.7, 0.3, 0.0),nrow=3)
rownames(D)<-c("a","b","c")
colnames(D)<-c("a","b","c")

P<-isoMDS(D)$points
plot(P[,1],P[,2],pch="+",col="blue")

P
##  [,1][,2]
## a  0.39114338  0.03809598
## b -0.08358748 -0.11884547
## c -0.30755590  0.08074949

dist(P)
##  a   b
## b  0.5
## c  0.7 0.3

The last result shows that the distances betweem the three points
in the 3 rows of P are as desired: a<->b=0.5, a<->c=0.7, b<->c=0.3

Hoping this helps!
Ted.


E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 05-Apr-07   Time: 16:29:49
-- XFMail --

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


Re: [R] package for Matlab

2007-04-05 Thread Greg Snow
The first 2 links from doing:

> RSiteSearch('matlab')

Look like they may answer your question.  

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Schmitt, Corinna
> Sent: Thursday, April 05, 2007 7:25 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] package for Matlab
> 
> Hallo,
> 
> does a package for Matlab exist in R?
> If yes, where can I find it and how can I install it under R?
> 
> Thanks, Corinna
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] package for Matlab

2007-04-05 Thread Schmitt, Corinna
Dear R-experts,

Thanks for the help. I just istalled everything and will test it after
Easter.

Happy Easter,
Corinna

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


Re: [R] package for Matlab

2007-04-05 Thread Schmitt, Corinna


Dear Tobias,

the first packet was succesfull installed.

Please check the link for the last packet again. I get the following error 
message if I try to install it:

CC <- "http://odin.mdacc.tmc.edu/~roebuck/R";
> install.packages("rwt", dependencies = TRUE, CRAN = MDACC)
Error in install.packages("rwt", dependencies = TRUE, CRAN = MDACC) : 
unbenutzte(s) Argument(e) (CRAN = 
"http://odin.mdacc.tmc.edu/~roebuck/R";)

Thanks, Corinna


-Ursprüngliche Nachricht-
Von: Tobias Verbeke [mailto:[EMAIL PROTECTED] 
Gesendet: Donnerstag, 5. April 2007 16:01
An: Schmitt, Corinna
Cc: r-help@stat.math.ethz.ch
Betreff: Re: [R] package for Matlab

Schmitt, Corinna wrote:
> Hallo,
>
> does a package for Matlab exist in R?
>   
To read and write MAT files, there is the R.matlab package:

http://cran.r-project.org/src/contrib/Descriptions/R.matlab.html

This package also enables bidirectional communication
between R and Matlab.

An alternative package with similar functionality (but not on CRAN
and according to its home page not yet functional on platforms other
than UNIX) is RMatlab

http://www.omegahat.org/RMatlab/

To ease translation of Matlab code, there is the matlab package:

http://cran.r-project.org/src/contrib/Descriptions/matlab.html

HTH,
Tobias
> If yes, where can I find it and how can I install it under R?
>
> Thanks, Corinna
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>   

-- 

Tobias Verbeke - Consultant
Business & Decision Benelux
Rue de la révolution 8
1000 Brussels - BELGIUM

+32 499 36 33 15
[EMAIL PROTECTED]

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


Re: [R] Transform distance constraints into a 2D-map

2007-04-05 Thread Greg Snow
Look at the cmdscale function (there are variations in some packages,
but that should get you started).


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Emmanuel Levy
> Sent: Thursday, April 05, 2007 7:05 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Transform distance constraints into a 2D-map
> 
> Dear all,
> 
> Could you please point me out to a function or set of 
> functions that would allow me to optimize positions on the 2D 
> map of points for which I are distance contrainted?
> 
> for example, if I have:
> a   b   c
> a 0.0 0.5 0.7
> b 0.5 0.0 0.3
> c 0.7 0.3 0.0
> 
> I would like to obtain (x,y) coordinates to plot A,B,C so 
> that the distance constraints are satisfied. i.e. a is 0.5 
> far from b, and o.7 far from c. etc ...
> 
> Many thanks for your help,
> 
> Best,
> 
> Emmanuel
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] omega squared calculation

2007-04-05 Thread Hufkens Koen
Hi list,
 
Is there a function in R to calculate the omega squared (an estimate of the 
dependent variance accounted for by the independent variable in the population 
for a fixed effects model), or does anyone have some code to let me calculate 
this fairly easy out of aov() or anova() output?
 
Kind regards,
Koen

-- 

Checked by AVG Free Edition.

13:09
 

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Reasons to Use R

2007-04-05 Thread Lorenzo Isella
Dear All,
The institute I work for is organizing an internal workshop for High
Performance Computing (HPC).
I am planning to attend it and talk a bit about fluid dynamics, but
there is also quite a lot of interest devoted to data post-processing
and management of huge data sets.
A lot of people are interested in image processing/pattern recognition
and statistic applied to geography/ecology, but I would like not to
post this on too many lists.
The final aim of the workshop is  understanding hardware requirements
and drafting a list of the equipment we would like to buy. I think
this could be the venue to talk about R as well.
Therefore, even if it is not exactly a typical mailing list question,
I would like to have suggestions about where to collect info about:
(1)Institutions (not only academia) using R
(2)Hardware requirements, possibly benchmarks
(3)R & clusters, R & multiple CPU machines, R performance on different hardware.
(4)finally, a list of the advantages for using R over commercial
statistical packages. The money-saving in itself is not a reason good
enough and some people are scared by the lack of professional support,
though this mailing list is simply wonderful.

Kind Regards

Lorenzo Isella

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


Re: [R] Generate a serie of new vars that correlate with existingvar

2007-04-05 Thread Greg Snow
Oliver,

I have thought of adding something like this to a package, but here is my 
current thinking on the issue.

This question (or similar) has been asked a few times, so there is some demand 
for a general answer, I see three approaches:

1. Have an example of the necessary steps archived in a publicly available 
place.
2. Write a function and include it in a non-core package.
3. Add it to the core of R or a core package.

Number 1 is already in process as the e-mails will be part of the archive.  
Though someone is welcome to add it to the Wiki if they think that would be 
useful as well.

Your suggestion is number 3, but I would argue that 2 is better than 3 for the 
simple reason that anything added to the core is implied to be top quality and 
have pretty much any options that most people would think of.  Putting it in a 
non-core package makes it available, with less implications of quality.

The question then becomes, what options do we make available?  Do we have them 
specify the entire correlation structure? Or just assume the new variables will 
be independent of each other?  What should the function do if the set of 
correlations result in a matrix that is not positive definite?  What if the 
user wants to have 2 fixed variables?  And other questions.

My current thinking is that the process is simple enough that it is easier to 
do this by hand than to remember all the options to the function.  There are 
currently people who use bootstrap and permutation tests without loading in the 
packages that do these because it is quicker to write the code by hand than to 
remember the syntax of the functions.  I think this type of data generation 
falls under the same situation.  But if you, or someone else thinks that there 
is enough justification for a function to do this, and can specify what options 
it should have, I will be happy to add it to my TeachingDemos package (this 
seems an appropriate place, since one of the places that I want to generate 
data with a specific correlation structure is when creating an example for 
students).


Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Olivier ETERRADOSSI
> Sent: Thursday, April 05, 2007 3:09 AM
> To: r-help@stat.math.ethz.ch
> Subject: Re: [R] Generate a serie of new vars that correlate 
> with existingvar
> 
> Hello, list
> why not add the smart proposal by Greg Snow as a built-in 
> function in {stats}, just changing the "x234" and "newc" 
> lines to allow for more distributions to be generated ?
> Or do I miss an already existing function to do that ?
> Regards. Olivier
> 
> 
> # slight modification of the original code by Greg Snow 
> [mailto:[EMAIL PROTECTED]
> # on April 04, 2007 1:46 AM
> 
> # generates ndistr vectors of same mean and sd, with various 
> cor.coeffs # input :
> # x1 : a vector
> # ndistr : number of distributions
> # coefs : vector o ndistr correl. coeffs
> 
> CorelSets<-function(x1= rnorm(100, 15, 5),ndistr=3, 
> coefs=c(0.4,0.5,0.6)){
> 
> # x2, x3, and x4 in a matrix, these will be modified to meet 
> the criteria
> x234 <- scale(matrix( rnorm(ndistr*length(x1)), ncol=ndistr ))
> 
> # put all into 1 matrix for simplicity
> x1234 <- cbind(scale(x1),x234)
> 
> # find the current correlation matrix
> c1 <- var(x1234)
> 
> # cholesky decomposition to get independence
> chol1 <- solve(chol(c1))
> 
> newx <-  x1234 %*% chol1
> 
> # check that we have independence and x1 unchanged
> zapsmall(cor(newx))
> all.equal( x1234[,1], newx[,1] )
> 
> # create new correlation structure
> newc<-diag(ndistr+1)
> newc[1,-1]<- coefs
> newc[-1,1]<- coefs
> 
> chol2 <- chol(newc)
> 
> finalx <- newx %*% chol2 * sd(x1) + mean(x1)
> pairs(finalx)
> CorelSets<-finalx
> }
> > Message-ID: <[EMAIL PROTECTED]>
> > Content-Type: text/plain;   charset="us-ascii"
> >
> > Dear Greg,
> > Thanks million!
> > "As good as it gets"  :)
> > All the best
> > Nguyen
> >
> > -Original Message-
> > From: Greg Snow [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, April 04, 2007 1:46 AM
> > To: Nguyen Dinh Nguyen; r-help@stat.math.ethz.ch
> > Subject: RE: [R] Generate a serie of new vars that correlate with 
> > existing var
> >
> > Here is one way to do 
> it:..8<.snip.8<
> >   
> --
> Olivier ETERRADOSSI
> Maître-Assistant
> CMGD / Equipe "Propriétés Psycho-Sensorielles des Matériaux"
> Ecole des Mines d'Alès
> Hélioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9 tel std: +33 
> (0)5.59.30.54.25 tel direct: +33 (0)5.59.30.90.35
> fax: +33 (0)5.59.30.63.68
> http://www.ema.fr
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, min

Re: [R] Extent of time zone vulerability for POSIX date and time classes

2007-04-05 Thread Gabor Grothendieck
If you use

Sys.putenv(TZ = "GMT")

at the beginning of your session then local time zone and GMT time
zone will be the same so you should not have a problem.  This was
not possible, at least on Windows, at the time the R News article
was written.





On 4/5/07, Tim Bergsma <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I frequently convert date and time data to and from character
> representations.  I'm frustrated with chron, because 'seconds' are
> required to create a time object (my input data never has seconds).

You could use paste:

  times(paste("12:30", 0, sep = ":"))

and make it into a function if you use it a lot.

> More importantly, I cannot make chron print the format 12/30/2006 (which
> my output data requires).

That is the default output format so you don't have to specify anything. Its
only with POSIX that its not the default.  For example:

> library(chron)
> x <- chron("12/30/2006")
> x
[1] 12/30/06

>
> I really like the format flexibility of strftime() and strptime(), but
> of course am paranoid about timezone issues.  After reading the standard
> reference several times
> (http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf), I am tempted to
> conclude that if I never specify timezones, and never use Sys.time(),
> the vulnerabilities do not pertain.

That won't protect you but this would let you use POSIX safely:

http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg83508.html

>
> To the point: if I'm merely converting to and from character data that
> does not represent time zones, is there still a time zone vulnerability
> with strftime() and strptime()?
>
> Thanks in advance,
>
> Tim Bergsma, PhD
> Metrum Research Group, LLC
>
>
> #example
> strftime(
>   strptime(
> "30-Dec-06 23:30",
> format="%d-%b-%y %H:%M"
>   ),
>   format="%m/%d/%Y %H:%M"
> )
> [1] "12/30/2006 23:30"
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Running MCMCpack

2007-04-05 Thread Thomas Christin
Hi there,

 

I am running MCMCpack (MCMCirt1d model) on some files (26 items x about 800
– 1200 individuals).

 

I have a problem. When I am working on “big” files, the R program crashes.

 

More precisely I got the following Microsoft Warning: 

 

***

Microsoft Visual C++ Runtime Library

Runtime Error!

Program: C:\Program Files\R\R-2.4.1\bin\Rgui.exe

 

This application has requested the Runtime to terminate it in an unusual
way. Please contact the application’s support team for more information.

***

I click on OK and R close down.

 

Do you know how I could help my R program to run MCMC on my files?
(memory.limit is already set to (4*1024-1))

 

Many thanks and best greetings from Zurich (sorry, my german is rather
poor).

Thomas

 

Adresse / Address

 

Thomas Christin

Institut für Politikwissenschaft

Universität Zürich

Hirschengraben 56

8001 Zürich

Tel. (+41) 44 634 51 56

Fax. (+41) 44 634 50 98

Email :   [EMAIL PROTECTED]

URL: http://www.ipz.unizh.ch/mitarbeiter/interne/christin.php

 


[[alternative HTML version deleted]]

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


Re: [R] p value for coefficients in multinomial model

2007-04-05 Thread John Fox
Dear Xingwang Ye,

As it says on the help page for Anova(), "Be very careful in formulating the
model for type-III tests, or the hypotheses tested will not make sense."

 It looks as if you fit the model with the default contrast coding for the
factors, contr.treatment. To get sensible "Type-III" sums of squares, you
have to use contrasts that are orthogonal in the row basis of the model
matrix, such as contr.sum. 

SAS takes a different approach from R, using a deficient-rank
parametrization of the model, and then in effect placing a restriction on
the parameters that is equivalent to contr.treatment; it calculates
sums-of-squares in a manner that's independent of the parametrization, while
Anova() does not.

I hope this helps,
 John


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Xingwang Ye
> Sent: Thursday, April 05, 2007 9:01 AM
> To: r-help
> Subject: [R] p value for coefficients in multinomial model
> 
> Dear all,
>
> 1)how can I easily get p value for the coefficients of 
> factors in a multinomial model?
> 2)why the p values for "type III" test with Anova are not 
> identical to that from SAS?
>  
> for example:  
> 
>  A,B and C are categorical variables,but the proportions of 
> each level in each categorical variables are not balance. Y 
> is a nominal variables(>=3 categories); 
>   
> To do multinomial logistic regression in SAS, I tried proc 
> logistic data=a;  
> class A B C Y/param = ref ref = first;  
> model Y=A B C/link=logit;
> run;  
> 
> In R, I tried this:  
> library(car) 
> library(nnet)
> b <- as.data.frame(lapply(a[,c("A","B","C","Y")], as.factor))
> mod.mul<- (Y~A+B+C,data=b)  
> summary(mod.mul,cor=F,Wald=T) 
> Anova(mod.mul,type="III")
> 
> I can get the identical coefficients and std.errors in R as 
> in SAS. how can I easily get the p value for each 
> coeefficients? However,the "LR Chisq" for each variables are 
> similar but not identical to that from SAS, why?  
> 
> 
> BTW,please forward your kind answers to my email. Thank you.  
>   
> 
> Best wishes
> yours, sincerely 
> Xingwang Ye
> PhD candidate 
> Research Group of Nutrition Related Cancers and Other Chronic 
> Diseases  
> Institute for Nutritional Sciences,  
> Shanghai Institutes of Biological Sciences, 
> Chinese Academy of Sciences 
> P.O.Box 32 
> 294 Taiyuan Road 
> Shanghai 200031 
> P.R.CHINA
> 
>

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


Re: [R] Plotting multiple curves with lattice graphs

2007-04-05 Thread Gabor Grothendieck
Try this:

x <- 1:100
xyplot(dnorm(x, 50, 10) + dnorm(x, 55, 12) + dnorm(x, 60, 15) ~ x, type = "l")

By the way, you can save classic graphics, at least on windows, like this:

### your code
parms <- data.frame(ID=c(1,2,3),mu=c(50,55,60),sigma=c(10,12,15))
curve(dnorm(x,mean=parms$mu[1],sd=parms$sigma[1]),from=0,
to=150, ylab="density", col="red")
curve(dnorm(x,mean=parms$mu[2],sd=parms$sigma[2]),from=0,
to=150, ylab="density", col="blue", add=TRUE)
curve(dnorm(x,mean=parms$mu[3],sd=parms$sigma[3]),from=0,
to=150, ylab="density", col="forestgreen", add=TRUE)
###

myplot <- recordPlot()
title("Title A")

# replay the plot with Title B
replayPlot(myplot)
title("Title B")



On 4/5/07, Karen Chiswell <[EMAIL PROTECTED]> wrote:
> Hi List,
>
> I would like to plot multiple curves (parametric
> density curves) in one plot.
>
> For example:
> # parameters for three normal density curves
> parms =
> data.frame(ID=c(1,2,3),mu=c(50,55,60),sigma=c(10,12,15))
>
> # I can easily draw three normal density curves using
> curve():
> curve(dnorm(x,mean=parms$mu[1],sd=parms$sigma[1]),from=0,
> to=150, ylab="density", col="red")
> curve(dnorm(x,mean=parms$mu[2],sd=parms$sigma[2]),from=0,
> to=150, ylab="density", col="blue", add=TRUE)
> curve(dnorm(x,mean=parms$mu[3],sd=parms$sigma[3]),from=0,
> to=150, ylab="density", col="forestgreen", add=TRUE)
>
> but I would like to use lattice graphics (even though
> I only want one panel) because I want to save the
> resulting plot in an object.
>
> I could create a dataframe that contains the values I
> want to plot, and then plot using xyplot().  For
> example,
>
> x = seq(from=0, to=150, length=100)
> plot.df = data.frame(ID=rep(parms$ID,each=100),
> x=rep(x,3),mu=rep(parms$mu,each=100),sigma=rep(parms$sigma,each=100))
> plot.df$d =
> dnorm(plot.df$x,mean=plot.df$mu,sd=plot.df$sigma)
>
> require(lattice)
> p=xyplot(d~x, data=plot.df, groups=ID, type="l")
>
> However...  is there a more elegant/efficient way to
> do this?  I have tried using the panel.curve panel
> function (with xyplot() and histogram()), but I am not
> very experienced with using panel functions (or R
> actually), and I haven't had any success with this
> yet.
>
> Many thanks for any suggestions,
> Karen
>
> ---
> Karen Chiswell
> Department of Statistics
> North Carolina State University
> ---
>
>
>
>
> 
> It's here! Your new message!
> Get new email alerts with the free Yahoo! Toolbar.
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Densitymap

2007-04-05 Thread

Hello, 

we have a question concerning densitymaps. 
Actually, we found in the R help for package Geo Xp that the densitymap is
of the following form:

densitymap(long, lat, var,kernel='triweight',listvar=NULL, 
   listnomvar=NULL,carte=NULL, criteria=NULL,label="", 
   symbol=0,color=1, labvar="",axis=FALSE,
   lablong="", lablat="")

we tried this on our example but it didn't really work, so we are wondering
what var, kernel and listvar represent.
Thank you for your help!


-- 
View this message in context: 
http://www.nabble.com/Densitymap-tf3531800.html#a9856383
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] changing existing graphs optimally

2007-04-05 Thread Greg Snow
Using traditional and lattice(trellis) graphics, the usual approach is
to have your plotting commands in a script file (under windows you can
use the one with the GUI, in linux/unix you can have a text editor open
with the script).  Then either run the commands by copy/paste or using
the source function.  Then when you see something tha you would like to
change, just do the edits and rerun the code.

The ggplot package has some functionality for first specifying the data
that you want plotted, then how you want it plotted, then the command to
actually create the plot.  You can then modify how you want it plotted
and replot again.  

There are also some interfaces to external programs that work more like
what you describe.  There is a very basic interface to gnuplot in the
TeachingDemos package, the rggobi package interfaces with the ggobi
program, there may be others as well.

If you really want to get into deep magic, the recordPlot function
returns an object that contains the data and details used in the current
plot.  However, the way it is stored is subject to change and not always
stable, I tried modifying this once to change the range on the axis and
ended up crashing R, so I would not suggest that approach.  In general
it is easier to use my first suggestion rather than delving into the
guts of a recorded plot object.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of projection83
> Sent: Wednesday, April 04, 2007 9:41 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] changing existing graphs optimally
> 
> 
> hi there,
> 
> right now i am going about things a round about route with 
> graphs in that if i want to change the scale to log, I have 
> to to a "reset" with add=F, then program things to be redrawn 
> from scratch - bad coding basically:P
> 
> in plot(), the first arguement it needs is data - how do you 
> reference whats already there, rather than respecifying (or 
> am i supposed to use a different function?
> 
> thanks for any pointers!
> --
> View this message in context: 
> http://www.nabble.com/changing-existing-graphs-optimally-tf352
> 9483.html#a9849622
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] package for Matlab

2007-04-05 Thread Tobias Verbeke
Schmitt, Corinna wrote:
> Hallo,
>
> does a package for Matlab exist in R?
>   
To read and write MAT files, there is the R.matlab package:

http://cran.r-project.org/src/contrib/Descriptions/R.matlab.html

This package also enables bidirectional communication
between R and Matlab.

An alternative package with similar functionality (but not on CRAN
and according to its home page not yet functional on platforms other
than UNIX) is RMatlab

http://www.omegahat.org/RMatlab/

To ease translation of Matlab code, there is the matlab package:

http://cran.r-project.org/src/contrib/Descriptions/matlab.html

HTH,
Tobias
> If yes, where can I find it and how can I install it under R?
>
> Thanks, Corinna
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>   

-- 

Tobias Verbeke - Consultant
Business & Decision Benelux
Rue de la révolution 8
1000 Brussels - BELGIUM

+32 499 36 33 15
[EMAIL PROTECTED]

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


Re: [R] package for Matlab

2007-04-05 Thread Alberto Vieira Ferreira Monteiro
Petr PIKAL wrote:
>
> You probably could get quicker answer trying to use some search
> posibilities provided by CRAN. 
>
OTOH, if we try to google for "R", we get 1.880.000.000 hits :-)

Alberto Monteiro

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


Re: [R] package for Matlab

2007-04-05 Thread Henrique Dallazuanna
Hi Corinna!

I don't if this is , but look that:

http://cran-r.c3sl.ufpr.br/src/contrib/Descriptions/matlab.html
http://cran-r.c3sl.ufpr.br/src/contrib/Descriptions/R.matlab.html

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

On 05/04/07, Schmitt, Corinna <[EMAIL PROTECTED]> wrote:
>
>
>
> Hallo,
>
> here again my modified information:
>
> does a package for Matlab exist in R? I'm using Windows. I know that
> there exist one for UNIX. Does one exist for Windows? If yes, where can
> I find it and how can I install it under R?
>
> Thanks, Corinna
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Likelihood returning inf values to optim(L-BFGS-B) other options?

2007-04-05 Thread Prof Brian Ripley

On Thu, 5 Apr 2007, Ravi Varadhan wrote:


In your code, the variables x (which I assume is the observed data), Tvec,
and flag are not passed to the function as arguments.  This could be a
potential problem.


I think scoping will probably find them.


Another problem could be that you have to use "negative"
log-likelihood function as input to optim, since by default it "minimizes"
the function, whereas you are interested in finding the argmax of
log-likelihood.  So, in your function you should return (-ll) instead of ll.


OR set fnscale.  This is the most serious problem.


If the above strategies don't work, I would try different initial values (it
would be best if you have a data-driven strategy for picking a starting
value) and different optimization methods (e.g. conjugate gradient with
"Polak-Ribiere" steplength option, Nelder-Mead, etc.).


It looks to me as if the calculations are very vulnerable to 
overflow/underflow, as they use gamma and not lgamma.  They could be 
rearranged to be much stabler by computing the sum of logs for each 
sub-expression.


There were over 50 warnings, which we were not shown.  They probably 
explained the problem.


Beyond that, the feasible region seems to be the interior of the positive 
orthant, in which case transforming the parameters (e.g. working with 
their logs) would be a good idea.


Finally, always supply analytical gradients when you can (as would be easy 
here).




-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Thursday, April 05, 2007 6:12 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Likelihood returning inf values to optim(L-BFGS-B) other
options?

Dear R-help list,

I am working on an optimization with R by evaluating a likelihood
function that contains lots of Gamma calculations (BGNBD: Hardie Fader
Lee 2005 Management Science). Since I am forced to implement lower
bounds for the four parameters included in the model, I chose the
optim() function mith L-BFGS-B as method. But the likelihood often
returns inf-values which L-BFGS-B can't deal with.

Are there any other options to implement an optimization algorithm
with R accounting for lower bounds and a four parameter-space?

Here is the error message I receive (german):
--



out=optim(c(.1,.1,.1,.1),fn,method="L-BFGS-B",lower=c(.0001,.0001,.0001,.000
1,.0001))
Fehler in optim(c(0.1, 0.1, 0.1, 0.1), fn, method = "L-BFGS-B", lower
= c(1e-04,  :
L-BFGS-B benötigt endliche Werte von 'fn'
Zusätzlich: Es gab 50 oder mehr Warnungen (Anzeige der ersten 50 mit
warnings())
--
And this is the likelihood function:
--
fn<-function(p) {
A1=(gamma(p[1]+x)*p[2]^p[1])/(gamma(p[1]))
A2=(gamma(p[3]+p[4])*gamma(p[4]+x))/(gamma(p[4])*gamma(p[3]+p[4]+x))
A3=(1/(p[2]+Tvec))^(p[1]+x)
A4=(p[3]/(p[4]+x-1))*((1/(p[2]+t_x))^(p[1]+x))
ll=sum(log(A1*A2*(A3+flag*A4)))
return(ll)
}

Thank you very much for your help in advance!

Best regards,

Michael

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



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] ISO Sims test

2007-04-05 Thread Chris Elsaesser
Does anyone know of a package that includes the Modified Sims test
[Sims, 1972]?

This test is used in econometrics and is a kind of alternative to the
Granger test [Granger, 1969], which is in the package lmtest.

Thanks in advance,
chris


Refernces:

Granger, C.W.J. (1969), "Investigating Causal Relations by Econometric
Methods and Cross-Spectral Methods," Econometrica, 34, 424-438.

Sims, C. (1972), "Money, Income and Causality," American Economic
Review, 62, 540-552.


Chris Elsaesser, PhD703.637.9421 (o)
Principal Geospatial Scientist  703.371.7301 (m)
SPADAC Inc.
7921 Jones Branch Dr. Suite 600
McLean, VA 22102

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] coxme residuals

2007-04-05 Thread Youenn Drouet
Hi all,

I am trying to use the coxme function to fit a random effect cox model with 
correlated frailty. The function is working well but I would like to know 
how to get predicted values and residuals.

Thanks for your help,

Youenn Drouet,
Student in biostatistics from Lyon1 university.

_
Partagez des fichiers de toute taille dans Messenger !

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


[R] Plotting multiple curves with lattice graphs

2007-04-05 Thread Karen Chiswell
Hi List,

I would like to plot multiple curves (parametric
density curves) in one plot.  

For example:
# parameters for three normal density curves
parms =
data.frame(ID=c(1,2,3),mu=c(50,55,60),sigma=c(10,12,15))

# I can easily draw three normal density curves using
curve():
curve(dnorm(x,mean=parms$mu[1],sd=parms$sigma[1]),from=0,
to=150, ylab="density", col="red")
curve(dnorm(x,mean=parms$mu[2],sd=parms$sigma[2]),from=0,
to=150, ylab="density", col="blue", add=TRUE)
curve(dnorm(x,mean=parms$mu[3],sd=parms$sigma[3]),from=0,
to=150, ylab="density", col="forestgreen", add=TRUE)

but I would like to use lattice graphics (even though
I only want one panel) because I want to save the
resulting plot in an object.
 
I could create a dataframe that contains the values I
want to plot, and then plot using xyplot().  For
example,

x = seq(from=0, to=150, length=100)
plot.df = data.frame(ID=rep(parms$ID,each=100),
x=rep(x,3),mu=rep(parms$mu,each=100),sigma=rep(parms$sigma,each=100))
plot.df$d =
dnorm(plot.df$x,mean=plot.df$mu,sd=plot.df$sigma)

require(lattice)
p=xyplot(d~x, data=plot.df, groups=ID, type="l")

However...  is there a more elegant/efficient way to
do this?  I have tried using the panel.curve panel
function (with xyplot() and histogram()), but I am not
very experienced with using panel functions (or R
actually), and I haven't had any success with this
yet.  

Many thanks for any suggestions,
Karen

---
Karen Chiswell
Department of Statistics
North Carolina State University
---



 

It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.

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


Re: [R] Likelihood returning inf values to optim(L-BFGS-B) other options?

2007-04-05 Thread Jin Huang
Hi,
   
  I got this message sometimes too. Try to change the initial value and lower 
bound value and see if it works.
   
  Jin

[EMAIL PROTECTED] wrote:
  Dear R-help list,

I am working on an optimization with R by evaluating a likelihood 
function that contains lots of Gamma calculations (BGNBD: Hardie Fader 
Lee 2005 Management Science). Since I am forced to implement lower 
bounds for the four parameters included in the model, I chose the 
optim() function mith L-BFGS-B as method. But the likelihood often 
returns inf-values which L-BFGS-B can't deal with.

Are there any other options to implement an optimization algorithm 
with R accounting for lower bounds and a four parameter-space?

Here is the error message I receive (german):
--
> out=optim(c(.1,.1,.1,.1),fn,method="L-BFGS-B",lower=c(.0001,.0001,.0001,.0001,.0001))
Fehler in optim(c(0.1, 0.1, 0.1, 0.1), fn, method = "L-BFGS-B", lower 
= c(1e-04, :
L-BFGS-B benötigt endliche Werte von 'fn'
Zusätzlich: Es gab 50 oder mehr Warnungen (Anzeige der ersten 50 mit 
warnings())
--
And this is the likelihood function:
--
fn<-function(p) {
A1=(gamma(p[1]+x)*p[2]^p[1])/(gamma(p[1]))
A2=(gamma(p[3]+p[4])*gamma(p[4]+x))/(gamma(p[4])*gamma(p[3]+p[4]+x))
A3=(1/(p[2]+Tvec))^(p[1]+x)
A4=(p[3]/(p[4]+x-1))*((1/(p[2]+t_x))^(p[1]+x))
ll=sum(log(A1*A2*(A3+flag*A4)))
return(ll)
}

Thank you very much for your help in advance!

Best regards,

Michael

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


 
-
Be a PS3 game guru.

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Extent of time zone vulerability for POSIX date and time classes

2007-04-05 Thread Tim Bergsma
Hi.

I frequently convert date and time data to and from character 
representations.  I'm frustrated with chron, because 'seconds' are 
required to create a time object (my input data never has seconds).
More importantly, I cannot make chron print the format 12/30/2006 (which 
my output data requires).

I really like the format flexibility of strftime() and strptime(), but 
of course am paranoid about timezone issues.  After reading the standard 
reference several times 
(http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf), I am tempted to 
conclude that if I never specify timezones, and never use Sys.time(), 
the vulnerabilities do not pertain.

To the point: if I'm merely converting to and from character data that 
does not represent time zones, is there still a time zone vulnerability 
with strftime() and strptime()?

Thanks in advance,

Tim Bergsma, PhD
Metrum Research Group, LLC


#example
strftime(
   strptime(
 "30-Dec-06 23:30",
 format="%d-%b-%y %H:%M"
   ),
   format="%m/%d/%Y %H:%M"
)
[1] "12/30/2006 23:30"

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


Re: [R] Deming regression

2007-04-05 Thread davidr
Looking in the archives for Deming regression brings up a previous reply
of mine:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/57384.html ,
which may shed some light.

David L. Reiner
Rho Trading Securities, LLC
Chicago  IL  60605
312-362-4963

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Nguyen Dinh
Nguyen
Sent: Thursday, April 05, 2007 1:11 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Deming regression

Dear R helpers,
I would like to know whether there is any package in R for Deming
regression?
Many thanks
Nguyen

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


Re: [R] package for Matlab

2007-04-05 Thread Petr PIKAL
[EMAIL PROTECTED] napsal dne 05.04.2007 15:24:57:

> Hallo,
> 
> does a package for Matlab exist in R?

You probably could get quicker answer trying to use some search 
posibilities provided by CRAN. In first few hits from Rseek there is a 
package R.matlab. I hope it can be installed by a standard instalation 
procedures.

Regards
Petr

> If yes, where can I find it and how can I install it under R?
> 
> Thanks, Corinna
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] package for Matlab

2007-04-05 Thread Schmitt, Corinna


Hallo,

here again my modified information:

does a package for Matlab exist in R? I'm using Windows. I know that
there exist one for UNIX. Does one exist for Windows? If yes, where can
I find it and how can I install it under R?

Thanks, Corinna

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] permutations of a binary matrix with fixed margins

2007-04-05 Thread Mathieu Jérôme
Dear R Users,
How can I randomize a matrix (with contains only 0 and 1) with the
constraint that margin totals (columns and rows sums) are kept constant?
Some have called this "swap permutation" or something like that.

The principle is to find bloc of
10
01
and change it for
01
10
there can be several rows or columns between these numbers.
It probably exists in R, but I can't find the function. I am aware of
permcont, but it works only for 2x2 matrices

thanks in advance
Jerome

-- 
Jérôme Mathieu
Laboratory of soil tropical ecology
UPMC
[EMAIL PROTECTED]

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


Re: [R] Likelihood returning inf values to optim(L-BFGS-B) other options?

2007-04-05 Thread Ravi Varadhan
Hi,

In your code, the variables x (which I assume is the observed data), Tvec,
and flag are not passed to the function as arguments.  This could be a
potential problem.  Another problem could be that you have to use "negative"
log-likelihood function as input to optim, since by default it "minimizes"
the function, whereas you are interested in finding the argmax of
log-likelihood.  So, in your function you should return (-ll) instead of ll.

If the above strategies don't work, I would try different initial values (it
would be best if you have a data-driven strategy for picking a starting
value) and different optimization methods (e.g. conjugate gradient with
"Polak-Ribiere" steplength option, Nelder-Mead, etc.).  

Ravi.



---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: [EMAIL PROTECTED]

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 





-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Thursday, April 05, 2007 6:12 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Likelihood returning inf values to optim(L-BFGS-B) other
options?

Dear R-help list,

I am working on an optimization with R by evaluating a likelihood  
function that contains lots of Gamma calculations (BGNBD: Hardie Fader  
Lee 2005 Management Science). Since I am forced to implement lower  
bounds for the four parameters included in the model, I chose the  
optim() function mith L-BFGS-B as method. But the likelihood often  
returns inf-values which L-BFGS-B can't deal with.

Are there any other options to implement an optimization algorithm  
with R accounting for lower bounds and a four parameter-space?

Here is the error message I receive (german):
--
>
out=optim(c(.1,.1,.1,.1),fn,method="L-BFGS-B",lower=c(.0001,.0001,.0001,.000
1,.0001))
Fehler in optim(c(0.1, 0.1, 0.1, 0.1), fn, method = "L-BFGS-B", lower  
= c(1e-04,  :
L-BFGS-B benötigt endliche Werte von 'fn'
Zusätzlich: Es gab 50 oder mehr Warnungen (Anzeige der ersten 50 mit  
warnings())
--
And this is the likelihood function:
--
fn<-function(p) {
 A1=(gamma(p[1]+x)*p[2]^p[1])/(gamma(p[1]))
 A2=(gamma(p[3]+p[4])*gamma(p[4]+x))/(gamma(p[4])*gamma(p[3]+p[4]+x))
 A3=(1/(p[2]+Tvec))^(p[1]+x)
 A4=(p[3]/(p[4]+x-1))*((1/(p[2]+t_x))^(p[1]+x))
 ll=sum(log(A1*A2*(A3+flag*A4)))
 return(ll)
}

Thank you very much for your help in advance!

Best regards,

Michael

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] package for Matlab

2007-04-05 Thread Schmitt, Corinna
Hallo,

does a package for Matlab exist in R?
If yes, where can I find it and how can I install it under R?

Thanks, Corinna

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Transform distance constraints into a 2D-map

2007-04-05 Thread Emmanuel Levy
Dear all,

Could you please point me out to a function or set of functions that
would allow me to
optimize positions on the 2D map of points for which I are distance contrainted?

for example, if I have:
a   b   c
a 0.0 0.5 0.7
b 0.5 0.0 0.3
c 0.7 0.3 0.0

I would like to obtain (x,y) coordinates to plot A,B,C so that the
distance constraints are satisfied. i.e. a is 0.5 far from b, and o.7
far from c. etc ...

Many thanks for your help,

Best,

Emmanuel

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] p value for coefficients in multinomial model

2007-04-05 Thread Xingwang Ye
Dear all,
   
1)how can I easily get p value for the coefficients of factors in a multinomial 
model?
2)why the p values for "type III" test with Anova are not identical to that 
from SAS?
 
for example:  

 A,B and C are categorical variables,but the proportions of each level in each 
categorical variables are not balance. Y is a nominal variables(>=3 
categories); 
  
To do multinomial logistic regression in SAS, I tried  
proc logistic data=a;  
class A B C Y/param = ref ref = first;  
model Y=A B C/link=logit;  
run;  

In R, I tried this:  
library(car) 
library(nnet)
b <- as.data.frame(lapply(a[,c("A","B","C","Y")], as.factor))
mod.mul<- (Y~A+B+C,data=b)  
summary(mod.mul,cor=F,Wald=T) 
Anova(mod.mul,type="III")

I can get the identical coefficients and std.errors in R as in SAS. how can I 
easily get the p value for each coeefficients? However,the "LR Chisq" for each 
variables are similar but not identical to that from SAS, why?  


BTW,please forward your kind answers to my email. Thank you.  
  

Best wishes 
yours, sincerely 
Xingwang Ye
PhD candidate 
Research Group of Nutrition Related Cancers and Other Chronic Diseases  
Institute for Nutritional Sciences,  
Shanghai Institutes of Biological Sciences, 
Chinese Academy of Sciences 
P.O.Box 32 
294 Taiyuan Road 
Shanghai 200031 
P.R.CHINA

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 image.plot a XY grid file into a lat-lon map

2007-04-05 Thread Roger Bivand
On Thu, 5 Apr 2007, Vladimir Eremeev wrote:

> 
> If your country or state borders are polygons or polylines, you could
> convert them to desired projection using the function project from the
> package rgdal.
> 
> Latitude-longitude grid also could be added by generating desired
> polylines in lat-lon and converting them to the desired projection using
> project.
> 

Yes, the route would be to plot the image in its native projection, and
project the vector data (shorelines, countries) to the same projection.  
Similar topics have been discussed on the R-sig-geo list, including the
reading of netcdf files (which are a bit picky) with functions in the
rgdal package which import the coordinate reference system directly.

Please follow this up on R-sig-geo if you need more help.

> 
> Linda Smith wrote:
> > 
> > I have a netcdf gridded file with LCC projection. I can easily use
> > image.plot to visualize it. However, as the axises are in X,Y, not Lat and
> > Lon, I could not add state or country maps onto it (or lat lon
> > information).
> > I do have a grid2d file that describes the lat and lon for each (X,Y)
> > grid,
> > but the lat and lon are not regularly spaced, so I could not use
> > image.plot.
> > 
> > Does anyone know how to plot this type of gridded data so that country or
> > state borders can be easily added? Thanks a lot!
> > 
> 
> What do you mean by "grid2d file that describes the lat and lon for each
> (X,Y) grid"?
> If this are two rasters of the same size having corresponding latitude and
> longitude values in each raster cell, then you could use contourLines to get
> lat-lon grid. However, you, probably, will want to smooth it.
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] 20% off selected R and S-plus books from Cambridge University Press

2007-04-05 Thread Graham Robertson
Get 20% off selected Cambridge books for the R-help community.
 
Until the end of June,  R-help users  can get an exclusive discount on the 
following Cambridge University Press books that use R or S-plus!  Simply 
visit http://www.cambridge.org/rbooks and click the appropriate link to 
get more information about the book(s) that interests you. To get your 
discount, you will need to click the 'Add to Basket' button on the book's 
information page, and then enter the discount code  RSTATZ when prompted. 
You can order as many books as you wish from the list..

The books:

Data Analysis and Graphics Using R
2nd Edition
John Maindonald, Australian National University, Canberra
John Braun, University of Western Ontario

>From reviews of previous edition:
?I would strongly recommend the book to scientists who have already had a 
regression or a linear models course and who wish to learn to use R ? an 
easy-to-read and an understandable reference on the use of R for practical 
data analysis.?  R News

*Practical, hands-on, example-based approach deals with real-world issues
*Extensive use of graphs for exploration of data and interpretation of 
analyses
*R code, data sets, updates and exercise solutions, all provided on 
companion website
*This revised edition reflects changes in R since 2003 and has new 
material on survival analysis, random coefficient models, and the handling 
of high-dimensional data. 

9780521861168, Hardback, Offer  Price ?34.40/$64.00
Get your discount at: http://www.cambridge.org/rbooks


Bootstrap Methods and their Application
A. C. Davison, ?cole Polytechnique F?d?rale, Lausanne
D. V. Hinkley, University of California, Santa Barbara

?We recommend this book most highly. It made us stop and think regularly 
and contributed tremendously to our understanding of the bootstrap. It is 
an excellent book for professors, students, practitioners, and researchers 
alike.? Journal of American Statistical Association

* Numerous applied examples, developed in a coherent way with the 
necessary theoretical basis
*S-Plus programs for data analysis available at 
http://statwww.epfl.ch/davison/BMA/
* Each chapter includes both practical and theoretical exercises.

9780521574716, Paperback,  Offer  Price: ?30.00 /$48.00
Get your discount at: http://www.cambridge.org/rbooks



Quantile Regression
Roger Koenker, University of Illinois, Urbana-Champaign

'? well written and easy to read, with useful illustrations of important 
aspects of quantile regression. It is obvious that the author knows the 
subject inside out, giving an up-to-date, exhaustive account of the 
subject. ? The book is a valuable contribution to the statistical 
literature, and a must have for every statistician or econometrician 
interested in quantile regression methods.'
Journal of the Royal Statistical Society 

* Comprehensive study of quantile regression methods
* Tutorial on associated statistical software in R
* Illustrative applications from a broad variety of disciplines

9780521608275, Paperback, Offer  Price: ?15.99/$27.99
Get your discount at: http://www.cambridge.org/rbooks

Statistical Analysis of Stochastic Processes in Time
J. K. Lindsey, Universit? de Li?ge, Belgium

'This book is an extraordinary piece of literature ? It is simply a 
masterpiece and even the most experienced statistician will learn a thing 
or two from this text. ? It is more than a mere cookery book type of 
statistical commands, output and interpretation but, rather, a deep 
understanding and appreciation of the statistical thinking process. ? The 
book is well written and would be good reading for applied statisticians 
as well as all post-graduate and faculty members who interact with data. 
Libraries should purchase a copy.'Journal of the Royal Statistical 
Society, Series A

* Covers stochastic processes needed by research scientists and students 
with many practical examples and exercises
* Treats applications in a wide variety of disciplines
 * R code, data sets and worked examples provided free on author?s website
9780521837415, Hardback. Offer Price: ?33.59/$60.00
Get your discount at: http://www.cambridge.org/rbooks

Statistical Models
A. C. Davison, ?cole Polytechnique F?d?rale, Lausanne

?? an almost encyclopaedic survey of modern parametric statistics. In my 
view this mammoth and scholarly undertaking invites comparison with 
Kendall's original Advanced Theory of Statistics, providing as it does a 
snapshot of the discipline at the present time. Anybody who is seriously 
involved in the theory or practice of statistics would be well advised to 
ensure that they have access to a copy.?
Short Book Reviews
*Blends theory and practice to give a useful general discussion of 
statistical modelling
*Unrivalled coverage of major modern statistical methodologies
*Many problems, with practical exercises based on the S language at the 
end of each chapter

9780521773393, Hardback. Offer Price ?37.60/$68.00
Get your discount at: http://ww

[R] R Graphics training course - Basel - 21.22.23 may 2007

2007-04-05 Thread Romain Francois
Mango Solutions are pleased to announce the above 3 days R course in
Basel as part of our schedule for Q2 2007.

---
 R Graphics   -21th - 23rd May 2007 (Basel)
---


* Who Should Attend ?

This course is suitable for people with a basic working knowledge of
the R language, who want to take advantage of the full graphical
capabilities of R.


* Course Goals

-  Review the basic concepts of the R language
-  Understand the R Graphics Systems
-  Create meaningful graphics
-  Enable attendees to customize graphics


* Course Outline

1.  Refresh the basics of the R language
2.  R functions
3.  Overview of the R graphics systems
4.  Traditional Graphics
5.  Lattice Graphics
6.  Grid Graphics
7.  Beyond R Graphics: interactivity, 3D, ...


* Presenter Information

Romain Francois is a R consultant at Mango Solutions.
He has worked with R for 5 years, and is active in the R community.
Romain is also responsible for the R Graphics Gallery [1] and software
initiatives such as the R Search Sidebar for Firefox [2].


* Registration

Should you want to book a place on this course or have any questions
please contact [EMAIL PROTECTED]

Should your organization have more than 3 possible attendees why not
talk to us about hosting a customized and focused course delivered at
your premises? Details of further courses in alternative locations are
available at http://www.mango-solutions.com/services/training.html






[1] R Graphics Gallery:
   http://addictedtor.free.fr/graphiques/

[2] Search Sidebar extension for Firefox:
   http://addictedtor.free.fr/rsitesearch

-- 
Mango Solutions
data analysis that delivers

Tel:  +44(0) 1249 467 467
Fax:  +44(0) 1249 467 468
Mob:  +44(0) 7813 526 123

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] read.spss (package foreign) and SPSS 15.0 files

2007-04-05 Thread RINNER Heinrich
Hello,

does anyone have experience with reading SPSS Version 15.0 files into R 
(version 2.4.1, WinXP)?

I have long been sucessfully reading SPSS files with read.spss from the 
wonderful foreign package, but somehow after upgrading from SPSS14 to SPSS15 I 
seem to have problems.

Trying a simple example, where test.sav is a SPSS 15.0 data file consisting of 
x1=c(1,2,3) and x2=c("a","b","c"), I get this:
> read.spss(file = "C:\\temp\\test.sav")
Fehler in read.spss(file = "C:\\temp\\test.sav") : 
error reading system-file header
Zusätzlich: Warning message:
C:\temp\test.sav: File-indicated character representation code (Unknown) is not 
ASCII 

version infos:
R version 2.4.1 (under WinXP)
foreign version 0.8-18

Has anyone experienced the same, and can give a solution here (possibly other 
than "downgrade to SPSS14.0" ;-))?

Regards,
Heinrich.

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


Re: [R] clear console

2007-04-05 Thread Robert McFadden
Gabor thank you very much. It works wonderful.
Rob
 

> -Original Message-
> From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, April 05, 2007 1:39 PM
> To: Robert McFadden
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] clear console
> 
> Check out:
> 
> http://tolstoy.newcastle.edu.au/R/help/06/02/21634.html
> 
> On 4/5/07, Robert McFadden <[EMAIL PROTECTED]> wrote:
> > Hi R Users,
> >
> > In Windows I can clear console using CTRL-L, but can I do this by 
> > certain command in my programs? e.g
> >
> > for (i in 1:10){
> >
> > something
> >
> > clear console
> >
> > }
> >
> >
> >
> > Best,
> >
> > Rob
> >
> >
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] clear console

2007-04-05 Thread Bos, Roger

This has been asked previously and I happened to have saved the final
answer:

cls <- function() {
   require(rcom)
   wsh <- comCreateObject("Wscript.Shell")
   comInvoke(wsh, "SendKeys", "\014")
   invisible(wsh)
}
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Gabor
Grothendieck
Sent: Thursday, April 05, 2007 7:39 AM
To: Robert McFadden
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] clear console

Check out:

http://tolstoy.newcastle.edu.au/R/help/06/02/21634.html

On 4/5/07, Robert McFadden <[EMAIL PROTECTED]> wrote:
> Hi R Users,
>
> In Windows I can clear console using CTRL-L, but can I do this by 
> certain command in my programs? e.g
>
> for (i in 1:10){
>
> something
>
> clear console
>
> }
>
>
>
> Best,
>
> Rob
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

** * 
This message is for the named person's use only. It may 
contain confidential, proprietary or legally privileged 
information. No right to confidential or privileged treatment 
of this message is waived or lost by any error in 
transmission. If you have received this message in error, 
please immediately notify the sender by e-mail, 
delete the message and all copies from your system and destroy 
any hard copies. You must not, directly or indirectly, use, 
disclose, distribute, print or copy any part of this message 
if you are not the intended recipient.

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


[R] R 'could not find any X11 fonts'

2007-04-05 Thread fsando
I'm having this problem - and I have seen earlier post on the same 
problem - but the solutions either do not work for me or (being fairly 
new to linux) I do not understand the suggested actions.

So here goes:
Whenever I try to add a 'main' title R responds with an error that it 
can't find any X11 fonts.

### Very basic examples ###
# 1. No error (a scatterplot x=1:10 and y=1:10):
plot(1:10,1:10)
# 2. No error (as above, but add a subtitle):
plot(1:10,1:10,sub="subtitle")
# 3a. Error (as above, but add a main title):
plot(1:10,1:10,main="Main title")
# 3b. Error (an equivalent way to produce the same):
plot(1:10,1:10) # no error
title(main="main") # error

# produced error:
 > plot(1:10,1:10,main="main")
Error in title(...) : could not find any X11 fonts
Check that the Font Path is correct.

# output from sessionInfo()
 > sessionInfo()
Version 2.3.1 (2006-06-01)
i486-pc-linux-gnu

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

# I don't know if this is relevant but
# from getOption("X11fonts")
 > getOption('X11fonts')
[1] "-adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
[2] "-adobe-symbol-medium-r-*-*-%d-*-*-*-*-*-*-*"

### examples end ###

The solution may obvious for somebody more familiar with Linux, but as 
stated, I'm new to Linux, so I would appreciate detailed explanations.
Thanks

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


Re: [R] Question about R

2007-04-05 Thread John Kane
?sample
nams  <-  c(rep("a",10), rep("b",10))
table(sample(nams, 5, replace = TRUE))

--- Chia-Yi Tseng <[EMAIL PROTECTED]> wrote:

> Hi,
>
>   I would like to ask how can I do the problem as
> follows by R. Thank you very much.
>
>   Q: Create a list of twenty distinct first names,
> ten male and ten female, and store them into an
> array. Write a routine for selecting a simple random
> sample of five names and counts the number of male
> and female names in the sample when the sample is
> drawn :
>   (a) with replacement
>   (b) without replacement
> 
>  
> -
> Finding fabulous fares is fun.
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] gpclib library

2007-04-05 Thread Leonardo Lami

Hi
my OS is Linux Debian distribution, my R vers is 2.4.0 Patched
(2006-11-25 r39997)

I tried several repositories but the output is ever the same

Thank yor for your help

All the best
Leonardo


Prof Brian Ripley ha scritto:
> It's a _package_ that you are looking for (there is something else
> called a gpclib library, to do with GNU Pascal).
>
> You haven't told us your OS or R version, so we don't know what file
> you are looking for.  But try another mirror if one appears not to
> work (and using a US mirror with an email address in Italy seems odd).
> On Wed, 4 Apr 2007, Leonardo Lami wrote:
>
>> Hi all,
>> I'm tring to download the gpclib library but I don't find it in the old
>> repository
>>
>> install.packages(c("gpclib"), dependencies=TRUE,
>> repos="http://cran.cnr.berkeley.edu/";)
>> Avviso in install.packages(c("gpclib"), dependencies = TRUE, repos =
>> "http://cran.cnr.berkeley.edu/";) :
>> argument 'lib' is missing: using /usr/local/lib/R/site-library
>
> That's not what that message says: presumably you got some more output.
>
>>
>>
>> May be my old library have some problem:
>>
>> library(gpclib)
>> Errore in loadNamespace(package, c(which.lib.loc, lib.loc), keep.source
>> = keep.source) :
>>in 'gpclib', metodi da esportare specificati, ma nessuno
>> definito: show, get.bbox, plot, intersect, union, setdiff, [,
>> append.poly, scale.poly, area.poly, get.pts, coerce
>> Errore: caricamento pacchetto/namespace fallito per 'gpclib'
>>
>> Someone knows where I can find the library
>>
>> Thank you
>> Leonardo
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] reading of a matrix

2007-04-05 Thread Vladimir Eremeev


Schmitt, Corinna wrote:
> 
> I still have problems with the reading of a matrix.
> 
> Input: matrixData6.txt
> 
> A-Paar B-Paar C-Paar D-Paar E-Paar
> A 1  3  5  7  9
> B 2  4  6  8 10
> 
> 
> R-commands:
> y=read.table(file="Z:/Software/R-Programme/matrixData6.txt")
> y
> 
> Result:
>   A.Paar B.Paar C.Paar D.Paar E.Paar
> A  1  3  5  7  9
> B  2  4  6  8 10
> 
> If you look into the txt-file you can recognize that the column names
> are not the same. Why?
> 

Using "_" in variable names was illegal earlier (now this rule seems to be
relaxed).
read.table has converted names.
You could try to change them back (UNTESTED)
names(y) <- gsub(".", "_", names(y)), 


Schmitt, Corinna wrote:
> 
> If I add in the txt-file the line "MyData:" infront of all followed by a
> newline. The R-command as above response an error. How can I read the
> modified input and get the following result:
> 
> MyData:
> 
>A.Paar B.Paar C.Paar D.Paar E.Paar
> A  1  3  5  7  9
> B  2  4  6  8 10
> 

You could name your variable MyData:

> MyData<-read.table(   )
> MyData


Schmitt, Corinna wrote:
> 
> Another stupid question might be hows can I change the column and row
> names after I made "read.table"? I want to have the following result,
> for example:
> 
> MyData:
> 
>G  H  I  J  K
> M  1  3  5  7  9
> N  2  4  6  8 10
> 
> I studied all manuals I could find and the help but could not understand
> the examples or interpret it right for my case.
> 
> Thanks for help,
> Corinna
> 

names(MyData)<-c("G","H","I","J","K")
row.names(MyData)<-c("M","N")

-- 
View this message in context: 
http://www.nabble.com/reading-of-a-matrix-tf3530874.html#a9854003
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] clear console

2007-04-05 Thread Robert McFadden
Hi R Users,

In Windows I can clear console using CTRL-L, but can I do this by certain
command in my programs? e.g

for (i in 1:10){

something

clear console

}

 

Best,

Rob

 

[[alternative HTML version deleted]]

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


Re: [R] clear console

2007-04-05 Thread Gabor Grothendieck
Check out:

http://tolstoy.newcastle.edu.au/R/help/06/02/21634.html

On 4/5/07, Robert McFadden <[EMAIL PROTECTED]> wrote:
> Hi R Users,
>
> In Windows I can clear console using CTRL-L, but can I do this by certain
> command in my programs? e.g
>
> for (i in 1:10){
>
> something
>
> clear console
>
> }
>
>
>
> Best,
>
> Rob
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] reading of a matrix

2007-04-05 Thread Charilaos Skiadas
On Apr 5, 2007, at 6:50 AM, Schmitt, Corinna wrote:

> Dear R-experts,
>
> I still have problems with the reading of a matrix.
>
> Input: matrixData6.txt
>
> A-Paar B-Paar C-Paar D-Paar E-Paar
> A 1  3  5  7  9
> B 2  4  6  8 10
>
>
> R-commands:
> y=read.table(file="Z:/Software/R-Programme/matrixData6.txt")
> y
>
> Result:
>   A.Paar B.Paar C.Paar D.Paar E.Paar
> A  1  3  5  7  9
> B  2  4  6  8 10
>
>
> If you look into the txt-file you can recognize that the column names
> are not the same. Why?
>
Look at ?read.table for details, basically the variable names are  
turned into syntactically valid names via make.names (?make.names).  
This is, I pressume, so that you can later refer to them via: df 
$A.Paar  (df$A-Paar means something very different). You can try to  
add: check.names=FALSE to the read.table call, not sure it will do  
what you want it to.

> If I add in the txt-file the line "MyData:" infront of all followed  
> by a
> newline. The R-command as above response an error. How can I read the
> modified input and get the following result:

Hm, if you really want the MyData to show up in the result, then you  
will have to do some more hard work, since data frames don't really  
have a room for that. But if you simply want MyData: to show up in  
the text file but not be read by R, then you would want to prepend  
the line with the comment character, #.

> MyData:
>
>A.Paar B.Paar C.Paar D.Paar E.Paar
> A  1  3  5  7  9
> B  2  4  6  8 10
>
> Another stupid question might be hows can I change the column and row
> names after I made "read.table"? I want to have the following result,
> for example:
>
names(yourdf) <- c("G","H","I","J","K")
or perhaps better:
names(yourdf) <- LETTERS[6+1:5]

That's for the columns. Use ?rownames for the rows.
> MyData:
>
>G  H  I  J  K
> M  1  3  5  7  9
> N  2  4  6  8 10
>
> I studied all manuals I could find and the help but could not  
> understand
> the examples or interpret it right for my case.
>
> Thanks for help,
>
> Corinna
>
Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

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


Re: [R] reading of a matrix

2007-04-05 Thread Petr PIKAL
Hi

[EMAIL PROTECTED] napsal dne 05.04.2007 12:50:09:

> Dear R-experts,
> 
> I still have problems with the reading of a matrix.
> 
> Input: matrixData6.txt
> 
> A-Paar B-Paar C-Paar D-Paar E-Paar
> A 1  3  5  7  9
> B 2  4  6  8 10
> 
> 
> R-commands:
> y=read.table(file="Z:/Software/R-Programme/matrixData6.txt")
> y
> 
> Result:
>   A.Paar B.Paar C.Paar D.Paar E.Paar
> A  1  3  5  7  9
> B  2  4  6  8 10
> 
> 
> If you look into the txt-file you can recognize that the column names
> are not the same. Why?
> 
> If I add in the txt-file the line "MyData:" infront of all followed by a
> newline. The R-command as above response an error. How can I read the
> modified input and get the following result:
> 
> MyData:
> 
>A.Paar B.Paar C.Paar D.Paar E.Paar
> A  1  3  5  7  9
> B  2  4  6  8 10

The only difference I can see is centering columns and Mydata: row. This 
does not have anything with reading your data. You shall instead consult 
how your data is printed on console by looking at ?print help page. 
However I think that R itself is not the best tool for text formating.

> 
> Another stupid question might be hows can I change the column and row
> names after I made "read.table"? I want to have the following result,
> for example:
> 
> MyData:
> 
>G  H  I  J  K
> M  1  3  5  7  9
> N  2  4  6  8 10
> 
> I studied all manuals I could find and the help but could not understand
> the examples or interpret it right for my case.

Did you by chance try
?names or ?rownames

Regards
Petr


> 
> Thanks for help,
> 
> Corinna
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] gpclib library

2007-04-05 Thread Roger Bivand
On Thu, 5 Apr 2007, Leonardo Lami wrote:

> 
> Hi
> my OS is Linux Debian distribution, my R vers is 2.4.0 Patched
> (2006-11-25 r39997)
> 
> I tried several repositories but the output is ever the same

Please do not write to the author of the original non-R-project C code -
the package maintainer is the appropriate person. Your R version is now
out of date, and you may be caught by the current package depending on R
2.4.1 (that is probably why you got the "not found" message). If you can't
upgrade R to match gpclib, consider an older version of the package source
pre-dating R 2.4.1, such as:

http://cran.r-project.org/src/contrib/Archive/G/gpclib_1.3-3.tar.gz

> 
> Thank yor for your help
> 
> All the best
> Leonardo
> 
> 
> Prof Brian Ripley ha scritto:
> > It's a _package_ that you are looking for (there is something else
> > called a gpclib library, to do with GNU Pascal).
> >
> > You haven't told us your OS or R version, so we don't know what file
> > you are looking for.  But try another mirror if one appears not to
> > work (and using a US mirror with an email address in Italy seems odd).
> > On Wed, 4 Apr 2007, Leonardo Lami wrote:
> >
> >> Hi all,
> >> I'm tring to download the gpclib library but I don't find it in the old
> >> repository
> >>
> >> install.packages(c("gpclib"), dependencies=TRUE,
> >> repos="http://cran.cnr.berkeley.edu/";)
> >> Avviso in install.packages(c("gpclib"), dependencies = TRUE, repos =
> >> "http://cran.cnr.berkeley.edu/";) :
> >> argument 'lib' is missing: using /usr/local/lib/R/site-library
> >
> > That's not what that message says: presumably you got some more output.
> >
> >>
> >>
> >> May be my old library have some problem:
> >>
> >> library(gpclib)
> >> Errore in loadNamespace(package, c(which.lib.loc, lib.loc), keep.source
> >> = keep.source) :
> >>in 'gpclib', metodi da esportare specificati, ma nessuno
> >> definito: show, get.bbox, plot, intersect, union, setdiff, [,
> >> append.poly, scale.poly, area.poly, get.pts, coerce
> >> Errore: caricamento pacchetto/namespace fallito per 'gpclib'
> >>
> >> Someone knows where I can find the library
> >>
> >> Thank you
> >> Leonardo
> >>
> >> __
> >> R-help@stat.math.ethz.ch mailing list
> >> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [EMAIL PROTECTED]

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


Re: [R] gpclib library

2007-04-05 Thread Prof Brian Ripley
On Thu, 5 Apr 2007, Leonardo Lami wrote:

> my OS is Linux Debian distribution, my R vers is 2.4.0 Patched
> (2006-11-25 r39997)
>
> I tried several repositories but the output is ever the same

And you have *still* not had the courtesy to show us what it actually is 
(as asked for both by me and the posting guide). Mine starts

> install.packages("gpclib", dependencies=TRUE)
Warning in install.packages("gpclib", dependencies = TRUE) :
  argument 'lib' is missing: using ~/R/test-library
trying URL 'http://cran.r-project.org/src/contrib/gpclib_1.4-1.tar.gz'
Content type 'application/x-tar' length 24840 bytes
opened URL
==
downloaded 24Kb

* Installing *source* package 'gpclib' ...
[...]

>
> Thank yor for your help
>
> All the best
> Leonardo
>
>
> Prof Brian Ripley ha scritto:
>> It's a _package_ that you are looking for (there is something else
>> called a gpclib library, to do with GNU Pascal).
>>
>> You haven't told us your OS or R version, so we don't know what file
>> you are looking for.  But try another mirror if one appears not to
>> work (and using a US mirror with an email address in Italy seems odd).
>> On Wed, 4 Apr 2007, Leonardo Lami wrote:
>>
>>> Hi all,
>>> I'm tring to download the gpclib library but I don't find it in the old
>>> repository
>>>
>>> install.packages(c("gpclib"), dependencies=TRUE,
>>> repos="http://cran.cnr.berkeley.edu/";)
>>> Avviso in install.packages(c("gpclib"), dependencies = TRUE, repos =
>>> "http://cran.cnr.berkeley.edu/";) :
>>> argument 'lib' is missing: using /usr/local/lib/R/site-library
>>
>> That's not what that message says: presumably you got some more output.
>>
>>>
>>>
>>> May be my old library have some problem:
>>>
>>> library(gpclib)
>>> Errore in loadNamespace(package, c(which.lib.loc, lib.loc), keep.source
>>> = keep.source) :
>>>in 'gpclib', metodi da esportare specificati, ma nessuno
>>> definito: show, get.bbox, plot, intersect, union, setdiff, [,
>>> append.poly, scale.poly, area.poly, get.pts, coerce
>>> Errore: caricamento pacchetto/namespace fallito per 'gpclib'
>>>
>>> Someone knows where I can find the library
>>>
>>> Thank you
>>> Leonardo
>>>
>>> __
>>> R-help@stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>

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

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


Re: [R] Problems loading package GeoXp

2007-04-05 Thread Roger Bivand
On Wed, 4 Apr 2007, Carlos Guerra wrote:

> Dear useR's,
> I wanted to load the package GeoXP in my computer but I couldn't because 
> this warning message appeared:
> 
>  > require(GeoXp)
> Carregando pacotes exigidos: GeoXp
> Carregando pacotes exigidos: tcltk
> Loading Tcl/Tk interface ... Erro em fun(...) : couldn't connect to 
> display ":0"

The problem seems not to be GeoXp, but rather that your installation does 
not have a working tcltk/X11 setup. Can you check that your tcltk works, 
for example using it in update.packages()? Are you perhaps installing 
GeoXp on a server with no X11 rather than a workstation?


> Além disso: Warning message:
> pacote 'GeoXp' foi compilado na versão do R 2.4.1
> Erro: .onLoad falhou em 'loadNamespace' para 'tcltk'
> Erro: pacote 'tcltk' não pôde ser carregado
> 
> Can this package only be used under Windows??

No, it works on Linux workstations.

> 
> 
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] reading of a matrix

2007-04-05 Thread Schmitt, Corinna
Dear R-experts,

I still have problems with the reading of a matrix.

Input: matrixData6.txt

A-Paar B-Paar C-Paar D-Paar E-Paar
A 1  3  5  7  9
B 2  4  6  8 10


R-commands:
y=read.table(file="Z:/Software/R-Programme/matrixData6.txt")
y

Result:
  A.Paar B.Paar C.Paar D.Paar E.Paar
A  1  3  5  7  9
B  2  4  6  8 10


If you look into the txt-file you can recognize that the column names
are not the same. Why?

If I add in the txt-file the line "MyData:" infront of all followed by a
newline. The R-command as above response an error. How can I read the
modified input and get the following result:

MyData:

   A.Paar B.Paar C.Paar D.Paar E.Paar
A  1  3  5  7  9
B  2  4  6  8 10

Another stupid question might be hows can I change the column and row
names after I made "read.table"? I want to have the following result,
for example:

MyData:

   G  H  I  J  K
M  1  3  5  7  9
N  2  4  6  8 10

I studied all manuals I could find and the help but could not understand
the examples or interpret it right for my case.

Thanks for help,

Corinna

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


Re: [R] reading of a matrix

2007-04-05 Thread Schmitt, Corinna
Thank you very much. It realizes the things I want.

Thanks a lot, Corinna


-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Vladimir Eremeev
Gesendet: Donnerstag, 5. April 2007 13:25
An: r-help@stat.math.ethz.ch
Betreff: Re: [R] reading of a matrix



Schmitt, Corinna wrote:
> 
> I still have problems with the reading of a matrix.
> 
> Input: matrixData6.txt
> 
> A-Paar B-Paar C-Paar D-Paar E-Paar
> A 1  3  5  7  9
> B 2  4  6  8 10
> 
> 
> R-commands:
> y=read.table(file="Z:/Software/R-Programme/matrixData6.txt")
> y
> 
> Result:
>   A.Paar B.Paar C.Paar D.Paar E.Paar
> A  1  3  5  7  9
> B  2  4  6  8 10
> 
> If you look into the txt-file you can recognize that the column names
> are not the same. Why?
> 

Using "_" in variable names was illegal earlier (now this rule seems to be
relaxed).
read.table has converted names.
You could try to change them back (UNTESTED)
names(y) <- gsub(".", "_", names(y)), 


Schmitt, Corinna wrote:
> 
> If I add in the txt-file the line "MyData:" infront of all followed by a
> newline. The R-command as above response an error. How can I read the
> modified input and get the following result:
> 
> MyData:
> 
>A.Paar B.Paar C.Paar D.Paar E.Paar
> A  1  3  5  7  9
> B  2  4  6  8 10
> 

You could name your variable MyData:

> MyData<-read.table(   )
> MyData


Schmitt, Corinna wrote:
> 
> Another stupid question might be hows can I change the column and row
> names after I made "read.table"? I want to have the following result,
> for example:
> 
> MyData:
> 
>G  H  I  J  K
> M  1  3  5  7  9
> N  2  4  6  8 10
> 
> I studied all manuals I could find and the help but could not understand
> the examples or interpret it right for my case.
> 
> Thanks for help,
> Corinna
> 

names(MyData)<-c("G","H","I","J","K")
row.names(MyData)<-c("M","N")

-- 
View this message in context: 
http://www.nabble.com/reading-of-a-matrix-tf3530874.html#a9854003
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] glmmPQL and wald test or score test

2007-04-05 Thread Marc Bernard
Dear All,
   
  I would like to know if I can use the Wald test or the Score test for testing 
a set of parameter in a glmm model estimated by the glmmPQL method.  I am 
asking this question because I don't know  whether  the glmmPQL's estimates are 
maximum likelihood estimates or not, and also because  likelihood ration test  
cannot be used with this method.
   
  Many thanks,
   
  Bernard


-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Likelihood returning inf values to optim(L-BFGS-B) other options?

2007-04-05 Thread r
Dear R-help list,

I am working on an optimization with R by evaluating a likelihood  
function that contains lots of Gamma calculations (BGNBD: Hardie Fader  
Lee 2005 Management Science). Since I am forced to implement lower  
bounds for the four parameters included in the model, I chose the  
optim() function mith L-BFGS-B as method. But the likelihood often  
returns inf-values which L-BFGS-B can't deal with.

Are there any other options to implement an optimization algorithm  
with R accounting for lower bounds and a four parameter-space?

Here is the error message I receive (german):
--
> out=optim(c(.1,.1,.1,.1),fn,method="L-BFGS-B",lower=c(.0001,.0001,.0001,.0001,.0001))
Fehler in optim(c(0.1, 0.1, 0.1, 0.1), fn, method = "L-BFGS-B", lower  
= c(1e-04,  :
L-BFGS-B benötigt endliche Werte von 'fn'
Zusätzlich: Es gab 50 oder mehr Warnungen (Anzeige der ersten 50 mit  
warnings())
--
And this is the likelihood function:
--
fn<-function(p) {
 A1=(gamma(p[1]+x)*p[2]^p[1])/(gamma(p[1]))
 A2=(gamma(p[3]+p[4])*gamma(p[4]+x))/(gamma(p[4])*gamma(p[3]+p[4]+x))
 A3=(1/(p[2]+Tvec))^(p[1]+x)
 A4=(p[3]/(p[4]+x-1))*((1/(p[2]+t_x))^(p[1]+x))
 ll=sum(log(A1*A2*(A3+flag*A4)))
 return(ll)
}

Thank you very much for your help in advance!

Best regards,

Michael

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] or, you could consider R-spatial.

2007-04-05 Thread Vladimir Eremeev


http://r-spatial.sourceforge.net



Linda Smith wrote:
> 
> I have a netcdf gridded file with LCC projection. I can easily use
> image.plot to visualize it. However, as the axises are in X,Y, not Lat and
> Lon, I could not add state or country maps onto it (or lat lon
> information).
> I do have a grid2d file that describes the lat and lon for each (X,Y)
> grid,
> but the lat and lon are not regularly spaced, so I could not use
> image.plot.
> 
> Does anyone know how to plot this type of gridded data so that country or
> state borders can be easily added? Thanks a lot!
> 
> Linda
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-image.plot-a-XY-grid-file-into-a-lat-lon-map-tf3528721.html#a9852804
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 image.plot a XY grid file into a lat-lon map

2007-04-05 Thread Vladimir Eremeev

If your country or state borders are polygons or polylines, you could convert
them to desired projection using 
the function project from the package rgdal.

Latitude-longitude grid also could be added by generating desired polylines
in lat-lon and converting them to the desired projection using project.


Linda Smith wrote:
> 
> I have a netcdf gridded file with LCC projection. I can easily use
> image.plot to visualize it. However, as the axises are in X,Y, not Lat and
> Lon, I could not add state or country maps onto it (or lat lon
> information).
> I do have a grid2d file that describes the lat and lon for each (X,Y)
> grid,
> but the lat and lon are not regularly spaced, so I could not use
> image.plot.
> 
> Does anyone know how to plot this type of gridded data so that country or
> state borders can be easily added? Thanks a lot!
> 

What do you mean by "grid2d file that describes the lat and lon for each
(X,Y) grid"?
If this are two rasters of the same size having corresponding latitude and
longitude values in each raster cell, then you could use contourLines to get
lat-lon grid. However, you, probably, will want to smooth it.
-- 
View this message in context: 
http://www.nabble.com/how-to-image.plot-a-XY-grid-file-into-a-lat-lon-map-tf3528721.html#a9852612
Sent from the R help mailing list archive at Nabble.com.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Cluster in large dataset with nominal variables.

2007-04-05 Thread Kenneth Cabrera
Hi R users:

Is it any R implementation of a cluster procedure
for large data sets (clara()) but with dissimilary
that can handle continuous, categorical and
nominal variables (daisy()) like
CLARANS (Clustering Large Applications
  based up on RANdomized Search), por example?

Thank you for your help.

-- 
Kenneth Roy Cabrera Torres
Cel 315 504 9339

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


Re: [R] Generate a serie of new vars that correlate with existingvar

2007-04-05 Thread Olivier ETERRADOSSI
Hello, list
why not add the smart proposal by Greg Snow as a built-in function in 
{stats},
just changing the "x234" and "newc" lines to allow for more 
distributions to be generated ?
Or do I miss an already existing function to do that ?
Regards. Olivier


# slight modification of the original code by Greg Snow 
[mailto:[EMAIL PROTECTED]
# on April 04, 2007 1:46 AM

# generates ndistr vectors of same mean and sd, with various cor.coeffs
# input :
# x1 : a vector
# ndistr : number of distributions
# coefs : vector o ndistr correl. coeffs

CorelSets<-function(x1= rnorm(100, 15, 5),ndistr=3, coefs=c(0.4,0.5,0.6)){

# x2, x3, and x4 in a matrix, these will be modified to meet the criteria
x234 <- scale(matrix( rnorm(ndistr*length(x1)), ncol=ndistr ))

# put all into 1 matrix for simplicity
x1234 <- cbind(scale(x1),x234)

# find the current correlation matrix
c1 <- var(x1234)

# cholesky decomposition to get independence
chol1 <- solve(chol(c1))

newx <-  x1234 %*% chol1

# check that we have independence and x1 unchanged
zapsmall(cor(newx))
all.equal( x1234[,1], newx[,1] )

# create new correlation structure
newc<-diag(ndistr+1)
newc[1,-1]<- coefs
newc[-1,1]<- coefs

chol2 <- chol(newc)

finalx <- newx %*% chol2 * sd(x1) + mean(x1)
pairs(finalx)
CorelSets<-finalx
}
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="us-ascii"
>
> Dear Greg,
> Thanks million!
> "As good as it gets"  :) 
> All the best
> Nguyen
>
> -Original Message-
> From: Greg Snow [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, April 04, 2007 1:46 AM
> To: Nguyen Dinh Nguyen; r-help@stat.math.ethz.ch
> Subject: RE: [R] Generate a serie of new vars that correlate with existing
> var
>
> Here is one way to do it:..8<.snip.8<
>   
-- 
Olivier ETERRADOSSI
Maître-Assistant
CMGD / Equipe "Propriétés Psycho-Sensorielles des Matériaux"
Ecole des Mines d'Alès
Hélioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9
tel std: +33 (0)5.59.30.54.25
tel direct: +33 (0)5.59.30.90.35 
fax: +33 (0)5.59.30.63.68
http://www.ema.fr

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: problem for use R

2007-04-05 Thread Petr PIKAL
Hi

It is difficult from your question to derive what you exactly want. For 
reading Excel files there are several ways - see archives. I personally 
select some data in Excel press 
Ctrl-C and then in R 
read.delim("clipboard"), however sometimes can be prefered a way through 
saving txt or csv files. Other posibility is to use RODBC - see Data 
Export/Import manual.

If you want to write some data and use it in Excel they shall be in matrix 
or data.frame form and use 
write.table(, sep="\t", row names= FALSE). The file can be directly 
used by Excel.

Regards

Petr Pikal
[EMAIL PROTECTED]

[EMAIL PROTECTED] napsal dne 05.04.2007 08:55:09:

> hello,
> 
> we are french student, we have problem for export the test on Excel.
> we didn't succed for save and name the test so we can't export it...
> 
> 
> can you help us please
> thanks
> 
> _
> 
> mobile comme sur PC ! http://mobile.live.fr/messenger/bouygues/
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: Question about R

2007-04-05 Thread Petr PIKAL
Hi

isnt it a homework?

FYI see

?list
?vector
?data.frame
?sample
?lapply

and some basic stuff like Introduction manual provided with your R 
instalation to see how some simple data manipulations can be done.

Regards

Petr Pikal
[EMAIL PROTECTED]

[EMAIL PROTECTED] napsal dne 05.04.2007 05:58:48:

> Hi,
> 
>   I would like to ask how can I do the problem as follows by R. Thank 
you very much.
> 
>   Q: Create a list of twenty distinct first names, ten male and ten 
female, 
> and store them into an array. Write a routine for selecting a simple 
random 
> sample of five names and counts the number of male and female names in 
the 
> sample when the sample is drawn :
>   (a) with replacement
>   (b) without replacement
> 
> 
> -
> Finding fabulous fares is fun.
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multithreading

2007-04-05 Thread Prof Brian Ripley
1) Please update your R: 2.5.0 is imminent.

2) Please read the 'R Installation and Adminstration manual'.  R itself in 
not multithreaded but can make use of multithreaded BLAS.

3) A search of the list archives would have produced many hits, as does
RSiteSearch("multithreaded"), with more information.


On Thu, 5 Apr 2007, Ulrich Leopold wrote:

> Dear list,
>
> is R capable of multithreading? At the moment it uses only 1 CPU
> out of 4 CPUs on my system. Is there a compilation option or start option so
> that R uses multiple CPUs at the same time to accomplish a calculation?
>
> Some information on my system:
>
>> R.version
>   _
> platform   x86_64-pc-linux-gnu
> arch   x86_64
> os linux-gnu
> system x86_64, linux-gnu
> status
> major  2
> minor  3.1
> year   2006
> month  06
> day01
> svn rev38247
> language   R
> version.string Version 2.3.1 (2006-06-01)
>
>
> Best regards,
> Ulrich
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

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


[R] problem for use R

2007-04-05 Thread amelie despeaux
hello,

we are french student, we have problem for export the test on Excel.
we didn't succed for save and name the test so we can't export it...


can you help us please
thanks

_

mobile comme sur PC ! http://mobile.live.fr/messenger/bouygues/

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Deming regression

2007-04-05 Thread Nguyen Dinh Nguyen
Dear R helpers,
I would like to know whether there is any package in R for Deming
regression?
Many thanks
Nguyen

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


[R] Question about R

2007-04-05 Thread Chia-Yi Tseng
Hi,
   
  I would like to ask how can I do the problem as follows by R. Thank you very 
much.
   
  Q: Create a list of twenty distinct first names, ten male and ten female, and 
store them into an array. Write a routine for selecting a simple random sample 
of five names and counts the number of male and female names in the sample when 
the sample is drawn :
  (a) with replacement
  (b) without replacement

 
-
Finding fabulous fares is fun.

[[alternative HTML version deleted]]

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

2007-04-05 Thread Ulrich Leopold
Dear list,

is R capable of multithreading? At the moment it uses only 1 CPU
out of 4 CPUs on my system. Is there a compilation option or start option so
that R uses multiple CPUs at the same time to accomplish a calculation?

Some information on my system:

> R.version
   _
platform   x86_64-pc-linux-gnu
arch   x86_64
os linux-gnu
system x86_64, linux-gnu
status
major  2
minor  3.1
year   2006
month  06
day01
svn rev38247
language   R
version.string Version 2.3.1 (2006-06-01)


Best regards,
Ulrich

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