Re: [R] TR: Latent Class Analysis

2006-07-14 Thread Robert Mcfadden


> De : Pousset [mailto:[EMAIL PROTECTED]
> Envoyi : mardi 4 juillet 2006 18:38
> @ : 'r-help@stat.math.ethz.ch'
> Objet : Latent Class Analysis
> 
> 
> 
> Hello everybody,
> 
> 
> 
> I am working on latent class analysis and have already used the R
> function
> + lca ; (in the e1071 package). I ve got interesting results but I cant
> simply find out the methodology used by this routine :
> 
> 1) What kind of model is behind the routine (mixture model? If so, can you
> choose among different kind of distributions such as normal, Poisson,
> binomial)
> 
> 2) What kind of algorithm is used (hierarchical methods? Relocation
> methods?)
> 
> 3) Which criterion allows determining the best model?
> 
> In addition, I wonder if it is possible, with R software, to determine the
> best number of class or do one have to fix it a priori.
> 
> If one can help, thanks a lot,
> 
> 
> 
> Maud
> 
> INSERM U669, Cochin Hospital, Paris
> 
> 
> 


You can use package (available at R page) poLCA that has documentation
describing what you want. Look also at http://dlinzer.bol.ucla.edu/poLCA/
As far as you know BIC, AIC (based on chi-sqr and G^2 statistics) and
Cressie-Read allow you to choose the most appropriate model.
Best,
Robert

__
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


Re: [R] set the bahavior that R deal with missing values?

2006-07-14 Thread Dieter Menne
zhijie zhang  gmail.com> writes:

>  The default behavior in R when performing a regression model with missing
> values is to exclude any case that contains a
> missing value? How could i set the bahavior that R deal with missing values?

Difficult to say, since there is no such thing as a regression model in R, but
certainly more than a few dozens in several packages. Best show a self-contained
runnably sample where you would prefer some na.action (see, for example,
parameter na.action in lm).

Dieter

__
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


Re: [R] how to make a contour plot using data in long format

2006-07-14 Thread Dieter Menne
Maria Wang  hotmail.com> writes:

> 
> There is a dataset with Latitude Longitude information and corresponding 
> value shaped like this:
> Lati Longi  Value
> 18.0001 -159.6667 123
> 18.0023 -159.6665 124
> I want to use this data to make a filled contour map imposed on an USA map. 


Best use package geoR. There are also some examples in MASS (chapter 14).

Dieter

__
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


[R] Export to LaTeX

2006-07-14 Thread Mag. Ferri Leberl
Dear Everybody!
I want to export data to LaTeX. As I want to employ the data as freely as 
possible I want to avoid the xtable-command and instead generate some List 
like

\MyOwnPrettyCommand{Adam}{Auer}{17}
\MyOwnPrettyCommand{Bertram}{Bauer}{14}
\MyOwnPrettyCommand{Christoph}{Huber}{75}
\MyOwnPrettyCommand{Damian}{Dorfer}{69}
\MyOwnPrettyCommand{Emanuel}{Eder}{43}

with \MyOwnPrittyCommand defined elsewhere.
As a pitty, if I make up about such a table in r, lets call it "A", and use 
the commands

sink("tabelle.tex")
A
sink("anderedatei")

tabelle.tex will look like this:

 [,1]  [,2][,3] [,4] [,5] [,6] [,7]
[1,] "MyOwnPrettyCommand{" "Adam"  "}{" "Auer"   "}{" "17" "}" 
[2,] "MyOwnPrettyCommand{" "Bertram"   "}{" "Bauer"  "}{" "14" "}" 
[3,] "MyOwnPrettyCommand{" "Christoph" "}{" "Huber"  "}{" "75" "}" 
[4,] "MyOwnPrettyCommand{" "Damian""}{" "Dorfer" "}{" "69" "}" 
[5,] "MyOwnPrettyCommand{" "Emanuel"   "}{" "Eder"   "}{" "43" "}" 

So my question is how to export the data properly, without line-indices, 
without quotes but WITH backslashes.
Thank you in advance.
Yours,
Mag. Ferri Leberl

__
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


[R] mgcv::gam error message

2006-07-14 Thread Savrina Carrizo
Hi 

Could anyone please tell me what to do to resolve this error message?

I tried to run a gam with the mgcv package and got the following error:
"Error in qr.qty(qrc, sm$S[[1]]): NA/NaN/Inf in foreign function call (arg
5)"

(I have 116 covariates, I'm using the "cr" basis to speed things up, the
binomial family and, where necessary, have set the required k to lower than
the number of distinct values for a given covarate when less than the
default)

Thank you,
Savrina

[EMAIL PROTECTED]
School of Information Technologies
Univeristy of Sydney

__
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


Re: [R] Export to LaTeX

2006-07-14 Thread Tobias Verbeke
Mag. Ferri Leberl wrote:
> Dear Everybody!
> I want to export data to LaTeX. As I want to employ the data as freely as 
> possible I want to avoid the xtable-command and instead generate some List 
> like
>
> \MyOwnPrettyCommand{Adam}{Auer}{17}
> \MyOwnPrettyCommand{Bertram}{Bauer}{14}
> \MyOwnPrettyCommand{Christoph}{Huber}{75}
> \MyOwnPrettyCommand{Damian}{Dorfer}{69}
> \MyOwnPrettyCommand{Emanuel}{Eder}{43}
>
> with \MyOwnPrittyCommand defined elsewhere.
> As a pitty, if I make up about such a table in r, lets call it "A", and use 
> the commands
>
> sink("tabelle.tex")
> A
> sink("anderedatei")
>
> tabelle.tex will look like this:
>
>  [,1]  [,2][,3] [,4] [,5] [,6] [,7]
> [1,] "MyOwnPrettyCommand{" "Adam"  "}{" "Auer"   "}{" "17" "}" 
> [2,] "MyOwnPrettyCommand{" "Bertram"   "}{" "Bauer"  "}{" "14" "}" 
> [3,] "MyOwnPrettyCommand{" "Christoph" "}{" "Huber"  "}{" "75" "}" 
> [4,] "MyOwnPrettyCommand{" "Damian""}{" "Dorfer" "}{" "69" "}" 
> [5,] "MyOwnPrettyCommand{" "Emanuel"   "}{" "Eder"   "}{" "43" "}" 
>
> So my question is how to export the data properly, without line-indices, 
> without quotes but WITH backslashes.
>   
mydf <- as.data.frame(
  rbind(c("Adam",  "Auer",   17),
  c("Bertram",   "Bauer",  14),
  c("Christoph", "Huber",  75),
  c("Damian","Dorfer", 69),
  c("Emanuel",   "Eder",   43))
  )
cat(
paste("\\MyCommand{", mydf[,"V1"], "}{", mydf[,"V2"], "}{", 
mydf[,"V3"], "}",
  sep ="", collapse = "\n")
, file = "tabelle.tex")

HTH,
Tobias
> Thank you in advance.
> Yours,
> Mag. Ferri Leberl
>
> __
> 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
>
>
>

__
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


Re: [R] References verifying accuracy of R for basic statisticalcalculations and tests

2006-07-14 Thread Rau, Roland
Hi,
> [mailto:[EMAIL PROTECTED] On Behalf Of Corey Powell
> 
> Do you know of any references that verify the accuracy of R 
> for basic statistical calculations and tests.  The results of 
> these studies should indicate that R results are the same as 
> the results of other statistical packages to a certain number 
> of decimal places on some benchmark calculations.

I don't know of any references, but maybe you can somehow "verify the
accuracy of R" by running some analysis with the "NIST Statistical
Reference Datasets"; the URL is http://www.itl.nist.gov/div898/strd/ 
So maybe you can run the analyses mentioned there and say that R
(hopefully) returned the correct results.

Hope this helps,
Roland

--
This mail has been sent through the MPI for Demographic Rese...{{dropped}}

__
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


Re: [R] colors on graph

2006-07-14 Thread Jim Lemon
COMTE Guillaume wrote:
> Hy all,
> 
>  
> 
> I need to draw something in 2 dimension that has 3 dimension, the choice
> has been made to use colors to display the third dimension into the
> graph.
> 
>  
> 
> Has someone done something like that, i can't figure out how to
> parametize the colors.
> 
Hi Guilllaume,

Have a look at color.scale in the plotrix package.

Jim

__
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


Re: [R] Export to LaTeX

2006-07-14 Thread Dieter Menne
Mag. Ferri Leberl  gmx.at> writes:

> I want to export data to LaTeX. As I want to employ the data as freely as 
> possible I want to avoid the xtable-command and instead generate some List 
> like
> 
> \MyOwnPrettyCommand{Adam}{Auer}{17}
> \MyOwnPrettyCommand{Bertram}{Bauer}{14}
> \MyOwnPrettyCommand{Christoph}{Huber}{75}
> 
> with \MyOwnPrittyCommand defined elsewhere.


Method 1: Use latex in package Hmisc. It is VERY flexible, and works for me in
most cases.

Hint 1: "\" rarely works in R as in C, it must be escaped to "\\"

Hint 2: To increase you changes of getting a reply, always provide a full
example generating the sample data. For example, in most cases "Adam" will be
stored as a factor in the dataframe, which make things a bit more tricky. I used
I() to avoid this in the example below

d = data.frame(name=I(c("Auer","Caesar")),
   vname=I(c("Dieter","Karl")),age=c(10,30))
for (i in 1:nrow(d)) {
  d0 = d[i,]
  cat("\\MyNiceCommand{",d0$name,"}{",d0$vname,"}{",d0$age,"}\n",sep="")
}

You may nest this with sink, or better use the file argument in cat, don't
forget append.
Or directly use Rweave, which should not be too difficult for a LaTeXer, and
does not require the sink stuff.

Dieter

__
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


Re: [R] colors on graph

2006-07-14 Thread Joerg van den Hoff
Jim Lemon wrote:
> COMTE Guillaume wrote:
>> Hy all,
>>
>>  
>>
>> I need to draw something in 2 dimension that has 3 dimension, the choice
>> has been made to use colors to display the third dimension into the
>> graph.
>>
>>  
>>
>> Has someone done something like that, i can't figure out how to
>> parametize the colors.
>>
> Hi Guilllaume,
> 
> Have a look at color.scale in the plotrix package.
> 
> Jim
> 
> __
> 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


?image
?filled.contour

and the "See Also"s therein

__
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


[R] least square fit with non-negativity constraints for absorption spectra fitting

2006-07-14 Thread Xu, Xiuli \(NIH/NHLBI\) [E]
I would really appreciate it if someone can give suggestions on how to
do spectra fitting in R using ordinary least square fitting and
non-negativity constraints. The lm() function works well for ordinary
least square fitting, but how to specify non-negativity constraints? It
wouldn't make sense if the fitting coefficients coming out as negative
in absorption spectra deconvolution.

Thanks. 

Xiuli

__
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


Re: [R] References verifying accuracy of R for basic statisticalcalculations and tests

2006-07-14 Thread Sean O'Riordain
Please don't shoot!

q: would it be a good idea to use these datasets as a basis for some
regression tests?

Sean



On 14/07/06, Rau, Roland <[EMAIL PROTECTED]> wrote:
> Hi,
> > [mailto:[EMAIL PROTECTED] On Behalf Of Corey Powell
> >
> > Do you know of any references that verify the accuracy of R
> > for basic statistical calculations and tests.  The results of
> > these studies should indicate that R results are the same as
> > the results of other statistical packages to a certain number
> > of decimal places on some benchmark calculations.
>
> I don't know of any references, but maybe you can somehow "verify the
> accuracy of R" by running some analysis with the "NIST Statistical
> Reference Datasets"; the URL is http://www.itl.nist.gov/div898/strd/
> So maybe you can run the analyses mentioned there and say that R
> (hopefully) returned the correct results.
>
> Hope this helps,
> Roland
>
> --
> This mail has been sent through the MPI for Demographic Rese...{{dropped}}
>
> __
> 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
>

__
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


Re: [R] References verifying accuracy of R for basic statisticalcalculations and tests

2006-07-14 Thread Jesus Frias
Hi all,

There is a NISTnls package with the nonlinear regression examples in CRAN.
This work might have been done already.

regards,

Jesus


On Fri, July 14, 2006 10:57 am, Sean O'Riordain said:
> Please don't shoot!
>
> q: would it be a good idea to use these datasets as a basis for some
> regression tests?
>
> Sean
>
>
>
> On 14/07/06, Rau, Roland <[EMAIL PROTECTED]> wrote:
>> Hi,
>> > [mailto:[EMAIL PROTECTED] On Behalf Of Corey Powell
>> >
>> > Do you know of any references that verify the accuracy of R
>> > for basic statistical calculations and tests.  The results of
>> > these studies should indicate that R results are the same as
>> > the results of other statistical packages to a certain number
>> > of decimal places on some benchmark calculations.
>>
>> I don't know of any references, but maybe you can somehow "verify the
>> accuracy of R" by running some analysis with the "NIST Statistical
>> Reference Datasets"; the URL is http://www.itl.nist.gov/div898/strd/
>> So maybe you can run the analyses mentioned there and say that R
>> (hopefully) returned the correct results.
>>
>> Hope this helps,
>> Roland
>>
>> --
>> This mail has been sent through the MPI for Demographic
>> Rese...{{dropped}}
>>
>> __
>> 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
>>
>
> __
> 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
>
>
> This message has been scanned for content and viruses by the
> DIT Information Services MailScanner Service
> and is believed to be clean.
> http://www.dit.ie
>
>
>


School of Food Science and Environmental Health
Dublin Institute of Technology
t + 1 402 4459
f + 1 402 4495
w www.dit.ie/DIT/tourismfood/science/



This message has been scanned for content and viruses by the
DIT Information Services MailScanner Service
and is believed to be clean.
http://www.dit.ie

__
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


Re: [R] test regression against given slope for reduced major axis regression (RMA)

2006-07-14 Thread Patrick Drechsler

Patrick Drechsler wrote on 11 Jul 2006 02:10:21 MET:

[...]
> I am now confronted with the problem that I have data which
> requires a modelII regression (also called reduced major axes
> regression (RMA) or geometric mean regression). For this I use
> the function "modelII" (see below).
>
> What would be a good way of adapting
> "test_regression_against_slope" for use with RMA regression?
>
> The question I am trying to answer is: "Does the slope acquired
> from experimental data differ significantly from theoretical
> predictions?"

JFTR: David Warton's "smatr" package solves the problem.
-- 
"You know the world is going crazy when the best rapper is a white
guy, the best golfer is a black guy, the Swiss hold the America's Cup,
France is accusing the US of arrogance, and Germany doesn't want to go
to war."  -- Charles Barkley

__
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


Re: [R] References verifying accuracy of R for basic statisticalcalculations and tests

2006-07-14 Thread Prof Brian Ripley
On Fri, 14 Jul 2006, Sean O'Riordain wrote:

> Please don't shoot!
> 
> q: would it be a good idea to use these datasets as a basis for some
> regression tests?

See package NISTnls

> On 14/07/06, Rau, Roland <[EMAIL PROTECTED]> wrote:
> > Hi,
> > > [mailto:[EMAIL PROTECTED] On Behalf Of Corey Powell
> > >
> > > Do you know of any references that verify the accuracy of R
> > > for basic statistical calculations and tests.  The results of
> > > these studies should indicate that R results are the same as
> > > the results of other statistical packages to a certain number
> > > of decimal places on some benchmark calculations.
> >
> > I don't know of any references, but maybe you can somehow "verify the
> > accuracy of R" by running some analysis with the "NIST Statistical
> > Reference Datasets"; the URL is http://www.itl.nist.gov/div898/strd/
> > So maybe you can run the analyses mentioned there and say that R
> > (hopefully) returned the correct results.

`Correct' as in `as obtained by NIST'?  It is a considerable assumption 
that the reference results are 'correct' or 'accurate'.

I learnt from my work with analytical chemists that the outlying result 
could be the only reasonably accurate one: all the other analysts had made 
the same error.

> > Hope this helps,
> > Roland

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


[R] Generating random normal distribution with mean 0 and standard deviation 1

2006-07-14 Thread Neuro LeSuperHéros
Hello,

This must be really simple, but I can't find it on R Site search.  I need to 
generate a random normally distributed series with mean 0 and sd 1. In 
Matlab, this code is randn(n).

The closest I found is runif(20,-1,1) but this forces a maximum and a 
minimum, and there's no way to specify a standard deviation of 1.

>sd(runif(20,-1,1))
[1] 0.578164

__
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


Re: [R] Generating random normal distribution with mean 0 and standard deviation 1

2006-07-14 Thread Sean O'Riordain
?rnorm

On 14/07/06, Neuro LeSuperHéros <[EMAIL PROTECTED]> wrote:
> Hello,
>
> This must be really simple, but I can't find it on R Site search.  I need to
> generate a random normally distributed series with mean 0 and sd 1. In
> Matlab, this code is randn(n).
>
> The closest I found is runif(20,-1,1) but this forces a maximum and a
> minimum, and there's no way to specify a standard deviation of 1.
>
> >sd(runif(20,-1,1))
> [1] 0.578164
>
> __
> 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
>

__
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


Re: [R] Generating random normal distribution with mean 0 and standarddeviation 1

2006-07-14 Thread michael watson \(IAH-C\)
See rnorm() 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Neuro 
LeSuperHéros
Sent: 14 July 2006 13:15
To: r-help@stat.math.ethz.ch
Subject: [R] Generating random normal distribution with mean 0 and 
standarddeviation 1

Hello,

This must be really simple, but I can't find it on R Site search.  I need to 
generate a random normally distributed series with mean 0 and sd 1. In 
Matlab, this code is randn(n).

The closest I found is runif(20,-1,1) but this forces a maximum and a 
minimum, and there's no way to specify a standard deviation of 1.

>sd(runif(20,-1,1))
[1] 0.578164

__
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

__
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


Re: [R] Generating random normal distribution with mean 0 and standard deviation 1

2006-07-14 Thread Marc Schwartz
On Fri, 2006-07-14 at 08:14 -0400, Neuro LeSuperHéros wrote:
> Hello,
> 
> This must be really simple, but I can't find it on R Site search.  I need to 
> generate a random normally distributed series with mean 0 and sd 1. In 
> Matlab, this code is randn(n).
> 
> The closest I found is runif(20,-1,1) but this forces a maximum and a 
> minimum, and there's no way to specify a standard deviation of 1.
> 
> >sd(runif(20,-1,1))
> [1] 0.578164

help.search("normal") leads you to "Normal(stats)".

?Normal leads you to rnorm().

More generally, help.search("distributions") will give you an overview
of the various distributions available in your installation.

HTH,

Marc Schwartz

__
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


Re: [R] least square fit with non-negativity constraints fo r absorption spectra fitting

2006-07-14 Thread Dieter Menne
Xu, Xiuli (NIH/NHLBI) [E]  nhlbi.nih.gov> writes:

> 
> I would really appreciate it if someone can give suggestions on how to
> do spectra fitting in R using ordinary least square fitting and
> non-negativity constraints. The lm() function works well for ordinary
> least square fitting, but how to specify non-negativity constraints? It
> wouldn't make sense if the fitting coefficients coming out as negative
> in absorption spectra deconvolution.

I don't see much reasons to use lm() to fit a spectrum, but if you want to do
that,  negative coefficients simply mean a shift by pi, sothe sign can be
discarded for most practical purposed. 

But better look at one of the specialized packages like spectrino.

Dieter

__
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


Re: [R] least square fit with non-negativity constraints for absorption spectra fitting

2006-07-14 Thread Joerg van den Hoff
Xu, Xiuli (NIH/NHLBI) [E] wrote:
> I would really appreciate it if someone can give suggestions on how to
> do spectra fitting in R using ordinary least square fitting and
> non-negativity constraints. The lm() function works well for ordinary
> least square fitting, but how to specify non-negativity constraints? It
> wouldn't make sense if the fitting coefficients coming out as negative
> in absorption spectra deconvolution.
> 
> Thanks. 
> 
> Xiuli
> 

I'm not sure, but would presume that constraints could not be imposed on 
a linear least squares fit. maybe someone can correct me.

if you move to `nls', i.e. non-linear least squares fitting, you should 
be able to transform your model function. say, you want some parameter 
`a' to stay positive. then you could e.g. substitute

`a = exp(b)' in the model function and fit `b' without constraints in 
the "new" model and calculate `a' afterwards (which obviously is 
guaranteed now to be positive). note that error estimates would than 
have to be computed by gaussian error propagation from `b' to `a'.


joerg

__
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


[R] Negative Binomial: Simulation

2006-07-14 Thread Hadassa Brunschwig
Hi R-Users!

I fitted a negative binomial distribution to my count data using the
function glm.nb() and obtained the calculated parameters
theta (dispersion) and mu.

I would like to simulate values from this negative binomial distribution.
Looking at the function rnbinom() I was looking at the relationship
between the two possible parametrizations of the negative binomial and found
that for this fuction I must use:

prob = theta/(theta+mu) and   size = theta

Theta, however, is not an integer. So how can size (which is the number of
successes) equal theta?

I know there is a function rnegbin which does what I want. I would still
like to raise the above question (probably a more statistical one
than R).

Thanks a lot for any comments.

Hadassa

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


[R] Negative Binomial: Simulation

2006-07-14 Thread Hadassa Brunschwig
Hi R-Users!

(sorry about the last email)
I fitted a negative binomial distribution to my count data using the
function glm.nb() and obtained the calculated parameters
theta (dispersion) and mu.

I would like to simulate values from this negative binomial distribution.
Looking at the function rnbinom() I was looking at the relationship
between the two possible parametrizations of the negative binomial and found
that for this fuction I must use:

prob = theta/(theta+mu) and   size = theta

Theta, however, is not an integer. So how can size (which is the number of
successes) equal theta?

I know there is a function rnegbin which does what I want. I would still
like to raise the above question (probably a more statistical one
than R).

Thanks a lot for any comments.

Hadassa

__
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


[R] MLE and QR classes

2006-07-14 Thread ricardosilva
Hi,

I load my data set and separate it as folowing:

presu <- read.table("C:/_Ricardo/Paty/qtdata_f.txt", header=TRUE, sep="\t",
na.strings="NA", dec=".", strip.white=TRUE)
dep<-presu[,3];
exo<-presu[,4:92];

Now, I want to use it using the wls and quantreg packages. How I change the
data classes for mle and rq objects?

Thanks a lot,

Ricardo Gonçalves Silva

__
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


Re: [R] Write a summary or a longer text to a graphical device

2006-07-14 Thread Katharine Mullen
one option is to display your information in a tcltk window - load tcltk
and say demo(tkfaq) for an example of loading a txt file into a window
with a scrollbar (to apply this example directly you would first write
what you wanted to file)

>From: "Torsten Mathies" <[EMAIL PROTECTED]>
>To: 
>Subject: [R] Write a summary or a longer text to a graphical device
>Date: Thu, 13 Jul 2006 22:39:37 +0200
>
>How can I write a text, such as a result of a function or an explanation
>to a graphic device?
>
>When I try plot, I'm unable to reduce the axes.
>
>Greetings
>
>torsten
>
>__
>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


Katharine Mullen
Department of Physics and Astronomy
Faculty of Sciences
Vrije Universiteit Amsterdam
de Boelelaan 1081
1081 HV Amsterdam
The Netherlands
room: T.1.06
tel: +31 205987870
fax: +31 205987992
e-mail: [EMAIL PROTECTED]
http://www.nat.vu.nl/~kate/

__
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


Re: [R] Negative Binomial: Simulation

2006-07-14 Thread Hadassa Brunschwig
Addition to last email:

The problem basically arises also when I want to calculate (plot) the
cumulative distribution of the negative binomial with the calculated
parameters mu and theta!

On 7/14/06, Hadassa Brunschwig <[EMAIL PROTECTED]> wrote:
> Hi R-Users!
>
> (sorry about the last email)
> I fitted a negative binomial distribution to my count data using the
> function glm.nb() and obtained the calculated parameters
> theta (dispersion) and mu.
>
> I would like to simulate values from this negative binomial distribution.
> Looking at the function rnbinom() I was looking at the relationship
> between the two possible parametrizations of the negative binomial and found
> that for this fuction I must use:
>
> prob = theta/(theta+mu) and   size = theta
>
> Theta, however, is not an integer. So how can size (which is the number of
> successes) equal theta?
>
> I know there is a function rnegbin which does what I want. I would still
> like to raise the above question (probably a more statistical one
> than R).
>
> Thanks a lot for any comments.
>
> Hadassa
>

__
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


Re: [R] References verifying accuracy of R for basic statisticalcalculations and tests

2006-07-14 Thread Rau, Roland

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Prof 
> Brian Ripley
> 
> `Correct' as in `as obtained by NIST'?  It is a considerable 
> assumption 
> that the reference results are 'correct' or 'accurate'.
> 
> I learnt from my work with analytical chemists that the 
> outlying result 
> could be the only reasonably accurate one: all the other 
> analysts had made 
> the same error.
> 

Sorry for being a bit off-topic, but what would you recommend then to
convince people that the results of an analysis are correct?
Simulating data with the characteristics you want to "capture" in the
data, analyze those artifical data first and if everything goes well
proceed with your "real" data?

Thanks,
Roland

--
This mail has been sent through the MPI for Demographic Rese...{{dropped}}

__
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


[R] Cluster Analysis with flexible beta linkage method

2006-07-14 Thread Wade Wall
Hi all,

I am trying to run a cluster analysis using Sorenson (Bray-Curtis) distance
measure with flexible beta linkage method.  However, I can't seem to find
flexible beta in any of the functions/packages I have looked at.

Any help would be appreciated.

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


Re: [R] least square fit with non-negativity constraints for absorption spectra fitting

2006-07-14 Thread Prof Brian Ripley
On Fri, 14 Jul 2006, Joerg van den Hoff wrote:

> Xu, Xiuli (NIH/NHLBI) [E] wrote:
> > I would really appreciate it if someone can give suggestions on how to
> > do spectra fitting in R using ordinary least square fitting and
> > non-negativity constraints. The lm() function works well for ordinary
> > least square fitting, but how to specify non-negativity constraints? It
> > wouldn't make sense if the fitting coefficients coming out as negative
> > in absorption spectra deconvolution.
> > 
> > Thanks. 
> > 
> > Xiuli
> > 
> 
> I'm not sure, but would presume that constraints could not be imposed on 
> a linear least squares fit. maybe someone can correct me.

They can, and you get a simple quadratic programming problem.  So quadprog 
could be used to solve this one, but optim(methods="L-BFGS-B") may be as 
easy (and is pretty efficient on this class of QP problems).

S-PLUS has a function nnls.fit() for 'non-negative least squares'.

> if you move to `nls', i.e. non-linear least squares fitting, you should 
> be able to transform your model function. say, you want some parameter 
> `a' to stay positive. then you could e.g. substitute
> 
> `a = exp(b)' in the model function and fit `b' without constraints in 
> the "new" model and calculate `a' afterwards (which obviously is 
> guaranteed now to be positive). note that error estimates would than 
> have to be computed by gaussian error propagation from `b' to `a'.

The problem here is that a = 0 is a possible (and indeed plausible) value.

See MASS4 p.227 for nnls.fit and alternatives for use in R.  The MASS3 
ch08 script had an example of a regression with non-negative slope:

data(whiteside)
attach(whiteside)
Gas <- Gas[Insul=="Before"]
Temp <- -Temp[Insul=="Before"]
#nnls.fit(cbind(1, -1, Temp), Gas)
# can use box-constrained optimizer
fn <- function(par) sum((Gas - par[1] - par[2]*Temp)^2)
optim(rep(0,2), fn, lower=c(-Inf,0), method="L-BFGS-B")$par
rm(Gas, Temp)
detach()


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


Re: [R] Negative Binomial: Simulation

2006-07-14 Thread Prof Brian Ripley
On Fri, 14 Jul 2006, Hadassa Brunschwig wrote:

> Addition to last email:
> 
> The problem basically arises also when I want to calculate (plot) the
> cumulative distribution of the negative binomial with the calculated
> parameters mu and theta!
> 
> On 7/14/06, Hadassa Brunschwig <[EMAIL PROTECTED]> wrote:
> > Hi R-Users!
> >
> > (sorry about the last email)
> > I fitted a negative binomial distribution to my count data using the
> > function glm.nb() and obtained the calculated parameters
> > theta (dispersion) and mu.
> >
> > I would like to simulate values from this negative binomial distribution.
> > Looking at the function rnbinom() I was looking at the relationship
> > between the two possible parametrizations of the negative binomial and found
> > that for this fuction I must use:
> >
> > prob = theta/(theta+mu) and   size = theta
> >
> > Theta, however, is not an integer. So how can size (which is the number of
> > successes) equal theta?

>From ?rnegbin

size: target for number of successful trials, or dispersion
  parameter (the shape parameter of the gamma mixing
  distribution). Must be strictly positive.

Notice the 'or', and please see also the Details.

> > I know there is a function rnegbin which does what I want. I would still
> > like to raise the above question (probably a more statistical one
> > than R).
> >
> > Thanks a lot for any comments.
> >
> > Hadassa

> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

It does seem to be a question of following the posting guide.

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


Re: [R] least square fit with non-negativity constraints for absorption spectra fitting

2006-07-14 Thread Lu Yuefeng
Were you doing blind deconvolution or the spectrum basis are assummed to be
known?

As for blind deconvolution, alternatively you might consider alternating
least square, non-negative matrix factorization, or independent component
analysis + alternating least square as the post-processing.

yfl

On 7/11/06, Xu, Xiuli (NIH/NHLBI) [E] <[EMAIL PROTECTED]> wrote:
>
> I would really appreciate it if someone can give suggestions on how to
> do spectra fitting in R using ordinary least square fitting and
> non-negativity constraints. The lm() function works well for ordinary
> least square fitting, but how to specify non-negativity constraints? It
> wouldn't make sense if the fitting coefficients coming out as negative
> in absorption spectra deconvolution.
>
> Thanks.
>
> Xiuli
>
> __
> 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
>

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


Re: [R] non positive-definite G matrix in mixed models: bootstrap?

2006-07-14 Thread Spencer Graves
  Have you considered 'simulate.lme'?  I believe that this is what 
Bates included in the 'nlme' package for obtaining confidence intervals, 
joint confidence regions, etc., when there were questions about the 
results for whatever reason.  I have not tried it with a singular model, 
but I believe Bates has.  In particular, have you reviewed ch. 2 in 
Pinheiro and Bates (2000) Mixed-Effects Models in S and S-Plus (Springer)?

  I am not a fan of bootstrapping.  In mixed-effects applications, 
bootsrapping needs to incorporate the constraints imposed by the 
mixed-effects model.  For example, if you have several samples per batch 
and several batches per lot, you need to bootstrap lots as well as 
batches within lot and samples within batch.

  The advantage of bootstrapping is that if the normality assumptions 
behind the mixed model do not hold, the bootstrap results will still 
have some validity.  However, the range of extrapolability of bootstrap 
results is limited to other situations whose distribution is plausibly 
like the particular sample you bootstrapped, and I wouldn't know how to 
evaluate that.  By contrast, I know how to extrapolate simulation 
results.  To decide whether such results apply, I make normal 
probability plots of the data, random effects, and residuals.  If they 
all seem normal, I feel it is reasonable to use the simulation results.

  Others may offer a different perspective (or a correction, as the 
case may be).  However, you asked for comments about bootstrapping mixed 
models.  At least you've got one.

  Hope this helps.
  Spencer Graves

Bruno L. Giordano wrote:
> Dear list,
> In a mixed model I selected I find a non positive definite random effects 
> variance-covariance matrix G, where some parameters are estimated close to 
> zero, and related confidence intervals are incredibly large.
> 
> Since simplification of the random portion is not an option, for both 
> interest in the parameters and significant increase in the model fit, I 
> would like to collect "unbiased" random effects estimates.
> 
> I used bootstrap to this purpose, creating a linear model for each cluster 
> and bootstraping the variance of the coefficients. Is this procedure 
> reasonable? Would it be reasonable in this case to keep the marginal portion 
> of the mixed model?
> Note that in presence of positive-definite G matrix this bootstrap approach 
> and the mixed effect model give highly similar estimates and that in the non 
> positive-definite model the bootstrap and mixed model marginal-model 
> estimates are highly similar as well.
> 
> Thank you
> Bruno
> 
> __
> 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

__
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


[R] party - ctree() - terminal nodes reference for every obs

2006-07-14 Thread Daniele Medri
Dear R.Users,

using ctree() (from "party" library) on a data.frame, I want to append a
column with the references for the groups/segments detected. While these
nodes are easy readable in output, I need a vector for my obs.

Hints?


Cheers
-- 
Daniele Medri

__
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


[R] Generate object names from variables

2006-07-14 Thread Georg Otto
Hi,

I want to generate object names out of variables in a sort of variable
substitution.

first i generate some vectors and an empty list:

> vector.a<-c("a","b")
> vector.b<-c("c","d")
> vector.c<-c("e","f")
> vectors<-c("vector.a", "vector.b", "vector.c")
> vectors
[1] "vector.a" "vector.b" "vector.c"

> vectorlist<-list()

What I would then like to do is to generate elements of the list by
using variables, somehow like this (does not work):

>for (i in vectors) {
+ list$i<-i
+ }

To end up with a list like this:

> list
$vector.a
 [1] "a" "b"
$vector.b
 [1] "c" "d"
$vector.c
 [1] "e" "f"


Any hint will be appreciated.

Cheers,

Georg

__
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


Re: [R] Generate object names from variables

2006-07-14 Thread Gabor Grothendieck
Try this:

sapply(vectors, get, simplify = FALSE)

or

lapply(vectors, get)

although the last one does not give you the names.

On 7/14/06, Georg Otto <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I want to generate object names out of variables in a sort of variable
> substitution.
>
> first i generate some vectors and an empty list:
>
> > vector.a<-c("a","b")
> > vector.b<-c("c","d")
> > vector.c<-c("e","f")
> > vectors<-c("vector.a", "vector.b", "vector.c")
> > vectors
> [1] "vector.a" "vector.b" "vector.c"
>
> > vectorlist<-list()
>
> What I would then like to do is to generate elements of the list by
> using variables, somehow like this (does not work):
>
> >for (i in vectors) {
> + list$i<-i
> + }
>
> To end up with a list like this:
>
> > list
> $vector.a
>  [1] "a" "b"
> $vector.b
>  [1] "c" "d"
> $vector.c
>  [1] "e" "f"
>
>
> Any hint will be appreciated.
>
> Cheers,
>
> Georg
>
> __
> 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
>

__
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


Re: [R] Generate object names from variables

2006-07-14 Thread Marc Schwartz (via MN)
On Fri, 2006-07-14 at 16:57 +0200, Georg Otto wrote:
> Hi,
> 
> I want to generate object names out of variables in a sort of variable
> substitution.
> 
> first i generate some vectors and an empty list:
> 
> > vector.a<-c("a","b")
> > vector.b<-c("c","d")
> > vector.c<-c("e","f")
> > vectors<-c("vector.a", "vector.b", "vector.c")
> > vectors
> [1] "vector.a" "vector.b" "vector.c"
> 
> > vectorlist<-list()
> 
> What I would then like to do is to generate elements of the list by
> using variables, somehow like this (does not work):
> 
> >for (i in vectors) {
> + list$i<-i
> + }
> 
> To end up with a list like this:
> 
> > list
> $vector.a
>  [1] "a" "b"
> $vector.b
>  [1] "c" "d"
> $vector.c
>  [1] "e" "f"
> 
> 
> Any hint will be appreciated.
> 
> Cheers,
> 
> Georg

Presuming that your vectors fit a naming pattern of "vector.x":

# Use grep() to get the vector names from ls()
> vectors <- grep("vector[\.]", ls(), value = TRUE)

> vectors
[1] "vector.a" "vector.b" "vector.c"

# Use sapply to create the list
> sapply(vectors, get, simplify = FALSE)
$vector.a
[1] "a" "b"

$vector.b
[1] "c" "d"

$vector.c
[1] "e" "f"


HTH,

Marc Schwartz

__
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


[R] Help for updating package

2006-07-14 Thread Ivan Kalafatic
I have a problem with garchFit fuction in fSeries package. I found the
following reply on one of the R list:
"GARCH-Modelling is not easy, and indeed for your dataset the default
"Sequential Quadratic Programming" solver doesn't converge. I observed
this also for some other time series. There is already an updated
version on the server,
https://svn.r-project.org/Rmetrics/trunk/fSeries/
which uses improved control parameter settings as default values. With
this version there exist no convergence problems"

How to update my version of fSeries with the provided link?

Thank you.

__
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


Re: [R] Generate object names from variables

2006-07-14 Thread Paul Johnson
I collected some advice about this question a couple of  years ago.
This might help.

http://pj.freefaculty.org/R/Rtips.html#2.1 "Add variables to a data
frame (or list)"
and the next one after that.


On 7/14/06, Marc Schwartz (via MN) <[EMAIL PROTECTED]> wrote:
> On Fri, 2006-07-14 at 16:57 +0200, Georg Otto wrote:
> > Hi,
> >
> > I want to generate object names out of variables in a sort of variable
> > substitution.
> >
> > first i generate some vectors and an empty list:
> >
> > > vector.a<-c("a","b")
> > > vector.b<-c("c","d")
> > > vector.c<-c("e","f")
> > > vectors<-c("vector.a", "vector.b", "vector.c")
> > > vectors
> > [1] "vector.a" "vector.b" "vector.c"
> >
> > > vectorlist<-list()
> >
> > What I would then like to do is to generate elements of the list by
> > using variables, somehow like this (does not work):
> >
> > >for (i in vectors) {
> > + list$i<-i
> > + }
> >
> > To end up with a list like this:
> >
> > > list
> > $vector.a
> >  [1] "a" "b"
> > $vector.b
> >  [1] "c" "d"
> > $vector.c
> >  [1] "e" "f"
> >
> >
> > Any hint will be appreciated.
> >
> > Cheers,
> >
> > Georg
>

-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

__
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


[R] Questions about extract-lme.cov

2006-07-14 Thread Li, Hua
Hi, all:

I am using extract.lme.cov to extract the covariance matrix of lme. But
the results are not expected. 

For example, 

 b <- lme(travel~1,Rail,~1|Rail)

The default correlation for lme is no correlation within groups.

>extract.lme.cov(b,Rail)

The part of covariance matrix looks like:

 123456
1 631.4778 615.3111 615.3111   0.   0.   0.
2 615.3111 631.4778 615.3111   0.   0.   0.
3 615.3111 615.3111 631.4778   0.   0.   0.
4   0.   0.   0. 631.4778 615.3111 615.3111
5   0.   0.   0. 615.3111 631.4778 615.3111
6   0.   0.   0. 615.3111 615.3111 631.4778

Where does the covariance come from? Maybe I'm missing sth here?

Thanks,

Hua Li 

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


[R] Quantile Regression Object

2006-07-14 Thread ricardosilva
Hi,

I load my data set and separate it as folowing:

presu <- read.table("C:/_Ricardo/Paty/qtdata_f.txt", header=TRUE, sep="\t",
na.strings="NA", dec=".", strip.white=TRUE)
dep<-presu[,3];
exo<-presu[,4:92];

Now, I want to use it using the wls and quantreg packages. How I change the
data classes for mle and rq objects?

Thanks a lot,
Ricardo

__
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


Re: [R] SAS to R translator for particular procedures

2006-07-14 Thread Mehmet Somel
Dear /Bill Paterson,

while trying to find a way to convert SAS code into R, I came across 
your one time e-mail message 
(http://www.ens.gu.edu.au/robertk/R/help/99b/0908.html). I'd appreciate 
to learn if anything came out of this, or any suggestions.

Thank you in advance,

Mehmet Somel
/

-- 
Mehmet Somel
Max Planck Institute for Evolutionary Anthropology
Department of Evolutionary Genetics
Deutscher Platz 6, D-04103 Leipzig

Tel: +49-(0)341-3550-530
Fax: +49-(0)341-3550-555
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


[R] Error in Quantile Regression - Clear Message

2006-07-14 Thread ricardosilva
Dear Users,
I loaded my dataset as following:

presu <- read.table("C:/_Ricardo/Paty/qtdata_f.txt", header=TRUE, sep="\t",
na.strings="NA", dec=".", strip.white=TRUE)
dep<-presu[,3];
exo<-presu[,4:92];

When I try:

rq(dep ~ exo, ...) or mle.stepwise(dep ~ exo, ...)
I got the same error:
> rq(dep ~ exo)
Error in model.frame(formula, rownames, variables, varnames, extras,
extranames,  :
invalid variable type for 'exo'

Any hint in how to fix it? I think this is due my data format.

Thanks,


Ricardo Gonçalves Silva, M. Sc.
Apoio aos Processos de Modelagem Matemática
Econometria & Inadimplência
Serasa S.A.
(11) - 6847-8889
[EMAIL PROTECTED]

__


Hi,

I load my data set and separate it as folowing:

presu <- read.table("C:/_Ricardo/Paty/qtdata_f.txt", header=TRUE, sep="\t",
na.strings="NA", dec=".", strip.white=TRUE)
dep<-presu[,3];
exo<-presu[,4:92];

Now, I want to use it using the wls and quantreg packages. How I change the
data classes for mle and rq objects?

Thanks a lot,
Ricardo

__
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

__
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


[R] Competings risks

2006-07-14 Thread klaus . langohr
Hello!
Is there any possibility in R to carry out competing risks analysis with left-
truncated data (late entries)?

Thanks a lot for any help!!

Klaus.

__
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


[R] Listing all of combinations

2006-07-14 Thread miao
Dear All:

I want to list all of combination among (a,b,c,d,e,f,g,h). I try to use 
lp<-ist(A=c(a,b,c,d,e,f,g,h),B=(a,b,c,d,e,f,g,h)etc.).and then use 
expand.grid(p). this does not work for the same vector A,B...

Anyone had this experince?


   Thanks!

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


[R] [R-pkgs] New R-Packages: Triangle and LHS

2006-07-14 Thread Carnell, Rob C
Two new packages have been added to CRAN.  

The first is a simple package which provides the standard functions for
a triangle distribution (rtriangle, dtriangle, ptriangle, qtriangle).  

The second package generates and augments Latin Hypercube Samples.
Functions for generating random and optimized designs are provided.

I look forward hearing your feedback and improving the documentation!
 

Rob Carnell

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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


[R] [R-pkgs] glmmML updated

2006-07-14 Thread Göran Broström
I have uploaded a new version (0.30-2) of glmmML to CRAN today.

This is a rather extensive upgrade, mostly internal. Adaptive
Gauss-Hermite quadrature (GHQ) is now used for the evaluation of the
integrals in the log likelihood function. The user can choose the number
of points (default is 16), I _think_ that choosing 1 point will result
in a Laplace approximation. The integrals in the score and hessian
are evaluated by the QUADPACK function 'Rdqagi' which is the C code
behind the R function 'integrate'. This specific combination of the two
methods seems to work best. (I often get _exactly_ (up to seven digits)
the same value with the two methods, but in some extreme cases one may
fail and not the other.)

New components in the output from 'glmmML' are 'posterior.means' and
posterior.modes'. The modes are found by using 'vmmin' (behind R's
'optim') on the integrands in the GHQ, the means by numerical
integration. Usually, they do not differ much.

A special problem is situations where the random effects variance is
very small or zero. I may happen that glmmML is unable to get the
likelihood value above the value given by 'glm' on the corresponding
model with no clustering. In such a case zero variance is reported, with
a standard error that is NA. A warning is also given. If a test of the
hypothesis that sigma = 0 is on the wish list, a p-value can be
estimated by bootstrapping, see the input parameter 'boot'. The only
option now is a parametric bootstrap; I have removed the 'conditional'
approach.

As usual, comments, and error and bug reports are welcome.

Göran

-- 
Göran Broström

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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

Re: [R] Help for updating package

2006-07-14 Thread Kerpel, John
Ivan:

I'm guessing you've got the latest version of fSeries if you downloaded
it recently from CRAN.

I've noticed the convergence problems too.  I changed to
algorithm="lbfgsb" and haven't had a problem since.  (I'm running
Windows XP and R 2.3.1)

John

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ivan Kalafatic
Sent: Friday, July 14, 2006 10:26 AM
To: r-help@stat.math.ethz.ch; [EMAIL PROTECTED]
Subject: [R] Help for updating package

I have a problem with garchFit fuction in fSeries package. I found the
following reply on one of the R list:
"GARCH-Modelling is not easy, and indeed for your dataset the default
"Sequential Quadratic Programming" solver doesn't converge. I observed
this also for some other time series. There is already an updated
version on the server,
https://svn.r-project.org/Rmetrics/trunk/fSeries/
which uses improved control parameter settings as default values. With
this version there exist no convergence problems"

How to update my version of fSeries with the provided link?

Thank you.

__
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

__
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


Re: [R] SAS to R translator for particular procedures

2006-07-14 Thread Marc Schwartz (via MN)
On Fri, 2006-07-14 at 18:35 +0200, Mehmet Somel wrote:
> Dear /Bill Paterson,
> 
> while trying to find a way to convert SAS code into R, I came across 
> your one time e-mail message 
> (http://www.ens.gu.edu.au/robertk/R/help/99b/0908.html). I'd appreciate 
> to learn if anything came out of this, or any suggestions.
> 
> Thank you in advance,
> 
> Mehmet Somel
> /

There was this post back in 2004:

https://stat.ethz.ch/pipermail/r-help/2004-April/048750.html

HTH,

Marc Schwartz

N.B. Pay attention to the date...  :-)

__
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


Re: [R] Listing all of combinations

2006-07-14 Thread Muhammad Subianto
On this day 14/07/2006 15:35, miao wrote:
> Dear All:
>
> I want to list all of combination among (a,b,c,d,e,f,g,h). I try to use 
> lp<-ist(A=c(a,b,c,d,e,f,g,h),B=(a,b,c,d,e,f,g,h)etc.).and then use 
> expand.grid(p). this does not work for the same vector A,B...
>
> Anyone had this experince?
>
>
>Thanks!
>
>Xin
>   [[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
>

Try this below:

A <- letters[1:8]
B <- letters[1:8]
lp<-list(A,B)
expand.grid(lp)

Best, Muhammad Subianto

__
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


[R] Optim()

2006-07-14 Thread Iris Zhao
Dear all,



I have two functions (f1, f2) and 4 unknown parameters (p1, p2, p3, p4). Both
f1 and f2 are functions of p1, p2, and p3, denoted by f1(p1, p2, p3) and
f2(p1,p2,p3) respectively.



The goal is to maximize f1(p1, p2, p3) subject to two constraints:

(1)  c = k1*p4/(k1*p4+(1-k1)*f1(p1,p2,p3)), where c and k1 are some known
constants

(2)  p4 = f2(p1, p2, p3)

In addition, each parameter ranges from 0 to 1, and both f1 and f2 involve
integrations.



I tried to use lagrange multipliers to eliminate two equality constraints
and then use optim() to find the maximum value and optimal parameter
estimates.

So I let fn be f1+lambda1*(c- k1*p4/(k1*p4+(1-k1)*f1(p1,p2,p3))) +
lambda2(p4-f2(p1,p2,p3)). The error message I got was "Error in fn(par, ...)
: recursive default argument reference."



I wonder whether current build-in functions in R can do this type of jobs.
Any suggestion will be greatly appreciated.



Iris

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


Re: [R] [Rd] R as shell script

2006-07-14 Thread François Pinard
[Juha Vierinen]
>Hi,

Hello, Juha.  Your request, quoted below, is likely more appropriate for
R help than for R devel, so I'm redirecting this reply there.

>I am considering if I should invest in learning R. Based on the
>language definition and introductory documents, it seems nice. But now
>I am faced with a problem: I want to be able to run R programs easily
>from the unix shell, and write scripts that can automatically select R
>as the interpreter:

>#!/usr/bin/R
>cat("Hello world.\n")

>This of course doesn't work, because /usr/bin/R is a shell script.

>I have been able to create a binary wrapper that calls R with the
>correct arguments, which is documented here:

>http://kavaro.fi/mediawiki/index.php/Using_R_from_the_shell

>This still lacks eg. standard input (but I have no idea how I can
>implement it in R) and full command line argument passing (can be
>done), but am I on the right track, or is there already something that
>does what I need?

I'm often using something like:

   #!/bin/sh
   R --slave --vanilla 

Re: [R] looping using combinatorics

2006-07-14 Thread Jesse Albert Canchola
Many thanks, Gabor.  This is very close to what would be ideal.  You gave 
me an idea as follows:

Rather than combine pairs of data vectors/frames AFTER the "combn" 
function, combine all data before (though I belive this would be less 
efficient) and add an index then use that index to choose your pairs (or 
whatever combinatorics you are using; e.g., 8 choose 4  so all 
combinations of 4 out of 8 for a total of 70 combinations.)

Example data frames with variable names:

Data frame "a" where I add an "index":
id measure index
1  1.1  1
2  1.2  1
3  1.3  1

Data frame "b" where I add an "index":
id measure index
4  2.1  2
5  2.2  2
6  2.3  2

Data frame "c" where I add an index:
id measure index
7  3.1  3
8  3.2  3
9  3.3  3

If we combine all these data at once using rbind, we get:
id measure index
1  1.1  1
2  1.2  1
3  1.3  1
4  2.1  2
5  2.2  2
6  2.3  2
7  3.1  3
8  3.2  3
9  3.3  3

We can then use something similar to your code and the index to choose the 
required pairs as derived from the "combn" function. 
For example, the "combn" function will choose the data pairs
(1,2)
(1,3)
(2,3)

where, for example, the pairs (1,2) will have data from frames "a" and 
"b":
1  1.1  1
2  1.2  1
3  1.3  1
4  2.1  2
5  2.2  2
6  2.3  2

so that we can go down the list subsetting what we need and doing 
operations on each combined pair as we go. 

Is there an easy way in R to do this operation?

For the above, an attempt might be:

## STAB CODE #
DF <- rbind(a,b,c)
DF
for(index in as.data.frame(combn(3,2))) print(DF[,index])
 END STAB CODE ##

but this is choosing 3 choose 2 COLUMNS within the combined file rather 
than 3 choose 2 ROWS.


Best regards and TIAA,
Jesse 





"Gabor Grothendieck" <[EMAIL PROTECTED]> 
07/13/2006 07:39 PM

To
"Jesse Albert Canchola" <[EMAIL PROTECTED]>
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] looping using combinatorics






I assume your question is given 3 vectors of the same length: a, b and c
how do we loop over pairs of them.  In the following each iteration 
displays
one pair:

   library(combinat)
   DF <- data.frame(a = 1:4, b = 5:8, c = 9:12)
   for(idx in as.data.frame(combn(3,2))) print(DF[,idx])

On 7/13/06, Jesse Albert Canchola <[EMAIL PROTECTED]> wrote:
> I have a problem where I need to loop over the total combinations of
> vectors (combined once chosen via combinatorics).  Here is a
> simplification of the problem:
>
> STEP 1:  Define three vectors a, b, c.
> STEP 2:  Combine all possible pairwise vectors (i.e., 3 choose 2 = 3
> possible pairs of vectors: ab,ac, bc)
> NOTE:  the actual problem has 8 choose 4, 8 choose 5 and 8 choose 6
> combinations.
> STEP 3:  Do the same math on each pairwise combination and spit out
> answers each time
>
> ### BEGIN CODE ###
> #STEP 1
> a1 <- c(1,2,3,4,5,6,7,8,9,10,11,12)
> a <- matrix(a1,2,3,byrow=T)
> a
>
> b1 <- c(13,14,15,16,17,18,19,20,21,22,23,24)
> b <- matrix(b1,2,3,byrow=T)
> b
>
> c1 <- c(25,26,27,28,29,30,31,32,33,34,35,36)
> c <- matrix(b1,2,3,byrow=T)
> c
>
> # example:  combine the first two vectors "a" and "b"
> combab <- rbind(a,b)
>
> # the a,b combined data from the algorithm later below should look like
> # something like the following:
> combab
>
> # use the combinatorics "combn" function found in the "combinat" package
> on CRAN
> m <- combn(3,2) # three choose two combinations
> m
>
> # the first assignment below should be numeric and then subsequent
> # assignments as character since the first time you assign a number to
> # a character in a matrix the rest of the numbers in the matrix are
> coerced to character
> m[m==1]='a'; m[m=='2']='b'; m[m=='3']='c'
> m
>
> #STEP 2: combine pairwise vectors into a matrix or frame
> for (i in dim(m)[1])
>for (j in dim(m)[2])
>{
>combined <-
> rbind(cat(format(m[i]),"\n"),cat(format(m[j]),"\n")) #cat/format removes
> the quotes
>combined
>}
> traceback()
>
>
> #STEP 3: {not there yet}
> # END CODE 
>
> The problem is that in STEP 2 (not complete), the results in the rbind 
are
> not recognized as the objects they represent (i.e., the "a" without 
quotes
> is not recognized as the data object we defined in STEP 1.  Perhaps this
> is a parsing problem.  Perhaps there is an alterative way to do this.  I
> looked pretty long and hard in the CRAN libraries but alas, I am stuck.
> BTW, I picked up R about a month ago (I used primarily SAS, Stata and
> SPSS).
>
> Regards and TIA,
> Jesse
>
>
>
>
>
>
> Jesse A. Canchola
> Biostatistician III
> Bayer Healthcare
> 725 Potter St.
> Berkeley, CA 94710
> P: 510.705.5855
> F: 510.705.5718
> E: [EMAIL PROTECTED]
>
>
>
>
> 
___
>
> The information contained in this e-mail is for the exclusive use of the 
intended recipient(s) and may be confidential, proprietary, and/or legally 
privileged.  Inadvertent disclosure of this message do

[R] Recreate new dataframe based on condition

2006-07-14 Thread Sachin J
Hi,
   
  How can I achieve this in R. Dataset is as follows:
   
  >df
x
1 2
2 4
3 1
4 3
5 3
6 2

  structure(list(x = c(2, 4, 1, 3, 3, 2)), .Names = "x", row.names = c("1", 
"2", "3", "4", "5", "6"), class = "data.frame")

  I want to recreate a new data frame whose rows are sum of (1&2, 3&4, 5&6) of 
original df. For example
   
  >newdf
 x 
  1 6
  2 4
  3 5
   
  Thanx in advance for the help.
   
  Sachin
   


-

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


Re: [R] looping using combinatorics

2006-07-14 Thread Gabor Grothendieck
Use data.frame, not rbind, e.g. DF <- data.frame(a, b, c)

On 7/14/06, Jesse Albert Canchola <[EMAIL PROTECTED]> wrote:
> Many thanks, Gabor.  This is very close to what would be ideal.  You gave
> me an idea as follows:
>
> Rather than combine pairs of data vectors/frames AFTER the "combn"
> function, combine all data before (though I belive this would be less
> efficient) and add an index then use that index to choose your pairs (or
> whatever combinatorics you are using; e.g., 8 choose 4  so all
> combinations of 4 out of 8 for a total of 70 combinations.)
>
> Example data frames with variable names:
>
> Data frame "a" where I add an "index":
> id measure index
> 1  1.1  1
> 2  1.2  1
> 3  1.3  1
>
> Data frame "b" where I add an "index":
> id measure index
> 4  2.1  2
> 5  2.2  2
> 6  2.3  2
>
> Data frame "c" where I add an index:
> id measure index
> 7  3.1  3
> 8  3.2  3
> 9  3.3  3
>
> If we combine all these data at once using rbind, we get:
> id measure index
> 1  1.1  1
> 2  1.2  1
> 3  1.3  1
> 4  2.1  2
> 5  2.2  2
> 6  2.3  2
> 7  3.1  3
> 8  3.2  3
> 9  3.3  3
>
> We can then use something similar to your code and the index to choose the
> required pairs as derived from the "combn" function.
> For example, the "combn" function will choose the data pairs
> (1,2)
> (1,3)
> (2,3)
>
> where, for example, the pairs (1,2) will have data from frames "a" and
> "b":
> 1  1.1  1
> 2  1.2  1
> 3  1.3  1
> 4  2.1  2
> 5  2.2  2
> 6  2.3  2
>
> so that we can go down the list subsetting what we need and doing
> operations on each combined pair as we go.
>
> Is there an easy way in R to do this operation?
>
> For the above, an attempt might be:
>
> ## STAB CODE #
> DF <- rbind(a,b,c)
> DF
> for(index in as.data.frame(combn(3,2))) print(DF[,index])
>  END STAB CODE ##
>
> but this is choosing 3 choose 2 COLUMNS within the combined file rather
> than 3 choose 2 ROWS.
>
>
> Best regards and TIAA,
> Jesse
>
>
>
>
>
> "Gabor Grothendieck" <[EMAIL PROTECTED]>
> 07/13/2006 07:39 PM
>
> To
> "Jesse Albert Canchola" <[EMAIL PROTECTED]>
> cc
> r-help@stat.math.ethz.ch
> Subject
> Re: [R] looping using combinatorics
>
>
>
>
>
>
> I assume your question is given 3 vectors of the same length: a, b and c
> how do we loop over pairs of them.  In the following each iteration
> displays
> one pair:
>
>   library(combinat)
>   DF <- data.frame(a = 1:4, b = 5:8, c = 9:12)
>   for(idx in as.data.frame(combn(3,2))) print(DF[,idx])
>
> On 7/13/06, Jesse Albert Canchola <[EMAIL PROTECTED]> wrote:
> > I have a problem where I need to loop over the total combinations of
> > vectors (combined once chosen via combinatorics).  Here is a
> > simplification of the problem:
> >
> > STEP 1:  Define three vectors a, b, c.
> > STEP 2:  Combine all possible pairwise vectors (i.e., 3 choose 2 = 3
> > possible pairs of vectors: ab,ac, bc)
> > NOTE:  the actual problem has 8 choose 4, 8 choose 5 and 8 choose 6
> > combinations.
> > STEP 3:  Do the same math on each pairwise combination and spit out
> > answers each time
> >
> > ### BEGIN CODE ###
> > #STEP 1
> > a1 <- c(1,2,3,4,5,6,7,8,9,10,11,12)
> > a <- matrix(a1,2,3,byrow=T)
> > a
> >
> > b1 <- c(13,14,15,16,17,18,19,20,21,22,23,24)
> > b <- matrix(b1,2,3,byrow=T)
> > b
> >
> > c1 <- c(25,26,27,28,29,30,31,32,33,34,35,36)
> > c <- matrix(b1,2,3,byrow=T)
> > c
> >
> > # example:  combine the first two vectors "a" and "b"
> > combab <- rbind(a,b)
> >
> > # the a,b combined data from the algorithm later below should look like
> > # something like the following:
> > combab
> >
> > # use the combinatorics "combn" function found in the "combinat" package
> > on CRAN
> > m <- combn(3,2) # three choose two combinations
> > m
> >
> > # the first assignment below should be numeric and then subsequent
> > # assignments as character since the first time you assign a number to
> > # a character in a matrix the rest of the numbers in the matrix are
> > coerced to character
> > m[m==1]='a'; m[m=='2']='b'; m[m=='3']='c'
> > m
> >
> > #STEP 2: combine pairwise vectors into a matrix or frame
> > for (i in dim(m)[1])
> >for (j in dim(m)[2])
> >{
> >combined <-
> > rbind(cat(format(m[i]),"\n"),cat(format(m[j]),"\n")) #cat/format removes
> > the quotes
> >combined
> >}
> > traceback()
> >
> >
> > #STEP 3: {not there yet}
> > # END CODE 
> >
> > The problem is that in STEP 2 (not complete), the results in the rbind
> are
> > not recognized as the objects they represent (i.e., the "a" without
> quotes
> > is not recognized as the data object we defined in STEP 1.  Perhaps this
> > is a parsing problem.  Perhaps there is an alterative way to do this.  I
> > looked pretty long and hard in the CRAN libraries but alas, I am stuck.
> > BTW, I picked up R about a month ago (I used primarily SAS, Stata and
> > SPSS).
> >
> > Regards and TIA,
> > Jesse
> >
> >
> >
> >
> >
> >
> > Jesse A. Canchola
> > Biostat

Re: [R] Recreate new dataframe based on condition

2006-07-14 Thread jim holtman
> x <- "   x
+ 1 2
+ 2 4
+ 3 1
+ 4 3
+ 5 3
+ 6 2
+ "
> x <- read.table(textConnection(x), header=TRUE)
> data.frame(sum=tapply(x$x, rep(1:(nrow(x) / 2), each=2), sum))
  sum
1   6
2   4
3   5


On 7/14/06, Sachin J <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> How can I achieve this in R. Dataset is as follows:
>
> >df
>x
> 1 2
> 2 4
> 3 1
> 4 3
> 5 3
> 6 2
>
> structure(list(x = c(2, 4, 1, 3, 3, 2)), .Names = "x", row.names = c("1",
> "2", "3", "4", "5", "6"), class = "data.frame")
>
> I want to recreate a new data frame whose rows are sum of (1&2, 3&4, 5&6)
> of original df. For example
>
> >newdf
> x
> 1 6
> 2 4
> 3 5
>
> Thanx in advance for the help.
>
> Sachin
>
>
>
> -
>
>[[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
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390 (Cell)
+1 513 247 0281 (Home)

What is the problem you are trying to solve?

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


Re: [R] Recreate new dataframe based on condition

2006-07-14 Thread Gabor Grothendieck
Try this using DF since df is the name of an R function:

# test data from post
DF <-  structure(list(x = c(2, 4, 1, 3, 3, 2)), .Names = "x", row.names = c("1",
 "2", "3", "4", "5", "6"), class = "data.frame")


rowsum(DF, gl(nrow(DF),2,nrow(DF)))


On 7/14/06, Sachin J <[EMAIL PROTECTED]> wrote:
> Hi,
>
>  How can I achieve this in R. Dataset is as follows:
>
>  >df
>x
> 1 2
> 2 4
> 3 1
> 4 3
> 5 3
> 6 2
>
>  structure(list(x = c(2, 4, 1, 3, 3, 2)), .Names = "x", row.names = c("1",
> "2", "3", "4", "5", "6"), class = "data.frame")
>
>  I want to recreate a new data frame whose rows are sum of (1&2, 3&4, 5&6) of 
> original df. For example
>
>  >newdf
> x
>  1 6
>  2 4
>  3 5
>
>  Thanx in advance for the help.
>
>  Sachin
>
>
>
> -
>
>[[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
>

__
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


[R] EOF: object needs to be "field"?

2006-07-14 Thread Jih-Wang \(Aaron\) Wang
Hi, All:

I am using Chinese version of R, but I will translate the error message.

I have been trying to find out the spatial pattern of some meteorology 
variable. I converted the data from "grib" format to binary, which is not a big 
deal. Then I read in the binary data, and it has 3 dimensions: x, y, and time. 
The following is my code

-
nx <- 349
ny <- 277
nt <- 312
nRunning <- 12
missing <- -900.
datain <- 
readBin("PWAT-mon.197901-200412.dat",what=numeric(),n=nx*ny*nt,size=4,endian="little")
datain[datainhttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Splitting the left and right hand terms of a formula

2006-07-14 Thread Daniel Gerlanc
Let's say I have the following formula:

a.formula <- x ~ y + z

I want to extract the left and right-hand sides of the function so
that I have two character vectors like the ones you would create using
the following assignments:

left.hand.side <- "x"
right.hand.side <- c("y", "z")

One way to do this follows:

left.hand.side <- unlist(dimnames(attr(terms(a.formula), "factors"))[1])
right.hand.side <- unlist(dimnames(attr(terms(a.formula), "factors"))[-1])

Is there a better or cleaner way to do this?

Thanks!

Daniel Gerlanc
Williams College '07

__
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


Re: [R] Splitting the left and right hand terms of a formula

2006-07-14 Thread Gabor Grothendieck
Try this:

> all.vars(update(a.formula, .~0))
[1] "x"

> all.vars(update(a.formula, 0~.))
[1] "y" "z"

On 7/14/06, Daniel Gerlanc <[EMAIL PROTECTED]> wrote:
> Let's say I have the following formula:
>
> a.formula <- x ~ y + z
>
> I want to extract the left and right-hand sides of the function so
> that I have two character vectors like the ones you would create using
> the following assignments:
>
> left.hand.side <- "x"
> right.hand.side <- c("y", "z")
>
> One way to do this follows:
>
> left.hand.side <- unlist(dimnames(attr(terms(a.formula), "factors"))[1])
> right.hand.side <- unlist(dimnames(attr(terms(a.formula), "factors"))[-1])
>
> Is there a better or cleaner way to do this?
>
> Thanks!
>
> Daniel Gerlanc
> Williams College '07
>
> __
> 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
>

__
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


Re: [R] looping using combinatorics

2006-07-14 Thread Jesse Albert Canchola
Thanks.  It is actually the rows I want to choose from, not the columns 
(the columns will remain the same with the same names). A slighly 
abbreviated and modifed example:

data frame "a" has
ID  meas index
1   1.1  1
2   2.1  1

data frame "b" has
ID meas index
3  1.2  2
4  2.2  2

data frame "c" has
ID meas index
5 1.3  3
6 1.4  3

rbind the three frames "a", "b", and "c" into "d":
ID  meas  index
1   1.1  1
2   2.1  1
3   1.2   2
4   2.2   2
5  1.3   3 
6  1.4   3

The three (3 choose 2) pairs we want will be as follows.
Using "combn" from the "combinat" package on CRAN, we get the pairs (1,2), 
(1,3), (2,3) which can be used as the index in the "for" loop (as you have 
used below):
In this case, the pairs (1,2) refer to the actual subset of the data frame 
"d", above, where the actual variable named index=1 or index=2 (and so on 
for the other pairs). 

So the firstly chosen pair would be (1,2) and the resulting subset of the 
data frame "d" looks like this:
ID  meas  index
1   1.1  1
2   2.1  1
3   1.2   2
4   2.2   2

and so on for the other pairs.  So the "rbind" is correct it is the "for" 
loop that needs to be modified to grab the subsets from the DF frame below 
(i.e., the (1,2) pair selected by the combn function will select data from 
DF where the actual variable index=1 or index=2 ; using the example 
above).

 BEGIN CODE 
DF <- rbind(a,b,c)
DF
for(index in as.data.frame(combn(3,2))) print(DF[,index])
 END CODE 



Regards,
Jesse








"Gabor Grothendieck" <[EMAIL PROTECTED]> 
07/14/2006 11:01 AM

To
"Jesse Albert Canchola" <[EMAIL PROTECTED]>
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] looping using combinatorics






Use data.frame, not rbind, e.g. DF <- data.frame(a, b, c)

On 7/14/06, Jesse Albert Canchola <[EMAIL PROTECTED]> wrote:
> Many thanks, Gabor.  This is very close to what would be ideal.  You 
gave
> me an idea as follows:
>
> Rather than combine pairs of data vectors/frames AFTER the "combn"
> function, combine all data before (though I belive this would be less
> efficient) and add an index then use that index to choose your pairs (or
> whatever combinatorics you are using; e.g., 8 choose 4  so all
> combinations of 4 out of 8 for a total of 70 combinations.)
>
> Example data frames with variable names:
>
> Data frame "a" where I add an "index":
> id measure index
> 1  1.1  1
> 2  1.2  1
> 3  1.3  1
>
> Data frame "b" where I add an "index":
> id measure index
> 4  2.1  2
> 5  2.2  2
> 6  2.3  2
>
> Data frame "c" where I add an index:
> id measure index
> 7  3.1  3
> 8  3.2  3
> 9  3.3  3
>
> If we combine all these data at once using rbind, we get:
> id measure index
> 1  1.1  1
> 2  1.2  1
> 3  1.3  1
> 4  2.1  2
> 5  2.2  2
> 6  2.3  2
> 7  3.1  3
> 8  3.2  3
> 9  3.3  3
>
> We can then use something similar to your code and the index to choose 
the
> required pairs as derived from the "combn" function.
> For example, the "combn" function will choose the data pairs
> (1,2)
> (1,3)
> (2,3)
>
> where, for example, the pairs (1,2) will have data from frames "a" and
> "b":
> 1  1.1  1
> 2  1.2  1
> 3  1.3  1
> 4  2.1  2
> 5  2.2  2
> 6  2.3  2
>
> so that we can go down the list subsetting what we need and doing
> operations on each combined pair as we go.
>
> Is there an easy way in R to do this operation?
>
> For the above, an attempt might be:
>
> ## STAB CODE #
> DF <- rbind(a,b,c)
> DF
> for(index in as.data.frame(combn(3,2))) print(DF[,index])
>  END STAB CODE ##
>
> but this is choosing 3 choose 2 COLUMNS within the combined file rather
> than 3 choose 2 ROWS.
>
>
> Best regards and TIAA,
> Jesse
>
>
>
>
>
> "Gabor Grothendieck" <[EMAIL PROTECTED]>
> 07/13/2006 07:39 PM
>
> To
> "Jesse Albert Canchola" <[EMAIL PROTECTED]>
> cc
> r-help@stat.math.ethz.ch
> Subject
> Re: [R] looping using combinatorics
>
>
>
>
>
>
> I assume your question is given 3 vectors of the same length: a, b and c
> how do we loop over pairs of them.  In the following each iteration
> displays
> one pair:
>
>   library(combinat)
>   DF <- data.frame(a = 1:4, b = 5:8, c = 9:12)
>   for(idx in as.data.frame(combn(3,2))) print(DF[,idx])
>
> On 7/13/06, Jesse Albert Canchola <[EMAIL PROTECTED]> wrote:
> > I have a problem where I need to loop over the total combinations of
> > vectors (combined once chosen via combinatorics).  Here is a
> > simplification of the problem:
> >
> > STEP 1:  Define three vectors a, b, c.
> > STEP 2:  Combine all possible pairwise vectors (i.e., 3 choose 2 = 3
> > possible pairs of vectors: ab,ac, bc)
> > NOTE:  the actual problem has 8 choose 4, 8 choose 5 and 8 choose 6
> > combinations.
> > STEP 3:  Do the same math on each pairwise combination and spit out
> > answers each time
> >
> > ### BEGIN CODE ###
> > #STEP 1
> > a1 <- c(1,2,3,4,5,6,7,8,9,10,11,12)
> > a <- matrix(a1,2,3,byrow=T)
> > a
> >
> > b1 <- c(13,14,15,16,17,18,19,20,21,22,23,24)
> > b <- matrix(b1,2,3,byrow=T)
> > b
> >
> > c1 <- c(25,26,27,28,29,30,

[R] optim()

2006-07-14 Thread Iris Zhao
Dear all,



I am working on optimization problem and have some trouble running optim().
I have two functions (f1, f2) and 4 unknown parameters (p1, p2, p3, p4).
Both f1 and f2 are functions of p1, p2, and p3, denoted by f1(p1, p2, p3)
and f2(p1,p2,p3) respectively.



The goal is to maximize f1(p1, p2, p3) subject to two constraints:

(1)  c = k1*p4/(k1*p4+(1-k1)*f1(p1,p2,p3)), where c and k1 are some known
constants

(2)  p4 = f2(p1, p2, p3)

In addition, each parameter ranges from 0 to 1, and both f1 and f2 involve
integrations.



I tried to use lagrange multipliers to eliminate two equality constraints
and then use optim() to find the maximum value and optimal parameter
estimates.

So I let fn be f1+lambda1*(c- k1*p4/(k1*p4+(1-k1)*f1(p1,p2,p3))) +
lambda2(p4-f2(p1,p2,p3)). The error message I got was "Error in fn(par, ...)
: recursive default argument reference."



I wonder whether current build-in functions in R can do this type of jobs.
Any suggestion will be greatly appreciated.



Iris

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


Re: [R] looping using combinatorics

2006-07-14 Thread Gabor Grothendieck
If a, b and c are numeric vectors then rbind(a,b,c) and cbind(a,b,c) produce
matrices, not data frames and iterating over a matrix in a for loop iterates
over the elements of the matrix whereas iterating over a data frame in
a for loop iterates over the columns.  You can use as.data.frame(my.matrix)
to convert a matrix to a data frame.

Compare:

> for(i in matrix(1:4,2)) print(i)
[1] 1
[1] 2
[1] 3
[1] 4
> for(i in as.data.frame(matrix(1:4,2))) print(i)
[1] 1 2
[1] 3 4



On 7/14/06, Jesse Albert Canchola <[EMAIL PROTECTED]> wrote:
> Thanks.  It is actually the rows I want to choose from, not the columns
> (the columns will remain the same with the same names). A slighly
> abbreviated and modifed example:
>
> data frame "a" has
> ID  meas index
> 1   1.1  1
> 2   2.1  1
>
> data frame "b" has
> ID meas index
> 3  1.2  2
> 4  2.2  2
>
> data frame "c" has
> ID meas index
> 5 1.3  3
> 6 1.4  3
>
> rbind the three frames "a", "b", and "c" into "d":
> ID  meas  index
> 1   1.1  1
> 2   2.1  1
> 3   1.2   2
> 4   2.2   2
> 5  1.3   3
> 6  1.4   3
>
> The three (3 choose 2) pairs we want will be as follows.
> Using "combn" from the "combinat" package on CRAN, we get the pairs (1,2),
> (1,3), (2,3) which can be used as the index in the "for" loop (as you have
> used below):
> In this case, the pairs (1,2) refer to the actual subset of the data frame
> "d", above, where the actual variable named index=1 or index=2 (and so on
> for the other pairs).
>
> So the firstly chosen pair would be (1,2) and the resulting subset of the
> data frame "d" looks like this:
> ID  meas  index
> 1   1.1  1
> 2   2.1  1
> 3   1.2   2
> 4   2.2   2
>
> and so on for the other pairs.  So the "rbind" is correct it is the "for"
> loop that needs to be modified to grab the subsets from the DF frame below
> (i.e., the (1,2) pair selected by the combn function will select data from
> DF where the actual variable index=1 or index=2 ; using the example
> above).
>
>  BEGIN CODE 
> DF <- rbind(a,b,c)
> DF
> for(index in as.data.frame(combn(3,2))) print(DF[,index])
>  END CODE 
>
>
>
> Regards,
> Jesse
>
>
>
>
>
>
>
>
> "Gabor Grothendieck" <[EMAIL PROTECTED]>
> 07/14/2006 11:01 AM
>
> To
> "Jesse Albert Canchola" <[EMAIL PROTECTED]>
> cc
> r-help@stat.math.ethz.ch
> Subject
> Re: [R] looping using combinatorics
>
>
>
>
>
>
> Use data.frame, not rbind, e.g. DF <- data.frame(a, b, c)
>
> On 7/14/06, Jesse Albert Canchola <[EMAIL PROTECTED]> wrote:
> > Many thanks, Gabor.  This is very close to what would be ideal.  You
> gave
> > me an idea as follows:
> >
> > Rather than combine pairs of data vectors/frames AFTER the "combn"
> > function, combine all data before (though I belive this would be less
> > efficient) and add an index then use that index to choose your pairs (or
> > whatever combinatorics you are using; e.g., 8 choose 4  so all
> > combinations of 4 out of 8 for a total of 70 combinations.)
> >
> > Example data frames with variable names:
> >
> > Data frame "a" where I add an "index":
> > id measure index
> > 1  1.1  1
> > 2  1.2  1
> > 3  1.3  1
> >
> > Data frame "b" where I add an "index":
> > id measure index
> > 4  2.1  2
> > 5  2.2  2
> > 6  2.3  2
> >
> > Data frame "c" where I add an index:
> > id measure index
> > 7  3.1  3
> > 8  3.2  3
> > 9  3.3  3
> >
> > If we combine all these data at once using rbind, we get:
> > id measure index
> > 1  1.1  1
> > 2  1.2  1
> > 3  1.3  1
> > 4  2.1  2
> > 5  2.2  2
> > 6  2.3  2
> > 7  3.1  3
> > 8  3.2  3
> > 9  3.3  3
> >
> > We can then use something similar to your code and the index to choose
> the
> > required pairs as derived from the "combn" function.
> > For example, the "combn" function will choose the data pairs
> > (1,2)
> > (1,3)
> > (2,3)
> >
> > where, for example, the pairs (1,2) will have data from frames "a" and
> > "b":
> > 1  1.1  1
> > 2  1.2  1
> > 3  1.3  1
> > 4  2.1  2
> > 5  2.2  2
> > 6  2.3  2
> >
> > so that we can go down the list subsetting what we need and doing
> > operations on each combined pair as we go.
> >
> > Is there an easy way in R to do this operation?
> >
> > For the above, an attempt might be:
> >
> > ## STAB CODE #
> > DF <- rbind(a,b,c)
> > DF
> > for(index in as.data.frame(combn(3,2))) print(DF[,index])
> >  END STAB CODE ##
> >
> > but this is choosing 3 choose 2 COLUMNS within the combined file rather
> > than 3 choose 2 ROWS.
> >
> >
> > Best regards and TIAA,
> > Jesse
> >
> >
> >
> >
> >
> > "Gabor Grothendieck" <[EMAIL PROTECTED]>
> > 07/13/2006 07:39 PM
> >
> > To
> > "Jesse Albert Canchola" <[EMAIL PROTECTED]>
> > cc
> > r-help@stat.math.ethz.ch
> > Subject
> > Re: [R] looping using combinatorics
> >
> >
> >
> >
> >
> >
> > I assume your question is given 3 vectors of the same length: a, b and c
> > how do we loop over pairs of them.  In the following each iteration
> > displays
> > one pair:
> >
> >   library(combinat)
> >   DF <- data.frame(a = 1:4, b = 5:8, c = 9:12)
> >   for(idx i

Re: [R] Keep value lables with data frame manipulation

2006-07-14 Thread Heinz Tuechler
At 11:02 13.07.2006 -0500, Frank E Harrell Jr wrote:
>Heinz Tuechler wrote:
>> At 08:11 13.07.2006 -0500, Frank E Harrell Jr wrote:
>>> Heinz Tuechler wrote:
 At 13:14 12.07.2006 -0500, Marc Schwartz (via MN) wrote:
> On Wed, 2006-07-12 at 17:41 +0100, Jol, Arne wrote:
>> Dear R,
>>
>> I import data from spss into a R data.frame. On this rawdata I do some
>> data processing (selection of observations, normalization, recoding of
>> variables etc..). The result is stored in a new data.frame, however, in
>> this new data.frame the value labels are lost.
>>
>> Example of what I do in code:
>>
>> # read raw data from spss
>> rawdata <- read.spss("./data/T50937.SAV",
>>  use.value.labels=FALSE,to.data.frame=TRUE)
>>
>> # select the observations that we need
>> diarydata <- rawdata[rawdata$D22==2 | rawdata$D22==3 |
rawdata$D22==17 |
>> rawdata$D22==18 | rawdata$D22==20 | rawdata$D22==22 |
>>  rawdata$D22==24 | rawdata$D22==33,]
>>
>> The result is that rawdata$D22 has value labels and that diarydata$D22
>> is numeric without value labels.
>>
>> Question: How can I prevent this from happening?
>>
>> Thanks in advance!
>> Groeten,
>> Arne
> Two things:
>
> 1. With respect to your subsetting, your lengthy code can be replaced
> with the following:
>
>  diarydata <- subset(rawdata, D22 %in% c(2, 3, 17, 18, 20, 22, 24, 33))
>
> See ?subset and ?"%in%" for more information.
>
>
> 2. With respect to keeping the label related attributes, the
> 'value.labels' attribute and the 'variable.labels' attribute will not by
> default survive the use of "[".data.frame in R (see ?Extract
> and ?"[.data.frame").
>
> On the other hand, based upon my review of ?read.spss, the SPSS value
> labels should be converted to the factor levels of the respective
> columns when 'use.value.labels = TRUE' and these would survive a
> subsetting.
>
> If you want to consider a solution to the attribute subsetting issue,
> you might want to review the following post by Gabor Grothendieck in
> May, which provides a possible solution:
>
>  https://stat.ethz.ch/pipermail/r-help/2006-May/106308.html
>
> and this post by me, for an explanation of what is happening in Gabor's
> solution:
>
>  https://stat.ethz.ch/pipermail/r-help/2006-May/106351.html
>
> HTH,
>
> Marc Schwartz
>
 Hello Mark and Arne,

 I worked on the suggestions of Gabor and Mark and programmed some
functions
 in this way, but they are very, very preliminary (see below).
 In my view there is a lack of convenient possibilities in R to document
 empirical data by variable labels, value labels, etc. I would prefer to
 have these possibilities in the "standard" configuration.
 So I sketched a concept, but in my view it would only be useful, if there
 was some acceptance by the core developers of R.

 The concept would be to define a class. For now I call it "source.data".
 To design it more flexible than the Hmisc class "labelled" I would
define a
 related option "source.data.attributes" with default c('value.labels',
 'variable.name', 'label')). This option contains all attributes that
should
 persist in subsetting/indexing.

 I made only some very, very preliminary tests with these functions,
mainly
 because I am not happy with defining a new class. Instead I would prefer,
 if this functionality could be integrated in the Hmisc class "labelled",
 since this is in my view the best known starting point for data
 documentation in R.

 I would be happy, if there were some discussion about the wishes/needs of
 other Rusers concerning data documentation.

 Greetings,

 Heinz
>>> I feel that separating variable labels and value labels and just using 
>>> factors for value labels works fine, and I would urge you not to create 
>>> a new system that will not benefit from the many Hmisc functions that 
>>> use variable labels and units.  [.data.frame in Hmisc keeps all
attributes.
>>>
>>> Frank
>>>
>> 
>> Frank,
>> 
>> of course I aggree with you about the importance of Hmisc and as I said, I
>> do not want to define a new class, but in my view factors are no good
>> substitute for value labels.
>> As the language definition (version 2.3.1 (2006-06-05) Draft, page 7) says:
>> "Factors are currently implemented using an integer array to specify the
>> actual levels and a second array of names that are mapped to the integers.
>> Rather unfortunately users often make use of the implementation in order to
>> make some calculations easier." 
>> So, in my view, the levels represent the "values" of the factor.
>> This has inconveniencies if you want to use value labels in different
>> languages. Further I do not see a simple m

Re: [R] looping using combinatorics

2006-07-14 Thread Jesse Albert Canchola
Great.  I will work on the problem with those definitions in mind. Thanks 
for your help, Gabor.  I'll post the final solution when it is ready.

Best,
Jesse




"Gabor Grothendieck" <[EMAIL PROTECTED]> 
07/14/2006 11:59 AM

To
"Jesse Albert Canchola" <[EMAIL PROTECTED]>
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] looping using combinatorics






If a, b and c are numeric vectors then rbind(a,b,c) and cbind(a,b,c) 
produce
matrices, not data frames and iterating over a matrix in a for loop 
iterates
over the elements of the matrix whereas iterating over a data frame in
a for loop iterates over the columns.  You can use 
as.data.frame(my.matrix)
to convert a matrix to a data frame.

Compare:

> for(i in matrix(1:4,2)) print(i)
[1] 1
[1] 2
[1] 3
[1] 4
> for(i in as.data.frame(matrix(1:4,2))) print(i)
[1] 1 2
[1] 3 4



On 7/14/06, Jesse Albert Canchola <[EMAIL PROTECTED]> wrote:
> Thanks.  It is actually the rows I want to choose from, not the columns
> (the columns will remain the same with the same names). A slighly
> abbreviated and modifed example:
>
> data frame "a" has
> ID  meas index
> 1   1.1  1
> 2   2.1  1
>
> data frame "b" has
> ID meas index
> 3  1.2  2
> 4  2.2  2
>
> data frame "c" has
> ID meas index
> 5 1.3  3
> 6 1.4  3
>
> rbind the three frames "a", "b", and "c" into "d":
> ID  meas  index
> 1   1.1  1
> 2   2.1  1
> 3   1.2   2
> 4   2.2   2
> 5  1.3   3
> 6  1.4   3
>
> The three (3 choose 2) pairs we want will be as follows.
> Using "combn" from the "combinat" package on CRAN, we get the pairs 
(1,2),
> (1,3), (2,3) which can be used as the index in the "for" loop (as you 
have
> used below):
> In this case, the pairs (1,2) refer to the actual subset of the data 
frame
> "d", above, where the actual variable named index=1 or index=2 (and so 
on
> for the other pairs).
>
> So the firstly chosen pair would be (1,2) and the resulting subset of 
the
> data frame "d" looks like this:
> ID  meas  index
> 1   1.1  1
> 2   2.1  1
> 3   1.2   2
> 4   2.2   2
>
> and so on for the other pairs.  So the "rbind" is correct it is the 
"for"
> loop that needs to be modified to grab the subsets from the DF frame 
below
> (i.e., the (1,2) pair selected by the combn function will select data 
from
> DF where the actual variable index=1 or index=2 ; using the example
> above).
>
>  BEGIN CODE 
> DF <- rbind(a,b,c)
> DF
> for(index in as.data.frame(combn(3,2))) print(DF[,index])
>  END CODE 
>
>
>
> Regards,
> Jesse
>
>
>
>
>
>
>
>
> "Gabor Grothendieck" <[EMAIL PROTECTED]>
> 07/14/2006 11:01 AM
>
> To
> "Jesse Albert Canchola" <[EMAIL PROTECTED]>
> cc
> r-help@stat.math.ethz.ch
> Subject
> Re: [R] looping using combinatorics
>
>
>
>
>
>
> Use data.frame, not rbind, e.g. DF <- data.frame(a, b, c)
>
> On 7/14/06, Jesse Albert Canchola <[EMAIL PROTECTED]> wrote:
> > Many thanks, Gabor.  This is very close to what would be ideal.  You
> gave
> > me an idea as follows:
> >
> > Rather than combine pairs of data vectors/frames AFTER the "combn"
> > function, combine all data before (though I belive this would be less
> > efficient) and add an index then use that index to choose your pairs 
(or
> > whatever combinatorics you are using; e.g., 8 choose 4  so all
> > combinations of 4 out of 8 for a total of 70 combinations.)
> >
> > Example data frames with variable names:
> >
> > Data frame "a" where I add an "index":
> > id measure index
> > 1  1.1  1
> > 2  1.2  1
> > 3  1.3  1
> >
> > Data frame "b" where I add an "index":
> > id measure index
> > 4  2.1  2
> > 5  2.2  2
> > 6  2.3  2
> >
> > Data frame "c" where I add an index:
> > id measure index
> > 7  3.1  3
> > 8  3.2  3
> > 9  3.3  3
> >
> > If we combine all these data at once using rbind, we get:
> > id measure index
> > 1  1.1  1
> > 2  1.2  1
> > 3  1.3  1
> > 4  2.1  2
> > 5  2.2  2
> > 6  2.3  2
> > 7  3.1  3
> > 8  3.2  3
> > 9  3.3  3
> >
> > We can then use something similar to your code and the index to choose
> the
> > required pairs as derived from the "combn" function.
> > For example, the "combn" function will choose the data pairs
> > (1,2)
> > (1,3)
> > (2,3)
> >
> > where, for example, the pairs (1,2) will have data from frames "a" and
> > "b":
> > 1  1.1  1
> > 2  1.2  1
> > 3  1.3  1
> > 4  2.1  2
> > 5  2.2  2
> > 6  2.3  2
> >
> > so that we can go down the list subsetting what we need and doing
> > operations on each combined pair as we go.
> >
> > Is there an easy way in R to do this operation?
> >
> > For the above, an attempt might be:
> >
> > ## STAB CODE #
> > DF <- rbind(a,b,c)
> > DF
> > for(index in as.data.frame(combn(3,2))) print(DF[,index])
> >  END STAB CODE ##
> >
> > but this is choosing 3 choose 2 COLUMNS within the combined file 
rather
> > than 3 choose 2 ROWS.
> >
> >
> > Best regards and TIAA,
> > Jesse
> >
> >
> >
> >
> >
> > "Gabor Grothendieck" <[EMAIL PROTECTED]>
> > 07/13/2006 07:39 PM
> >
> > To
> > "Jesse Albert Canchola" <[EMAIL PROTECTED]>
> > cc
> > r-help@s

Re: [R] R newbie: logical subsets

2006-07-14 Thread Joshua Tokle
This is exactly what I needed -- thanks for your help Greg and Gabor.

I'm looking forward to replacing a dozen stored procedures, temp tables, 
and database calls with a one page R script.

Josh

On Wed, 12 Jul 2006, Greg Snow wrote:

> Gabor, your solution does not take into account the groups.  How about
> something like:
>
> iris2 <- iris
> iris2$m <- ave(iris2$Sepal.Length, iris2$Species)
> iris2$s <- ave(iris2$Sepal.Length, iris2$Species, FUN=sd)
>
> iris2 <- transform(iris2, z= (Sepal.Length-m)/s)
>
> iris2.2 <- subset(iris2, abs(z) < 2)
>
> aggregate(iris2.2, list(iris2.2$Species), FUN=mean)
>
>
>
> -- 
> 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 Gabor
> Grothendieck
> Sent: Tuesday, July 11, 2006 1:06 PM
> To: Joshua Tokle
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] R newbie: logical subsets
>
> Try this, using the built in anscombe data set:
>
> anscombe[!rowSums(abs(scale(anscombe)) > 2),]
>
>
>
> On 7/11/06, Joshua Tokle <[EMAIL PROTECTED]> wrote:
>> Hello!  I'm a newcomer to R hoping to replace some convoluted database
>
>> code with an R script.  Unfortunately, I haven't been able to figure
>> out how to implement the following logic.
>>
>> Essentially, we have a database of transactions that are coded with a
>> geographic locale and a type.  These are being loaded into a
>> data.frame with named variables city, type, and price.  E.g.,
>> trans$city and all that.
>>
>> We want to calculate mean prices by city and type, AFTER excluding
>> outliers.  That is, we want to calculate the mean price in 3 steps:
>>
>> 1. calculate a mean and standard deviation by city and type over all
>> transactions 2. create a subset of the original data frame, excluding
>> transactions that differ from the relevant mean by more than 2
>> standard deviations 3. calculate a final mean by city and type based
>> on this subset.
>>
>> I'm stuck on step 2.  I would like to do something like the following:
>>
>> fs <- list(factor(trans$city), factor(trans$type)) means <-
>> tapply(trans$price, fs, mean) stdevs <- tapply(trans$price, fs, sd)
>>
>> filter <- abs(trans$price - means[trans$city, trans$type]) <
>> 2*stdevs[trans$city, trans$type]
>>
>> sub <- subset(trans, filter)
>>
>> The above code doesn't work.  What's the correct way to do this?
>>
>> Thanks,
>> Josh
>>
>> __
>> 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
>>
>
> __
> 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
>
>

__
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


[R] lm: Displaying 95% confidence and prediction intervals on scatterplots

2006-07-14 Thread jenny tan
Hi,

May I know  how does one superimpose the 95% confidence and prediction 
intervals on the linear regression line of a scatterplot?

Thanks in advance!

jenny


My data:

CEU8EA
0.033   0
0.014   0
0.019   0
0.023   0
0.033   0
0.033   0
0.033   0
0.037   0
0.033   0
0.014   0
0.019   0
0.023   0
0.014   0
0.019   0
0.023   0
0.014   0
0.019   0
0.023   0
0.017   0
0.018   0
0.022   0
0.014   0
0.019   0
0.023   0
0.114   0.004
0.114   0.004
0.042   0.004
0.012   0.007
0.130.008
0.130.008
0.122   0.008
0.122   0.008
0.122   0.008
0.122   0.008
0.112   0.008
0.112   0.008
0.105   0.009
0.111   0.009
0.232   0.009
0.242   0.009
0.005   0.014
0.006   0.014
0.006   0.014
0.007   0.014
0.047   0.016
0.050.017
0.050.017
0.040.018
0.040.018
0.040.018
0.040.018
0.034   0.018
0.040.018
0.010.018
0.020.021
0.022   0.021
0.021   0.021
0.032   0.022
0.011   0.022
0.011   0.022
0   0.022
0   0.022
0.011   0.022
0.011   0.022
0.011   0.022
0.011   0.022
0.033   0.023
0.032   0.023
0.035   0.023
0.033   0.023
0.049   0.026
0.047   0.026
0.179   0.026
0.038   0.026
0.012   0.028
0.012   0.028
0.013   0.034
0.013   0.034
0.033   0.036
0.057   0.041
0.060.048
0.060.048
0.023   0.05
0.031   0.05
0.031   0.05
0.033   0.05
0.034   0.05
0.418   0.052
0.094   0.059
0.106   0.059
0.1 0.059
0.012   0.059
0.019   0.059
0.018   0.059
0.017   0.059
0.025   0.059
0.024   0.059
0.020.059
0.027   0.059
0.022   0.059
0.020.059
0.029   0.059
0.024   0.059
0.060.062
0.043   0.062
0.047   0.062
0.037   0.062
0.036   0.062
0.060.062
0.174   0.066
0.040.067
0.052   0.067
0.048   0.067
0.055   0.067
0.027   0.07
0.011   0.07
0.011   0.07
0.014   0.07
0.037   0.071
0.034   0.071
0.054   0.071
0.052   0.071
0.050.071
0.048   0.071
0.057   0.071
0.055   0.071
0.151   0.076
0.373   0.082
0.408   0.082
0.408   0.082
0.418   0.082
0.057   0.086
0.057   0.086
0.042   0.086
0.046   0.086
0.040.086
0.040.086
0.090.09
0.112   0.091
0.131   0.091
0.124   0.091
0.095   0.091
0.090.091
0.588   0.094
0.026   0.1
0.038   0.1
0.038   0.1
0.042   0.1
0.191   0.107
0.191   0.107
0.191   0.107
0.191   0.107
0.193   0.107
0.191   0.107
0.045   0.107
0.446   0.116
0.042   0.12
0.017   0.12
0.019   0.12
0.015   0.12
0.016   0.12
0.157   0.125
0.082   0.128
0.103   0.128
0.114   0.128
0.114   0.128
0.143   0.129
0.166   0.129
0.157   0.129
0.143   0.129
0.166   0.129
0.157   0.129
0.143   0.129
0.166   0.129
0.157   0.129
0.143   0.129
0.166   0.129
0.157   0.129
0.149   0.129
0.175   0.129
0.166   0.129
0.143   0.129
0.166   0.129
0.157   0.129
0.064   0.129
0.067   0.13
0.064   0.13
0.050.13
0.081   0.138
0.081   0.138
0.269   0.145
0.194   0.152
0.020.158
0.135   0.159
0.074   0.163
0.074   0.163
0.074   0.163
0.073   0.163
0.104   0.167
0.104   0.167
0.104   0.167
0.201   0.175
0.187   0.175
0.084   0.175
0.084   0.175
0.088   0.175
0.086   0.175
0.080.175
0.080.175
0.083   0.175
0.081   0.175
0.080.175
0.080.175
0.083   0.175
0.081   0.175
0.072   0.175
0.073   0.175
0.073   0.175
0.072   0.175
0.187   0.176
0.234   0.176
0.216   0.176
0.446   0.176
0.412   0.176
0.412   0.176
0.410.176
0.110.179
0.109   0.179
0.117   0.179
0.132   0.185
0.135   0.185
0.135   0.188
0.132   0.188
0.140.188
0.136   0.188
0.252   0.189
0.256   0.192
0.147   0.2
0.165   0.2
0.111   0.2
0.096   0.2
0.111   0.2
0.197   0.2
0.187   0.2
0.197   0.2
0.143   0.2
0.142   0.2
0.151   0.2
0.401   0.2
0.435   0.2
0.435   0.2
0.447   0.2
0.083   0.205
0.136   0.206
0.246   0.214
0.246   0.214
0.246   0.214
0.246   0.214
0.266   0.214
0.246   0.214
0.282   0.219
0.289   0.219
0.244   0.219
0.234   0.219
0.266   0.219
0.274   0.219
0.228   0.219
0.217   0.219
0.086   0.219
0.091   0.219
0.091   0.219
0.081   0.219
0.177   0.222
0.422   0.222
0.303   0.231
0.325   0.236
0.283   0.236
0.153   0.236
0.745   0.239
0.745   0.239
0.745   0.239
0.745   0.239
0.765   0.239
0.745   0.239
0.175   0.25
0.181   0.25
0.093   0.25
0.325   0.257
0.344   0.263
0.346   0.263
0.363   0.263
0.322   0.266
0.325   0.266
0.280.266
0.283   0.266
0.097   0.266
0.101   0.266
0.101   0.266
0.091   0.266
0.558   0.273
0.328   0.273
0.299   0.273
0.451   0.273
0.310.273
0.277   0.273
0.212   0.286
0.169   0.286
0.193   0.286
0.152   0.286
0.209   0.286
0.241   0.286
0.258   0.286
0.601   0.288
0.334   0.289
0.322   0.289
0.325   0.289
0.170.289
0.344   0.3
0.356   0.3
0.346   0.3
0.359   0.3
0.363   0.3
0.376   0.3
0.214   0.304
0.223   0.304
0.063   0.327
0.063   0.327
0.064   0.327
0.064   0.327
0.424   0.347
0.602   0.347
0.296   0.357
0.424   0.375
0.440.375
0.460.398
0.460.398
0.269   0.429
0.284   0.429
0.269   0.429
0.284   0.429
0.269   0.429
0.284   0.429
0.269   0.429
0.274   0.429
0.269   0.429
0.284   0.429
0.309   0.429
0.284   0.429
0.562   0.449
0.607   0.449
0.607   0.449
0.609   0.449
0.637   0.476
0.574   0.5
0.595   0.5
0.583   0.576
0

Re: [R] Keep value lables with data frame manipulation

2006-07-14 Thread Frank E Harrell Jr
Heinz Tuechler wrote:
> At 11:02 13.07.2006 -0500, Frank E Harrell Jr wrote:
>> Heinz Tuechler wrote:
>>> At 08:11 13.07.2006 -0500, Frank E Harrell Jr wrote:
 Heinz Tuechler wrote:
> At 13:14 12.07.2006 -0500, Marc Schwartz (via MN) wrote:
>> On Wed, 2006-07-12 at 17:41 +0100, Jol, Arne wrote:
>>> Dear R,
>>>
>>> I import data from spss into a R data.frame. On this rawdata I do some
>>> data processing (selection of observations, normalization, recoding of
>>> variables etc..). The result is stored in a new data.frame, however, in
>>> this new data.frame the value labels are lost.
>>>
>>> Example of what I do in code:
>>>
>>> # read raw data from spss
>>> rawdata <- read.spss("./data/T50937.SAV",
>>> use.value.labels=FALSE,to.data.frame=TRUE)
>>>
>>> # select the observations that we need
>>> diarydata <- rawdata[rawdata$D22==2 | rawdata$D22==3 |
> rawdata$D22==17 |
>>> rawdata$D22==18 | rawdata$D22==20 | rawdata$D22==22 |
>>> rawdata$D22==24 | rawdata$D22==33,]
>>>
>>> The result is that rawdata$D22 has value labels and that diarydata$D22
>>> is numeric without value labels.
>>>
>>> Question: How can I prevent this from happening?
>>>
>>> Thanks in advance!
>>> Groeten,
>>> Arne
>> Two things:
>>
>> 1. With respect to your subsetting, your lengthy code can be replaced
>> with the following:
>>
>>  diarydata <- subset(rawdata, D22 %in% c(2, 3, 17, 18, 20, 22, 24, 33))
>>
>> See ?subset and ?"%in%" for more information.
>>
>>
>> 2. With respect to keeping the label related attributes, the
>> 'value.labels' attribute and the 'variable.labels' attribute will not by
>> default survive the use of "[".data.frame in R (see ?Extract
>> and ?"[.data.frame").
>>
>> On the other hand, based upon my review of ?read.spss, the SPSS value
>> labels should be converted to the factor levels of the respective
>> columns when 'use.value.labels = TRUE' and these would survive a
>> subsetting.
>>
>> If you want to consider a solution to the attribute subsetting issue,
>> you might want to review the following post by Gabor Grothendieck in
>> May, which provides a possible solution:
>>
>>  https://stat.ethz.ch/pipermail/r-help/2006-May/106308.html
>>
>> and this post by me, for an explanation of what is happening in Gabor's
>> solution:
>>
>>  https://stat.ethz.ch/pipermail/r-help/2006-May/106351.html
>>
>> HTH,
>>
>> Marc Schwartz
>>
> Hello Mark and Arne,
>
> I worked on the suggestions of Gabor and Mark and programmed some
> functions
> in this way, but they are very, very preliminary (see below).
> In my view there is a lack of convenient possibilities in R to document
> empirical data by variable labels, value labels, etc. I would prefer to
> have these possibilities in the "standard" configuration.
> So I sketched a concept, but in my view it would only be useful, if there
> was some acceptance by the core developers of R.
>
> The concept would be to define a class. For now I call it "source.data".
> To design it more flexible than the Hmisc class "labelled" I would
> define a
> related option "source.data.attributes" with default c('value.labels',
> 'variable.name', 'label')). This option contains all attributes that
> should
> persist in subsetting/indexing.
>
> I made only some very, very preliminary tests with these functions,
> mainly
> because I am not happy with defining a new class. Instead I would prefer,
> if this functionality could be integrated in the Hmisc class "labelled",
> since this is in my view the best known starting point for data
> documentation in R.
>
> I would be happy, if there were some discussion about the wishes/needs of
> other Rusers concerning data documentation.
>
> Greetings,
>
> Heinz
 I feel that separating variable labels and value labels and just using 
 factors for value labels works fine, and I would urge you not to create 
 a new system that will not benefit from the many Hmisc functions that 
 use variable labels and units.  [.data.frame in Hmisc keeps all
> attributes.
 Frank

>>> Frank,
>>>
>>> of course I aggree with you about the importance of Hmisc and as I said, I
>>> do not want to define a new class, but in my view factors are no good
>>> substitute for value labels.
>>> As the language definition (version 2.3.1 (2006-06-05) Draft, page 7) says:
>>> "Factors are currently implemented using an integer array to specify the
>>> actual levels and a second array of names that are mapped to the integers.
>>> Rather unfortunately users often make use of the implementation in order to
>>> make some calculations easier." 
>>> So, in my view, the levels represent t

[R] R installation - WINDOWS - problem

2006-07-14 Thread N. Goodacre
Dear R mailing group,

 I am having extreme - and mysterious - trouble installing R. I tried 
simply dl ing R-2.3.1.tar.gz, and unzipping it, but after doing so, nowhere 
could I find a file called R-2.3.1.exe. I did however find an 
R-2.3.1.exe.manifest.

 I therefore tried the command line installation command - given in 
R-admin.pdf. This command is: tar zxvf R-2.3.1.tgz

This is strange because the file I dl'ed was a .tar.gz. I tried this line 
as well as: tar zxvf R-2.3.1.tar.gz. The command was not recognized.

 Can anyone help me with this trange problem?

 Sincerely,

Norman Goodacre

__
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


Re: [R] R installation - WINDOWS - problem

2006-07-14 Thread Dirk Eddelbuettel

On 15 July 2006 at 02:41, N. Goodacre wrote:
| Dear R mailing group,
| 
|  I am having extreme - and mysterious - trouble installing R. I tried 
| simply dl ing R-2.3.1.tar.gz, and unzipping it, but after doing so, nowhere 
| could I find a file called R-2.3.1.exe. I did however find an 
| R-2.3.1.exe.manifest.
| 
|  I therefore tried the command line installation command - given in 
| R-admin.pdf. This command is: tar zxvf R-2.3.1.tgz
| 
| This is strange because the file I dl'ed was a .tar.gz. I tried this line 
| as well as: tar zxvf R-2.3.1.tar.gz. The command was not recognized.
| 
|  Can anyone help me with this trange problem?

You are download the source, you want the binary. Start here (assumming that
you're actually physically/network-close to cam.ac.uk:

http://cran.uk.r-project.org/bin/windows/base

aka

http://www.stats.bris.ac.uk/R/bin/windows/base/

and pick the file R-2.3.1-win32.exe.

Hope this helps, Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
  -- Thomas A. Edison

__
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


[R] Ordered Logistic Regression in survey command

2006-07-14 Thread Debarchana Ghosh
Hi,

How can I do ordered logistic regression in svyglm?

Thanks,
D.

-- 
Debarchana Ghosh
Research Assistant
Department of Geography
University of Minnesota
PH: 8143607580
email to: [EMAIL PROTECTED]
www.tc.umn.edu/~ghos0033

__
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