Re: [R] Need help with error

2011-03-19 Thread Allan Engelhardt

As it says at the bottom of every post:


PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Without an example that fails, it is hard to help.

Allan

On 18/03/11 16:26, Savitri N Appana wrote:

Hi R users,

I am getting the following error when using the splsda function in R
v2.12.1:

Error in switch(classifier, logistic = { : EXPR must be a length 1
vector

What does this mean and how do I fix this?

Thank you in advance!

Best,
Savi

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


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


Re: [R] How do I delete multiple blank variables from a data frame?

2011-03-19 Thread Allan Engelhardt



On 19/03/11 01:35, Joshua Wiley wrote:

Hi Rita,

This is far from the most efficient or elegant way, but:

## two column data frame, one all NAs
d- data.frame(1:10, NA)
## use apply to create logical vector and subset d
d[, apply(d, 2, function(x) !all(is.na(x)))]


This works, but apply converts d to a matrix which is not needed, so try

d[, sapply(d, function(x) !all(is.na(x)))]


if performance is an issue (apply is about 3x slower on your test data 
frame d, more for larger data frames).


For the related problem of removing columns of constant-or-na values, 
the best I could come up with is


zv.1 - function(x) {
## The literal approach
y - var(x, na.rm = TRUE)
return(is.na(y) || y == 0)
}
sapply(train, zv.1)

See 
http://www.cybaea.net/Blogs/Data/R-Eliminating-observed-values-with-zero-variance.html 
for the benchmarks.


Allan



I am just apply()ing to each column (the 2) of d, the function
!all(is.na(x)) which will return FALSE if all of x is missing and TRUE
otherwise.  The result is a logical vector the same length as the
number of columns in d that is used to subset only the d columns with
at least some non-missing values.  For documentation see:

?apply
?is.na
?all
?[
?Logic

HTH,

Josh

On Fri, Mar 18, 2011 at 3:35 PM, Rita Carreiraritacarre...@hotmail.com  wrote:

Dear List Members,I have 55 data frames, each of which with 272 variables and 
267 observations. Some of these variables are blanks but the blanks are not the 
same for every data frame. I would like to write a procedure in which I import 
a data frame, see which variables are blank, and delete those variables. My 
data frames have variables named P1 to P136 and Q1 to Q136.
I have a couple of questions regarding this issue:
1) Is a loop an efficient way to address this problem? If not, what are my 
alternatives and how do I implement them?2) I have been playing with a single data 
frame to try to figure out a way of having R go through the columns and see which 
ones it should delete. I have figured out how to delete rows with missing data 
(newdata- na.omit(olddata)) but how do I do it for columns???
Thank you very much for your help and have a great weekend!
Rita  If you think education is expensive, 
try ignorance--Derek Bok



[[alternative HTML version deleted]]

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






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


Re: [R] [R-sig-ME] lmm WITHOUT random factor (lme4)

2011-03-19 Thread Mark Difford
On Mar 19, 2011; 01:39am Andrzej Galecki wrote:

 I agree with you that caution needs to be exercised. Simply because
 mathematically the same 
 likelihood may be defined using different constant.

Yes. But this is ensured by the implementation. If the call to anova() is
made with the lm$obj first in the sequence then an error is thrown. If the
call is correctly made, with the lme$obj placed first in the sequence, then
the log of the likelihood of each object is calculate by nlme:::logLik.lme
using the same formula [via lapply(object, logLik, REML), where logLik
points to nlme:::logLik.lme].

You will note, as Andrzej Galecki has pointed out, that the logLik.lm of the
lm$obj is different from logLik.lme.

##
 logLik(fm)
'log Lik.' -950.1465 (df=3)
 logLik(fm, REML=T)
'log Lik.' -946.8318 (df=3)

Regards, Mark.

--
View this message in context: 
http://r.789695.n4.nabble.com/lmm-WITHOUT-random-factor-lme4-tp3384054p3389249.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] [O/T] reference for regular expressions

2011-03-19 Thread David Wolfskill
On Fri, Mar 18, 2011 at 09:45:57PM -0500, Erin Hodgess wrote:
 Dear R People:
 
 Could someone recommend a good reference on regular expressions, please?
 ...

Mastering Regular Expressions; Friedl, Jeffrey E. F.; ISBN
9780596528126.

Many of the O'Reilly books (as this one) may be purchased in an
electronic format , which is often slightly less expensive, can be
faster to arrive, and is readily amenable (in the case of O'Reilly, at
least) to low-cost (or free) electronic delivery of updates.

That said, another approach would be to run Perl in debug mode against
some (Perl) script, and use the debugger to see exactly what matches
(and what happens when you change something).  You might able to do this
with R's browser() fiunction, at least to some extenr; I confess that I
have a great deal more experience with Perl, so I'm more comfortable
experimenting in that way using the Perl debugger.  (And in any case,
Perl is well-known for the facility with which one may use regular
expressions in it.)

The above are not (intended as) mutually exclusive.

Peace,
david
-- 
David H. Wolfskill  r...@catwhisker.org
Depriving a girl or boy of an opportunity for education is evil.

See http://www.catwhisker.org/~david/publickey.gpg for my public key.


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


Re: [R] Replace split with regex for speed ?

2011-03-19 Thread rivercode
Thanks for your suggestions.

Cheers,
Chris

--
View this message in context: 
http://r.789695.n4.nabble.com/Replace-split-with-regex-for-speed-tp3386098p3388958.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How do I delete multiple blank variables from a data frame?

2011-03-19 Thread Tyler Rinker

I actually prefer to do this portion of the work (data prep) inside of excel.  
When you export the data as an cvs doc the NA's will be in the excel 
spreadsheet.  Now the search and/or the search and replace option become very 
handy.  Probably a better way in [R] though.
 
Tyler

 
 Date: Fri, 18 Mar 2011 18:35:20 -0700
 From: jwiley.ps...@gmail.com
 To: ritacarre...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] How do I delete multiple blank variables from a data frame?
 
 Hi Rita,
 
 This is far from the most efficient or elegant way, but:
 
 ## two column data frame, one all NAs
 d - data.frame(1:10, NA)
 ## use apply to create logical vector and subset d
 d[, apply(d, 2, function(x) !all(is.na(x)))]
 
 I am just apply()ing to each column (the 2) of d, the function
 !all(is.na(x)) which will return FALSE if all of x is missing and TRUE
 otherwise. The result is a logical vector the same length as the
 number of columns in d that is used to subset only the d columns with
 at least some non-missing values. For documentation see:
 
 ?apply
 ?is.na
 ?all
 ?[
 ?Logic
 
 HTH,
 
 Josh
 
 On Fri, Mar 18, 2011 at 3:35 PM, Rita Carreira ritacarre...@hotmail.com 
 wrote:
 
  Dear List Members,I have 55 data frames, each of which with 272 variables 
  and 267 observations. Some of these variables are blanks but the blanks are 
  not the same for every data frame. I would like to write a procedure in 
  which I import a data frame, see which variables are blank, and delete 
  those variables. My data frames have variables named P1 to P136 and Q1 to 
  Q136.
  I have a couple of questions regarding this issue:
  1) Is a loop an efficient way to address this problem? If not, what are my 
  alternatives and how do I implement them?2) I have been playing with a 
  single data frame to try to figure out a way of having R go through the 
  columns and see which ones it should delete. I have figured out how to 
  delete rows with missing data (newdata - na.omit(olddata)) but how do I do 
  it for columns???
  Thank you very much for your help and have a great weekend!
  Rita  If you think education is 
  expensive, try ignorance--Derek Bok
 
 
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
 -- 
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
  
[[alternative HTML version deleted]]

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


Re: [R] Performance Difference? Windows vs. Linux

2011-03-19 Thread Prof Brian Ripley

On Fri, 18 Mar 2011, Shige Song wrote:


One thing that Linux makes trivially easy is to interpolate R with C++
through the Rcpp package. The GCC compiler collection is part of all
mainstream Linux distro. This is, however, not the case with Windows:
you may be able to do it eventually (not sure about this point), but
it takes quite some tweaks...


Oh, come on: you admit don't know what you are talking about, but you 
then give advice on something unrelated to the command line.  That 
forces other people to correct your erroneous advice for the record.


You do not need Rcpp to use C++ with R, and only a very small minority 
of C++-using packages do whereas Rcpp leans very heavily on the work 
of the core team to support C++.


There is a C++ compiler which is part of the Rtools collection which 
you need to use compiled code on Windows.  But actually that is no 
different from Linux, where the person who installed Linux has to 
arrange to install the compilers from the distro.




Shige

On Fri, Mar 18, 2011 at 6:00 PM, Brigid Mooney bkmoo...@gmail.com wrote:

I'm not trying to start a Windows vs. Linux debate, but I've been
using R on a Windows machine for a while, and was recently wondering
if R's performance would be faster on a Linux machine.  And similarly,
if any incremental increase in processing speed would be worth the
time it would take me to migrate my entire system to Linux (including
a database that I access via an R package.)

I don't know how much it matters what R is doing - but I've got R
pulling a large amount data from a database, performing many complex
computations on that data, and then writing output data to a database.

Thanks so much for the input,
Brigid

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



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



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


Re: [R] Performance Difference? Windows vs. Linux

2011-03-19 Thread Prof Brian Ripley

To try to answer the actual question 

I run x86_64 Linux and both 32-bit Windows XP and x64 Windows 7 on my 
home desktop.  So from years of experience of using the same hardware 
on those OSes:


1) Generally Linux will be a bit faster, mainly because I do not 
hobble it with --enable-R-shlib (the only way R can be built on 
Windows).  But the difference is small (5-20%).


2) Linux handles large amounts of memory (and especially swapping) 
better, so the differences will be more if what you do is using nearly 
all the address space or physical RAM of your computer.


3) Linux's process launch and disc access is many times faster, which 
makes a big difference to R development work.


From your described usage I would expect you to see a worthwhile 
performance gain -- it does matter what you are doing with R.  It also 
matters which database system.


On Fri, 18 Mar 2011, Brigid Mooney wrote:


I'm not trying to start a Windows vs. Linux debate, but I've been
using R on a Windows machine for a while, and was recently wondering
if R's performance would be faster on a Linux machine.  And similarly,
if any incremental increase in processing speed would be worth the
time it would take me to migrate my entire system to Linux (including
a database that I access via an R package.)

I don't know how much it matters what R is doing - but I've got R
pulling a large amount data from a database, performing many complex
computations on that data, and then writing output data to a database.

Thanks so much for the input,
Brigid

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



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

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


Re: [R] [O/T] reference for regular expressions

2011-03-19 Thread Gabor Grothendieck
On Fri, Mar 18, 2011 at 10:45 PM, Erin Hodgess erinm.hodg...@gmail.com wrote:
 Dear R People:

 Could someone recommend a good reference on regular expressions, please?


There are links to a number of sites on the gsubfn home page:

http://gsubfn.googlecode.com/#REGULAR_EXPRESSION_LINKS

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


[R] How to find position in bin-data?

2011-03-19 Thread Antje Niederlein
Hi there,

probably there is a very simple solution, but I cannot think of one...

I have a vector with values:

data - c(1,6,3,4,8,4,2,9)

and I have a vector with bin breaks:

bins - c(1,3,5,7,9,11)

Now, I'd like to get for each data point the index of the bin-vector
where the value falls in (or equals the lower bin break).

In the example case, I'd like to get:

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

How would you solve it?

Antje

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


[R] how to access the elements of a univariate results table with Anova (library car)

2011-03-19 Thread Juan Andres Hernandez
Dear R users,  I use the excelent Anova function of the library car because
the easy way to get sphericity correction. Unless I use the scan function. I
have not been able to access the values ​​of sum squares and degrees of
freedom for each effect in the univariate summary table.

Example of the car library for Anova function:

library(car)
phase - factor(rep(c(pretest, posttest, followup), c(5, 5, 5)),
 levels=c(pretest, posttest, followup))
 hour - ordered(rep(1:5, 3))
idata - data.frame(phase, hour)

mod.ok - lm(cbind(pre.1, pre.2, pre.3, pre.4, pre.5,
  post.1, post.2, post.3, post.4, post.5,
  fup.1, fup.2, fup.3, fup.4, fup.5) ~
 treatment*gender,
 data=OBrienKaiser)
av.ok - Anova(mod.ok, idata=idata, idesign=~phase*hour)

summary(av.ok, multivariate=FALSE)

If you assign the above line to a new object you will get a multivariate
summary and not the univariate one.

my.summary - summary(av.ok, multivariate=FALSE)
my.summary

Does anyone know how to assign the full univariate output to a new object
or variable. The logical way does not produce the desired  result.
Than'ks in advance.

Juan Hernández Cabrera
Facultad de Psicología
Universidad de La Laguna
Spain

[[alternative HTML version deleted]]

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


Re: [R] How to find position in bin-data?

2011-03-19 Thread Duncan Murdoch

On 11-03-19 8:18 AM, Antje Niederlein wrote:

Hi there,

probably there is a very simple solution, but I cannot think of one...

I have a vector with values:

data- c(1,6,3,4,8,4,2,9)

and I have a vector with bin breaks:

bins- c(1,3,5,7,9,11)

Now, I'd like to get for each data point the index of the bin-vector
where the value falls in (or equals the lower bin break).

In the example case, I'd like to get:

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

How would you solve it?


Use cut.  For example,

data - c(1,6,3,4,8,4,2,9)
bins - c(1,3,5,7,9,11)

result - cut(data, breaks=bins, right=FALSE)
as.numeric(result)


Duncan Murdoch

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


Re: [R] How to find position in bin-data?

2011-03-19 Thread Antje Niederlein
Thanks a lot! That's what I was looking for :-)

A



On 19 March 2011 13:56, Duncan Murdoch murdoch.dun...@gmail.com wrote:
 On 11-03-19 8:18 AM, Antje Niederlein wrote:

 Hi there,

 probably there is a very simple solution, but I cannot think of one...

 I have a vector with values:

 data- c(1,6,3,4,8,4,2,9)

 and I have a vector with bin breaks:

 bins- c(1,3,5,7,9,11)

 Now, I'd like to get for each data point the index of the bin-vector
 where the value falls in (or equals the lower bin break).

 In the example case, I'd like to get:

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

 How would you solve it?

 Use cut.  For example,

 data - c(1,6,3,4,8,4,2,9)
 bins - c(1,3,5,7,9,11)

 result - cut(data, breaks=bins, right=FALSE)
 as.numeric(result)


 Duncan Murdoch


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


Re: [R] How to find position in bin-data?

2011-03-19 Thread Alexander Engelhardt

Am 19.03.2011 13:18, schrieb Antje Niederlein:

Hi there,

probably there is a very simple solution, but I cannot think of one...
I have a vector with values:
data- c(1,6,3,4,8,4,2,9)
and I have a vector with bin breaks:
bins- c(1,3,5,7,9,11)


cut() does what you want:

 cut(data, bins)
[1] NA  (5,7] (1,3] (3,5] (7,9] (3,5] (1,3] (7,9]
Levels: (1,3] (3,5] (5,7] (7,9] (9,11]

 as.numeric(cut(data,bins))
[1] NA  3  1  2  4  2  1  4

data[1] is NA because of the structure of the intervals.

Grüsse,
 Alex

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


[R] cross-validation in rpart

2011-03-19 Thread Penny B
I am trying to find out what type of sampling scheme is used to select the 10
subsets in 10-fold cross-validation process used in rpart to choose the best
tree. Is it simple random sampling? Is there any documentation available on
this?

Thanks, Penny.

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

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


[R] strange PREDICTIONS from a PIECEWISE LINEAR (mixed) MODEL

2011-03-19 Thread Federico Bonofiglio
Hi Dears,

When I introduce an interaciton in a piecewise model I obtain some quite
unusual results.

If that would't take u such a problem I'd really appreciate an advise from
you.

I've reproduced an example below...

Many thanks




x-rnorm(1000)

y-exp(-x)+rnorm(1000)

plot(x,y)
abline(v=-1,col=2,lty=2)


mod-lm(y~x+x*(x-1))

summary(mod)

yy-predict(mod)

lines(x[order(x)],yy[order(x)],col=2,lwd=2)


#--lme

#grouping factor, unbalanced

g-as.character(c(1:200))
id-sample(g,size=1000,replace=T,
prob=sample(0:1,200,rep=T))

table(id)   #unbalanced



mod2-lme(y~x+x*(x-1),random=~x|id,
data=data.frame(x,y,id))

summary(mod2)


newframe-data.frame(  #fictious id
id=fictious,
x)

newframe[1:5,]

#predictions

yy2-predict(mod2,level=0, newdata=newframe)


lines(x[order(x)],yy2[order(x)],col=blue,lwd=2)



# add variable in the model

z-rgamma(1000,4,6)

mod3-lme(y~x+x*(x-1)+z
,random=~x|id,
data=data.frame(x,y,z,id))

summary(mod3)


#new id

newframe2-data.frame(  #fictious id
id=fictious,
x,
z)


#predict

yy3-predict(mod3,level=0, newdata=newframe2)


lines(x[order(x)],yy3[order(x)],col=green,lwd=2)



# ADD INTERACTION  z:x



mod4-lme(y~x+x*(x-1)+

z+
   z:x+
 z:x*(x-1)

   ,random=~x|id,
data=data.frame(x,y,z,id))



#predict

yy4-predict(mod4,level=0, newdata=newframe2)


lines(x[order(x)],yy4[order(x)],col=violet,lwd=2)  #something bizarre
#starts to happen
#in the predicted values

# they begin to jiggle around the straight line








-- 
*Little u can do against ignorance,it will always disarm u:
is the 2nd principle of thermodinamics made manifest, ...entropy in
expansion.**But setting order is the real quest 4 truth, ..and the
mission of a (temporally) wise dude.
*

[[alternative HTML version deleted]]

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


[R] Plotting graph problem!!

2011-03-19 Thread andrew456
http://r.789695.n4.nabble.com/file/n3389613/Life_Expectancies_2008.csv
Life_Expectancies_2008.csv 

I am trying to plot a histogram base on the file i uploaded above. I am
facing a trouble in sorting out the frequency of the life expectancies. I
wanted to plot a graph of life expectancies at birth versus frequency,but i
have no idea how to change the locations into frequencies taking the range
of life expectancies at birth from 40 to 90. I tried using
table(Life.Expectancies.at.Birth) to show the frequencies of each number and
I do not know how to continue.

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

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


Re: [R] Generating repeated measures data

2011-03-19 Thread Michael Dewey

At 00:37 19/03/2011, John Sorkin wrote:
How would one generate data to be used in a simulation of a repeated 
measures ANOVA given a known (1) within-person correlation with 
known (2) mean and SD of data obtained at each of three times of observation?



You do not say which distribution you want them to have but for 
normal the best choice seems to be to load MASS and use rmvtnorm.


Generating multivariate datasets from distributions
other than the normal
can be more challenging.
In \R contributed packages provide the following among others:
\begin{description}
\item[\pkg{corcount}]
Poisson, negative binomial, zero--inflated versions
\item[\pkg{binarySimCLF}]
Generates binary variables, see \citet{qaqish03}
for details
\item[\pkg{bindat}]
Generates binary by thresholding normal
\item[\pkg{mvtBinaryEP}]
Binary
\item[\pkg{sn}]
Skew normal and skew $t$
\end{description}

Apologies for all the LaTeX but I fear if I try to edit it I will 
delete something crucial.




Thanks,
John
John Sorkin
Chief Biostatistics and Informatics
Univ. of Maryland School of Medicine
Division of Gerontology and Geriatric Medicine
jsor...@grecc.umaryland.edu
Confidentiality Statement:
This email message, including any attachments, is for t...{{dropped:6}}


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


Re: [R] Extracting columns from a class

2011-03-19 Thread Thomas Levine
Hi,

Here is the prcomp output.

tom=prcomp(matrix(rnorm(25),5,5))

R functions often output lists. To see what's in this one, run
names(tom) or type tom$ and use tab completion. Once you do that,
the following is more obvious.

pc1=tom$rotation[,1]
sd1=tom$sdev[1]
column=c(sd1,pc1)

write.table(column,tom,row.names=F,col.names=F)

This will send the column to the file tom.

Tom

On Thu, Mar 17, 2011 at 8:10 AM, nuncio m nunci...@gmail.com wrote:
 Hi list,
           I am not a frequent user of R.  Recently I used R in principal
 component analysis and got the result as a class, which has information like
 standard deviation and principal components from 1 to 10.  How is it
 possible to extract the column corresponding to first principal component
 and write it to a file
 the out from prcomp command is something like this

 Standard
 deviations:

  [1] 3.325801e+00 7.669837e-01 6.625773e-01 4.990732e-01 3.470071e-01
  [6] 2.946679e-01 2.206289e-01 1.645828e-01 1.570887e-01
 4.741294e-16


 Rotation:
               PC1           PC2           PC3           PC4          PC5
  [1,] -0.07900624 -0.0824864352  0.1208419434  0.1763425845  0.089545020
  [2,] -0.09114708 -0.0901675110  0.1377608881  0.2224127252  0.076620976
  [3,] -0.10510742 -0.0935434206  0.1113586044  0.2513993555  0.029783117

 I want to extract PC1 and 1 value in the standard deviation

 Thanks

 --
 Nuncio.M
 Research Scientist
 National Center for Antarctic and Ocean research
 Head land Sada
 Vasco da Gamma
 Goa-403804

        [[alternative HTML version deleted]]

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


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


Re: [R] how to access the elements of a univariate results table with Anova (library car)

2011-03-19 Thread David Winsemius


On Mar 19, 2011, at 8:44 AM, Juan Andres Hernandez wrote:

Dear R users,  I use the excelent Anova function of the library car  
because
the easy way to get sphericity correction. Unless I use the scan  
function. I
have not been able to access the values ​​of sum squares and  
degrees of

freedom for each effect in the univariate summary table.

Example of the car library for Anova function:

library(car)
phase - factor(rep(c(pretest, posttest, followup), c(5, 5, 5)),
levels=c(pretest, posttest, followup))
hour - ordered(rep(1:5, 3))
idata - data.frame(phase, hour)

mod.ok - lm(cbind(pre.1, pre.2, pre.3, pre.4, pre.5,
 post.1, post.2, post.3, post.4, post.5,
 fup.1, fup.2, fup.3, fup.4, fup.5) ~
treatment*gender,
data=OBrienKaiser)
av.ok - Anova(mod.ok, idata=idata, idesign=~phase*hour)

summary(av.ok, multivariate=FALSE)

If you assign the above line to a new object you will get a  
multivariate

summary and not the univariate one.

my.summary - summary(av.ok, multivariate=FALSE)
my.summary

Does anyone know how to assign the full univariate output to a new  
object

or variable. The logical way does not produce the desired  result.
Than'ks in advance.


summary,Anova.mlm appears to returns the object that was passed to it.  
How to I know this (despite never having used the function before and  
having tried unsuccessfully to access the answer with  
help(summary.Anova.mlm))?  I looked at the code.  You are getting  
console output that varies a bit with different parameters to summary,  
but the object av.ok being passed as the value of summary and is not  
changing.


 all.equal(av.ok, my.summary)
[1] TRUE

If you want to capture the text output that appears on the console  
display then you need to use either sink() or capture.output().




Juan Hernández Cabrera
Facultad de Psicología
Universidad de La Laguna
Spain


--

David Winsemius, MD
West Hartford, CT

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


Re: [R] Plotting graph problem!!

2011-03-19 Thread David Winsemius


On Mar 19, 2011, at 9:10 AM, andrew456 wrote:


http://r.789695.n4.nabble.com/file/n3389613/Life_Expectancies_2008.csv
Life_Expectancies_2008.csv

I am trying to plot a histogram base on the file i uploaded above. I  
am
facing a trouble in sorting out the frequency of the life  
expectancies. I
wanted to plot a graph of life expectancies at birth versus  
frequency,but i
have no idea how to change the locations into frequencies taking the  
range

of life expectancies at birth from 40 to 90. I tried using
table(Life.Expectancies.at.Birth) to show the frequencies of each  
number and

I do not know how to continue.


You should show how you turned that data into an R object first. Then  
someone may offer a hint to take the next step in your homework.


--

David Winsemius, MD
West Hartford, CT

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


Re: [R] cross-validation in rpart

2011-03-19 Thread Allan Engelhardt
I assume you mean rpart::xpred.rpart ?  The beauty of R means that you 
can look at the source.  For the simple case (where xval is a single 
number) the code does indeed do simple random sampling


xgroups- sample(rep(1:xval, length = nobs), nobs, replace = FALSE)


If you want another sampling, then you simply pass a vector as the xval 
parameter, as the documentation says: “This may also be an explicit list 
of integers that define the cross-validation groups”.


Hope this helps a little.

Allan

On 19/03/11 09:21, Penny B wrote:

I am trying to find out what type of sampling scheme is used to select the 10
subsets in 10-fold cross-validation process used in rpart to choose the best
tree. Is it simple random sampling? Is there any documentation available on
this?

Thanks, Penny.


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


[R] persuade tabulate function to count NAs in a data frame

2011-03-19 Thread Bodnar Laszlo EB_HU
Hi,

I'd like to ask you a question again. It is basically about data frames, NAs 
and tabulate function.

I have this data frame. I already used this in one of the previous questions of 
mine. It intentionally looks this simple, my real 'df' dataframe is much bigger 
actually and again, I am not willing to annoy anyone with huge databases... So, 
my database:

id -c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3)
a -c(3,1,3,3,1,3,3,3,3,1,3,2,1,2,1,3,3,2,1,1,1,3,1,3,3,3,2,1,1,3)
b -c(3,2,1,1,1,1,1,1,1,1,1,2,1,3,2,1,1,1,2,1,3,1,2,2,1,3,3,2,3,2)
c -c(1,3,2,3,2,1,2,3,3,2,2,3,1,2,3,3,3,1,1,2,3,3,1,2,2,3,2,2,3,2)
d -c(3,3,3,1,3,2,2,1,2,3,2,2,2,1,3,1,2,2,3,2,3,2,3,2,1,1,1,1,1,2)
e -c(2,3,1,2,1,2,3,3,1,1,2,1,1,3,3,2,1,1,3,3,2,2,3,3,3,2,3,2,1,4)
df -data.frame(id,a,b,c,d,e)
df

I have managed to calculate the distributions of the numbers occurring in 
columns 'b' to 'e' but considering the fact at the very same time that these 
distributions should be 'groupped by' the id numbers in column 'id'. It works 
fine, check it -

matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,2] 
[[1]])),ncol=3,nrow=3,byrow=TRUE)
matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,3] 
[[2]])),ncol=3,nrow=3,byrow=TRUE)
matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,4] 
[[3]])),ncol=3,nrow=3,byrow=TRUE)
matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,5] 
[[4]])),ncol=3,nrow=3,byrow=TRUE)
matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,6] 
[[5]])),ncol=4,nrow=3,byrow=TRUE)

Now my problem is: what if my data frame contains NA values here and there and 
what if I want my in-built tabulate function to collect these NAs as well? So 
what if I want it to count how many occurrences I have from these NAs?

Here's my modified data frame with the NAs:
id -c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3)
a -c(NA,1,3,3,1,3,3,3,3,1,3,2,1,2,1,3,3,2,1,1,1,3,1,3,3,3,2,1,1,3)
b -c(3,2,1,1,1,1,1,1,1,1,1,2,1,3,2,1,1,1,2,1,3,1,2,2,1,3,3,2,3,2)
c -c(1,3,2,3,2,1,2,3,3,2,2,3,NA,2,3,3,3,1,1,2,3,3,1,2,2,3,2,2,3,2)
d -c(3,3,3,1,3,2,2,1,2,3,2,2,2,1,3,1,2,2,3,2,3,2,3,2,1,1,1,1,1,2)
e -c(2,3,1,2,1,2,3,3,1,1,2,1,1,3,3,2,1,1,3,3,2,2,3,3,3,2,3,NA,1,4)
df -data.frame(id,a,b,c,d,e)
df

At first I tried something like this (you see, the only thing I did was that I 
tried to apply this exclude=NULL thing).
unlist(lapply(df[,(-(1))],function(x) 
tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,2],exclude=NULL [[1]])

At least my code realizes the fact that I have 4 different levels in column 'a' 
(1,2,3,NA) and not only three (1,2,3). Check it here:
nlevels(factor(df[,2],exclude=NULL))

But you see in the result that somehow it could not calculate the NAs. It says
3  0  6  0(!)  4  3  3  0  4  1  5  0

Instead of the correct:
3  0  6  1(!)  4  3  3  0  4  1  5  0

Or in case of:
unlist(lapply(df[,(-(1))],function(x) 
tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,4],exclude=NULL [[3]])

It says
2  4  4  0  2  3  4  0(!)  1  5  4  0

Instead of the correct
2  4  4  0  2  3  4  1(!)  1  5  4  0
etc.

Does someone have any ideas how to persuade the function tabulate to count 
NAs? Is it possible at all?
Thanks very much and have a pleasant weekend,
Laszlo


Ez az e-mail és az összes hozzá tartozó csatolt melléklet titkos és/vagy 
jogilag, szakmailag vagy más módon védett információt tartalmazhat. 
Amennyiben nem Ön a levél címzettje akkor a levél tartalmának közlése, 
reprodukálása, másolása, vagy egyéb más úton történő terjesztése, 
felhasználása szigorúan tilos. Amennyiben tévedésből kapta meg ezt az 
üzenetet kérjük azonnal értesítse az üzenet küldőjét. Az Erste Bank 
Hungary Zrt. (EBH) nem vállal felelősséget az információ teljes és pontos 
- címzett(ek)hez történő - eljuttatásáért, valamint semmilyen 
késésért, kapcsolat megszakadásból eredő hibáért, vagy az információ 
felhasználásából vagy annak megbízhatatlanságából eredő kárért.

Az üzenetek EBH-n kívüli küldője vagy címzettje tudomásul veszi és 
hozzájárul, hogy az üzenetekhez más banki alkalmazott is hozzáférhet az 
EBH folytonos munkamenetének biztosítása érdekében.


This e-mail and any attached files are confidential and/...{{dropped:19}}

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


Re: [R] Plotting graph problem!!

2011-03-19 Thread Allan Engelhardt

You should probably tell us which part of

a- 
read.csv(http://r.789695.n4.nabble.com/file/n3389613/Life_Expectancies_2008.csv;)
hist(a)


doesn't do what you expect.

(Though often when people say histogram they want something else - 
what's with that anyhow?)


Allan

On 19/03/11 13:10, andrew456 wrote:

http://r.789695.n4.nabble.com/file/n3389613/Life_Expectancies_2008.csv
Life_Expectancies_2008.csv

I am trying to plot a histogram base on the file i uploaded above. I am
facing a trouble in sorting out the frequency of the life expectancies. I
wanted to plot a graph of life expectancies at birth versus frequency,but i
have no idea how to change the locations into frequencies taking the range
of life expectancies at birth from 40 to 90. I tried using
table(Life.Expectancies.at.Birth) to show the frequencies of each number and
I do not know how to continue.

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

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


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


Re: [R] cross-validation in rpart

2011-03-19 Thread Prof Brian Ripley

On Sat, 19 Mar 2011, Penny B wrote:


I am trying to find out what type of sampling scheme is used to select the 10
subsets in 10-fold cross-validation process used in rpart to choose the best
tree. Is it simple random sampling? Is there any documentation available on
this?


Not SRS (and least in its conventional meaning), as it is 
partitioning: the 10 folds are disjoint.


Note that this happens in two places, in rpart() and in xpred.rpart(), 
but the (default) method is the same.  I presume you asked about the 
first, but it wasn't clear.


There is a lot of documentation on the meaning of '10-fold 
cross-validation', e.g. in my 1996 book.  There are a few slightly 
different ways to do it, and you can read the rpart sources if you 
want to know the details.


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

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


Re: [R] persuade tabulate function to count NAs in a data frame

2011-03-19 Thread Gavin Simpson
On Sat, 2011-03-19 at 15:58 +0100, Bodnar Laszlo EB_HU wrote:
 Hi,

I'll top-post as the original Q is very lengthy:

tabs -lapply(df[,2:6], 
  function(x, id){ t(table(addNA(x), id, useNA = ifany)) }, df$id)

is one way of doing what you want. More details are here:

http://stackoverflow.com/questions/5362702/persuading-tabulate-function-to-count-nas-in-a-data-frame-in-r

where you also posted your Q.

HTH

G


 I'd like to ask you a question again. It is basically about data frames, NAs 
 and tabulate function.
 
 I have this data frame. I already used this in one of the previous questions 
 of mine. It intentionally looks this simple, my real 'df' dataframe is much 
 bigger actually and again, I am not willing to annoy anyone with huge 
 databases... So, my database:
 
 id -c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3)
 a -c(3,1,3,3,1,3,3,3,3,1,3,2,1,2,1,3,3,2,1,1,1,3,1,3,3,3,2,1,1,3)
 b -c(3,2,1,1,1,1,1,1,1,1,1,2,1,3,2,1,1,1,2,1,3,1,2,2,1,3,3,2,3,2)
 c -c(1,3,2,3,2,1,2,3,3,2,2,3,1,2,3,3,3,1,1,2,3,3,1,2,2,3,2,2,3,2)
 d -c(3,3,3,1,3,2,2,1,2,3,2,2,2,1,3,1,2,2,3,2,3,2,3,2,1,1,1,1,1,2)
 e -c(2,3,1,2,1,2,3,3,1,1,2,1,1,3,3,2,1,1,3,3,2,2,3,3,3,2,3,2,1,4)
 df -data.frame(id,a,b,c,d,e)
 df
 
 I have managed to calculate the distributions of the numbers occurring in 
 columns 'b' to 'e' but considering the fact at the very same time that these 
 distributions should be 'groupped by' the id numbers in column 'id'. It works 
 fine, check it -
 
 matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
 tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,2] 
 [[1]])),ncol=3,nrow=3,byrow=TRUE)
 matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
 tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,3] 
 [[2]])),ncol=3,nrow=3,byrow=TRUE)
 matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
 tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,4] 
 [[3]])),ncol=3,nrow=3,byrow=TRUE)
 matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
 tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,5] 
 [[4]])),ncol=3,nrow=3,byrow=TRUE)
 matrix(matrix(unlist(lapply(df[,(-(1))],function(x) 
 tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,6] 
 [[5]])),ncol=4,nrow=3,byrow=TRUE)
 
 Now my problem is: what if my data frame contains NA values here and there 
 and what if I want my in-built tabulate function to collect these NAs as 
 well? So what if I want it to count how many occurrences I have from these 
 NAs?
 
 Here's my modified data frame with the NAs:
 id -c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3)
 a -c(NA,1,3,3,1,3,3,3,3,1,3,2,1,2,1,3,3,2,1,1,1,3,1,3,3,3,2,1,1,3)
 b -c(3,2,1,1,1,1,1,1,1,1,1,2,1,3,2,1,1,1,2,1,3,1,2,2,1,3,3,2,3,2)
 c -c(1,3,2,3,2,1,2,3,3,2,2,3,NA,2,3,3,3,1,1,2,3,3,1,2,2,3,2,2,3,2)
 d -c(3,3,3,1,3,2,2,1,2,3,2,2,2,1,3,1,2,2,3,2,3,2,3,2,1,1,1,1,1,2)
 e -c(2,3,1,2,1,2,3,3,1,1,2,1,1,3,3,2,1,1,3,3,2,2,3,3,3,2,3,NA,1,4)
 df -data.frame(id,a,b,c,d,e)
 df
 
 At first I tried something like this (you see, the only thing I did was that 
 I tried to apply this exclude=NULL thing).
 unlist(lapply(df[,(-(1))],function(x) 
 tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,2],exclude=NULL [[1]])
 
 At least my code realizes the fact that I have 4 different levels in column 
 'a' (1,2,3,NA) and not only three (1,2,3). Check it here:
 nlevels(factor(df[,2],exclude=NULL))
 
 But you see in the result that somehow it could not calculate the NAs. It says
 3  0  6  0(!)  4  3  3  0  4  1  5  0
 
 Instead of the correct:
 3  0  6  1(!)  4  3  3  0  4  1  5  0
 
 Or in case of:
 unlist(lapply(df[,(-(1))],function(x) 
 tapply(x,df$id,tabulate,nbins=nlevels(factor(df[,4],exclude=NULL [[3]])
 
 It says
 2  4  4  0  2  3  4  0(!)  1  5  4  0
 
 Instead of the correct
 2  4  4  0  2  3  4  1(!)  1  5  4  0
 etc.
 
 Does someone have any ideas how to persuade the function tabulate to count 
 NAs? Is it possible at all?
 Thanks very much and have a pleasant weekend,
 Laszlo
 
 
 Ez az e-mail és az összes hozzá tartozó csatolt melléklet titkos és/vagy 
 jogilag, szakmailag vagy más módon védett információt tartalmazhat. 
 Amennyiben nem Ön a levél címzettje akkor a levél tartalmának közlése, 
 reprodukálása, másolása, vagy egyéb más úton történő terjesztése, 
 felhasználása szigorúan tilos. Amennyiben tévedésből kapta meg ezt az 
 üzenetet kérjük azonnal értesítse az üzenet küldőjét. Az Erste Bank Hungary 
 Zrt. (EBH) nem vállal felelősséget az információ teljes és pontos - 
 címzett(ek)hez történő - eljuttatásáért, valamint semmilyen késésért, 
 kapcsolat megszakadásból eredő hibáért, vagy az információ felhasználásából 
 vagy annak megbízhatatlanságából eredő kárért.
 
 Az üzenetek EBH-n kívüli küldője vagy címzettje tudomásul veszi és 
 hozzájárul, hogy az üzenetekhez más banki alkalmazott is hozzáférhet az EBH 
 folytonos munkamenetének biztosítása érdekében.
 
 
 This e-mail 

Re: [R] Plotting graph problem!!

2011-03-19 Thread Allan Engelhardt

On 19/03/11 15:04, Allan Engelhardt wrote:

You should probably tell us which part of

a- 
read.csv(http://r.789695.n4.nabble.com/file/n3389613/Life_Expectancies_2008.csv;)

hist(a)

Should be hist(a$Life.Expectancies.at.Birth), of course.  Sorry.



doesn't do what you expect.

(Though often when people say histogram they want something else - 
what's with that anyhow?)


Allan

On 19/03/11 13:10, andrew456 wrote:

http://r.789695.n4.nabble.com/file/n3389613/Life_Expectancies_2008.csv
Life_Expectancies_2008.csv

I am trying to plot a histogram base on the file i uploaded above. I am
facing a trouble in sorting out the frequency of the life 
expectancies. I
wanted to plot a graph of life expectancies at birth versus 
frequency,but i
have no idea how to change the locations into frequencies taking the 
range

of life expectancies at birth from 40 to 90. I tried using
table(Life.Expectancies.at.Birth) to show the frequencies of each 
number and

I do not know how to continue.

--
View this message in context: 
http://r.789695.n4.nabble.com/Plotting-graph-problem-tp3389613p3389613.html

Sent from the R help mailing list archive at Nabble.com.

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

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


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


Re: [R] Plotting graph problem!!

2011-03-19 Thread andrew456

data1-read.delim(C:\\Users\\wenyin\\desktop\\Life_Expectancies_2008.txt,header=T)
 attach(data1)
 names(data1)
 table(Life.Expectancies.at.Birth)

so this thing showed up:

Life.Expectancies.at.Birth
42 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
71 
 2  2  1  4  4  1  2  2  5  5  1  2  3  5  3  2  6  6  3  3  1  5  6  7  8 
6 
72 73 74 75 76 77 78 79 80 81 82 83 
13 11 14  9  8  2  5  3 12  8  5  2 

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

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


Re: [R] Plotting graph problem!!

2011-03-19 Thread andrew456
I assigned the dataset to data1,then i tried typing hist(data1),it says:

Error in hist.default(data1) : 'x' must be numeric

how can I change the Locations to frequency so that it is in numeric form
and I can plot the histogram?








You should probably tell us which part of

a-
read.csv(http://r.789695.n4.nabble.com/file/n3389613/Life_Expectancies_2008.csv;)
hist(a)


doesn't do what you expect.

(Though often when people say histogram they want something else - 
what's with that anyhow?)

Allan



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

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


[R] Could you share your R program to import US CDC mortality data?

2011-03-19 Thread Renny Li
Hello -

I downloaded yearly mortality (all cause) data from CDC website. But have 
trouble to import them into R, have you worked with CDC mortality data before? 
I would appreciate it if you could share your R code on importing the data into 
R.

Thanks,
Renny



  
[[alternative HTML version deleted]]

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


Re: [R] Could you share your R program to import US CDC mortality data?

2011-03-19 Thread David Winsemius


On Mar 19, 2011, at 12:03 PM, Renny Li wrote:


Hello -

I downloaded yearly mortality (all cause) data from CDC website.


You should offer a specific URL. The CDC website is huge and there are  
undoubtedly many places where various forms of such data are available.



But have trouble to import them into R, have you worked with CDC  
mortality data before? I would appreciate it if you could share your  
R code on importing the data into R.



[[alternative HTML version deleted]]


You should also learn how to submit plain text messages to rhelp.

--

David Winsemius, MD
West Hartford, CT

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


[R] Libraries issue

2011-03-19 Thread Ben Ward
Hi, I've just discovered R keeps installing my packages into 
C:\Users\Ben instead of C:\\Users\\Ben;/R/win-library/2.12 which is 
what is returned by running Sys.getenv(R_LIBS_USER).


I've tried setting environment variables in windows control panel of

R_LIBS.


But nothing seems to be working, it still wants to fill my user folder, 
I've tried uninstalling and re-installing but it still does the same 
thing. Does anybody know how I can fix this?

Thanks,
Ben W.



[[alternative HTML version deleted]]

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


Re: [R] quantmod Some Single Letter Tickers Not getFin

2011-03-19 Thread Joshua Ulrich
Hi John,

The financial statement pages exist, but they require the exchange to
be specified.  For example:
http://www.google.com/finance?fstype=iiq=NYSE:GE
and
http://www.google.com/finance?fstype=iiq=GE
take you to the same page, but
http://www.google.com/finance?fstype=iiq=NYSE:F
works, while
http://www.google.com/finance?fstype=iiq=F
results in a 400 'Bad request' error.

This seems to work for this one symbol, maybe it will work for others as well.
getFin(NYSE:F)

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



On Thu, Mar 17, 2011 at 10:48 PM, Sparks, John James jspa...@uic.edu wrote:
 Hi,

 I have been learning the quantmod package over the last several days.  I
 went to check some of my data pulls against other sources and was
 surprised to find that a few tickers that have single characters do not
 successfully scrape from Google Finance using getFin().  Particularly

 require(quantmod)
 getFin(A)
 getFin(E)
 getFin(F)
 getFin(G)
 getFin(M)

 all result in a file not found error.  I show the last one below.

 getFin(M)
 Error in download.file(paste(google.fin, Symbol, sep = ), quiet = TRUE,  :
  cannot open URL 'http://finance.google.com/finance?fstype=iiq=M'
 In addition: Warning message:
 In download.file(paste(google.fin, Symbol, sep = ), quiet = TRUE,  :
  cannot open: HTTP status was '400 Bad Request'


 I checked out the financial statement pages for all of these and they
 exist and are as expected:  5 quarters worth of quarterly figures (except
 for cash-flow which has 4 quarters) and 4 years of annual figures.  All
 the rows are also present by comparing a scrape to excel with the figures
 for Y, which does getFin(Y) without a problem.

 I was hoping that someone who knows a lot more about scraping then I do
 could look into this.

 Best wishes to all,
 --John Sparks

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


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


Re: [R] Libraries issue

2011-03-19 Thread Joshua Wiley
Hi Ben,

I could be completely off target (corrections welcome if I am), but I
think the semicolon in the environment variable is making two separate
paths and maybe R chooses the first?  It should be easy to try
changing.

HTH,

Josh

(and sorry for the wild goose hunt if my memory is shoddy)

On Sat, Mar 19, 2011 at 9:37 AM, Ben Ward benjamin.w...@bathspa.org wrote:
 Hi, I've just discovered R keeps installing my packages into
 C:\Users\Ben instead of C:\\Users\\Ben;/R/win-library/2.12 which is
 what is returned by running Sys.getenv(R_LIBS_USER).


 I've tried setting environment variables in windows control panel of

 R_LIBS.


 But nothing seems to be working, it still wants to fill my user folder,
 I've tried uninstalling and re-installing but it still does the same
 thing. Does anybody know how I can fix this?

 Thanks,
 Ben W.



        [[alternative HTML version deleted]]

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




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


[R] GAMLSS Question

2011-03-19 Thread YAddo
Dear All:

I have succeeded in fitting a GAMLSS.dist model to growth data I am working
with it.

My aim is to create a matrix of  predicted percentiles and the corresponding 
the fitted model's sigma mu nu by agebins.

Q:
How do it generate these parameters as in L M S per Cole and Green 1992?

Here are my working codes. 

  Name of fitted model is gamlssfit

 Agebin-seq(6,36,6)
centmatx
-centiles.pred(gamlssfit,xname=agemos,xvalues=Agebin,cent=c(10,25,50,75,90))

Although I got matrix of the percentiles by agebins, I want to obtain the L
M S/sigma mu nu corresponding to the same agebins.


Any help here will be appreciated.

Thanks,

Y Addo




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

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


Re: [R] Plotting graph problem!!

2011-03-19 Thread andrew456
Thanks a lot for teaching me!!! By the way,one more question,how do i plot a
boxplot of that??






On 19/03/11 15:04, Allan Engelhardt wrote:
 You should probably tell us which part of

 a- 
 read.csv(http://r.789695.n4.nabble.com/file/n3389613/Life_Expectancies_2008.csv;)
 hist(a)
Should be hist(a$Life.Expectancies.at.Birth), of course.  Sorry.





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

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


[R] How would you avoid loops in this simple example?

2011-03-19 Thread zerfetzen
I'm trying to code more R-like and avoid loops. Here is an example I'm having
a hard time getting away from loops with, and the real matrices are rather
large, and the computation is too time-consuming.

### Dimensions
N - 2
M - 3
P - 4
### Array and Matrices
nu - array(NA,dim=c(N,M,P))
Lambda - matrix(1:12,P,M)
F - matrix(1:8,N,P)
### Loop to avoid
for (i in 1:N) {for (m in 1:M) {for (p in 1:P) {
 nu[i,m,p] - Lambda[p,m] * F[i,p]
}}}

Any help is appreciated. Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/How-would-you-avoid-loops-in-this-simple-example-tp3390017p3390017.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Output a table formatted with standard deviations below means

2011-03-19 Thread Nathan Torrance
Is it in bad form to double post to StackOverflow and R-help? Apologies if
so. Here's my task:

I've got a matrix of means like so

means-matrix(1:10,nrow=2)
colnames(means)-c(a,b,c,d,e)

and a matrix of standard deviations like so

sds-matrix(seq(0.1,1,by=0.1),nrow=2)
colnames(sds)-c(a,b,c,d,e)

and I want to output a Latex (or HTML) table where the standard deviations
appear in parens just below the corresponding means.

Something like this:

a   b  c  d  e \\
1   3  5  7  9 \\
  (0.1)(0.3)  (0.5)  (0.7)  (0.9) \\
2   4  6  8  10 \\
  (0.2)(0.4)  (0.6)  (0.8)  (1.0) \\

except in proper Latex (or HTML).

How can I do this from R?

Someone mentioned the apsrtable package but that seems to require my
having a model object.

Thanks in advance folks.

[[alternative HTML version deleted]]

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


Re: [R] Output a table formatted with standard deviations below means

2011-03-19 Thread Jorge Ivan Velez
Hi Nathan,

Do not know a direct way, but the following seems to work:

# data
means - matrix(1:10,nrow=2)
sds - matrix(seq(0.1,1,by=0.1),nrow=2)
colnames(means) - colnames(sds) - c(a,b,c,d,e)

# adding ( ) to the SDs
sdsn - t(apply(sds, 1, function(x) paste('(', x, ')', sep = )))

# formatting
res - do.call(rbind, lapply(1:nrow(means), function(i) rbind(means[i, ],
sdsn[i, ])))
res

# LaTeX
require(xtable)
xtable(res)

*HTH,*
*Jorge*
*
*

On Sat, Mar 19, 2011 at 12:13 PM, Nathan Torrance  wrote:

 Is it in bad form to double post to StackOverflow and R-help? Apologies if
 so. Here's my task:

 I've got a matrix of means like so

 means-matrix(1:10,nrow=2)
 colnames(means)-c(a,b,c,d,e)

 and a matrix of standard deviations like so

 sds-matrix(seq(0.1,1,by=0.1),nrow=2)
 colnames(sds)-c(a,b,c,d,e)

 and I want to output a Latex (or HTML) table where the standard deviations
 appear in parens just below the corresponding means.

 Something like this:

a   b  c  d  e \\
1   3  5  7  9 \\
  (0.1)(0.3)  (0.5)  (0.7)  (0.9) \\
2   4  6  8  10 \\
  (0.2)(0.4)  (0.6)  (0.8)  (1.0) \\

 except in proper Latex (or HTML).

 How can I do this from R?

 Someone mentioned the apsrtable package but that seems to require my
 having a model object.

 Thanks in advance folks.

[[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


Re: [R] Output a table formatted with standard deviations below means

2011-03-19 Thread David Winsemius


On Mar 19, 2011, at 12:13 PM, Nathan Torrance wrote:

Is it in bad form to double post to StackOverflow and R-help?  
Apologies if

so. Here's my task:

I've got a matrix of means like so

means-matrix(1:10,nrow=2)
colnames(means)-c(a,b,c,d,e)

and a matrix of standard deviations like so

sds-matrix(seq(0.1,1,by=0.1),nrow=2)
colnames(sds)-c(a,b,c,d,e)

and I want to output a Latex (or HTML) table where the standard  
deviations

appear in parens just below the corresponding means.


require(Hmisc)
mtx -  matrix(c( means[1,], paste((,sds[1,],)), means[2,],  
paste((,sds[2,],))), nrow=4, byrow=TRUE)

colnames(mtx)-colnames(means)
latex(mtx)

--
David



Something like this:

   a   b  c  d  e \\
   1   3  5  7  9 \\
 (0.1)(0.3)  (0.5)  (0.7)  (0.9) \\
   2   4  6  8  10 \\
 (0.2)(0.4)  (0.6)  (0.8)  (1.0) \\

except in proper Latex (or HTML).

How can I do this from R?

Someone mentioned the apsrtable package but that seems to require my
having a model object.

Thanks in advance folks.

[[alternative HTML version deleted]]

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] How would you avoid loops in this simple example?

2011-03-19 Thread Joshua Wiley
Hi,

You are basically just doing matrix multiplication, which R has some
built in, optimized functions for.  You can see the documentation at
?matmult
This gets you part of the way there.  I suspect you can even avoid the
last loop if you know enough about linear algebra and how to use some
clever transposition and inner or outer multiplication (?outer ?t
?matmult).

## alternate nu
nu2 - array(NA,dim=c(N,M,P))
## avoiding much of that loop
for(i in 1:P) {
  nu2[,, i] - F[, i, drop = FALSE] %*% Lambda[i, ]
}

HTH,

Josh

On Sat, Mar 19, 2011 at 10:27 AM, zerfetzen
paul.heinrich.dietr...@gmail.com wrote:
 I'm trying to code more R-like and avoid loops. Here is an example I'm having
 a hard time getting away from loops with, and the real matrices are rather
 large, and the computation is too time-consuming.

 ### Dimensions
 N - 2
 M - 3
 P - 4
 ### Array and Matrices
 nu - array(NA,dim=c(N,M,P))
 Lambda - matrix(1:12,P,M)
 F - matrix(1:8,N,P)
 ### Loop to avoid
 for (i in 1:N) {for (m in 1:M) {for (p in 1:P) {
     nu[i,m,p] - Lambda[p,m] * F[i,p]
 }}}

 Any help is appreciated. Thanks.

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/How-would-you-avoid-loops-in-this-simple-example-tp3390017p3390017.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

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


Re: [R] Libraries issue

2011-03-19 Thread peter dalgaard

On Mar 19, 2011, at 17:37 , Ben Ward wrote:

 Hi, I've just discovered R keeps installing my packages into 
 C:\Users\Ben instead of C:\\Users\\Ben;/R/win-library/2.12 which is 
 what is returned by running Sys.getenv(R_LIBS_USER).
 

Er, I'm rusty on Windows, but that's what it is supposed to do, isn't it? It's 
a path with two semicolon separated directories.

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

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


[R] som package: the code of som.train (what is it?)

2011-03-19 Thread Nesnàju
Hi to all, I am new in the forum, and also in using R (with Rkward in
Kubuntu).
I have a little problem with the som package: I do the first steps (som.init
and som), but when I have to do the train 

[ som.train(data, code, xdim, ydim, alpha=NULL, alphaType=inverse,
neigh=gaussian, topol=rect, radius=NULL, rlen=NULL, err.radius=1,
inv.alp.c=NULL) ]

I cannot understand what I have to write in the place of code.
I'm sorry if my doubt seems non comprehensible to someone, but I am not an
expert in maths, nor in programming.
Thanks to all for the help.



--
View this message in context: 
http://r.789695.n4.nabble.com/som-package-the-code-of-som-train-what-is-it-tp3390108p3390108.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] problem running a function

2011-03-19 Thread garciap
Dear people,

I'm trying to do some analysis of a data using the models by Royle  Donazio
in their fantastic book, particular the following function:
http://www.mbr-pwrc.usgs.gov/pubanalysis/roylebook/panel4pt1.fn

that applied to my data and in the console is as follows:
 `desman.y` - structure(c(3L,4L,3L,2L,1L), .Names = c(1, 2, 3, 4,
 5))
 
 RN-function(y=desman.y,J=5,nsites=39,Nmax=100){
+
+ lik-function(parms){
+  r-expit(parms[1])
+  lambda-exp(parms[2])
+  pvec-1-(1-r)^(0:Nmax)
+  gN-dpois(0:Nmax,lambda)
+  gN-gN/sum(gN)
+  lik-rep(NA,nsites)
+  for(i in 1:nsites){
+ lik[i]-sum(dbinom(y[i],J,pvec)*gN)
+  }
+ -1*sum(log(lik))
+}
+ 
+ 
+   tmp-nlm(lik,c(0,0),hessian=TRUE)
+   ests-tmp$estimate
+   aic-tmp$minimum*2 + 2*length(ests)
+   se- sqrt(diag(solve(tmp$hessian)))
+   list(ests=ests,se=se,aic=aic)
+   }

but when I try to see the results (i.e., the list in the function), I've the
follow errors:

 summary(RN)
Error in object[[i]] : object of type 'closure' is not subsettable

or obtains something like:

 print(RN)
function(y=desman.y,J=5,nsites=39,Nmax=100){
   
lik-function(parms){
 r-expit(parms[1])
 lambda-exp(parms[2])
 pvec-1-(1-r)^(0:Nmax)
 gN-dpois(0:Nmax,lambda)
 gN-gN/sum(gN)
 lik-rep(NA,nsites)
 for(i in 1:nsites){
lik[i]-sum(dbinom(y[i],J,pvec)*gN)
 }
-1*sum(log(lik))
   }


  tmp-nlm(lik,c(0,0),hessian=TRUE)
  ests-tmp$estimate
  aic-tmp$minimum*2 + 2*length(ests)
  se- sqrt(diag(solve(tmp$hessian)))
  list(ests=ests,se=se,aic=aic)
  }
 

this second one seems like the analyses are not done at all.

Any suggestion? Many thanks,

Pablo

--
View this message in context: 
http://r.789695.n4.nabble.com/problem-running-a-function-tp3390117p3390117.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Problem in installing and starting Rattle

2011-03-19 Thread Tony Plate
On Mon, Mar 7, 2011 at 6:57 AM, nerice neil.r...@plymouth.ac.uk wrote:
 CHECK FOR CONFLICTS IN YOUR PATH !!!

 I had a related problem when trying to use library RGtk2 for the first
 time.  My problem was that when loading the library R was looking for the
 file zlib1.dll but couldn't find the procedure to launch RGtk2. I was
 getting an Entry Point not found error from Rgui.exe.

 The reason was because I had another package in my PATH environment variable
 (C:\program files\Intel\WiFi\bin) which had a CONFLICTING version of the
 zlib1.dll - and it was looking in this file and not the zlib1.dll which
 came with GTK+.

 Removed this conflict from the PATH and all was ok.



I also had a related problem trying to use libary RGtk2 under Windows XP.

I kept getting the message unable to load shared object
C:\R\site-library\RGtk2\libs\i386\RGtk2.dll

Uninstalling and reinstalling various versions of GTK2, both through R
and outside R, many times, did not help.

With the help of Neil Rice's comment, I found that there was another
version of zlib1.dll in a directory on my PATH.  Removing that
directory from the path (inside R) fixed the problem and RGtk2 runs
fine now.

Here's an R expression to look for other copies on zlib1.dll on the path:

 with(list(x=file.path(strsplit(Sys.getenv(PATH), ;)$PATH, zlib1.dll)), 
 x[file.exists(x)])
[1] C:\\R\\GTK2-Runtime\\bin/zlib1.dll


There are many ways to modify the PATH.  To set PATH inside R:

 Sys.setenv(PATH=paste(grep(UNWANTEDPATH, strsplit(Sys.getenv(PATH), 
 ;)[[1]], value=T, invert=T), collapse=;))

(substitute some pattern that matches the unwanted directory for
UNWANTEDPATH, remembering to use four backslashes to match one).

-- Tony Plate

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


Re: [R] Libraries issue

2011-03-19 Thread Henrik Bengtsson
Hi.

On Sat, Mar 19, 2011 at 12:17 PM, peter dalgaard pda...@gmail.com wrote:

 On Mar 19, 2011, at 17:37 , Ben Ward wrote:

 Hi, I've just discovered R keeps installing my packages into
 C:\Users\Ben instead of C:\\Users\\Ben;/R/win-library/2.12 which is
 what is returned by running Sys.getenv(R_LIBS_USER).


 Er, I'm rusty on Windows, but that's what it is supposed to do, isn't it? 
 It's a path with two semicolon separated directories.

Unless explicitly requested to be so, most likely it is indeed meant
to be without the semicolon, i.e. C:\\Users\\Ben/R/win-library/2.12
(or normalized C:\\Users\\Ben\R\win-library\2.12, but that doesn't
matter here).  This is in line with what is said in help(.libPaths):

By default R_LIBS is unset, and R_LIBS_USER is set to subdirectory
‘R/win-library/x.y’ of the home directory, for R x.y.z.

Here are my Windows environment variables:

 Sys.getenv(R_LIBS_USER)
   R_LIBS_USER
C:\\Users\\hb/R/win-library/2.12

 Sys.getenv(HOME)
   HOME
C:\\Users\\hb

There should certainly not be any semicolons in the latter.  If you
set HOME to C:\\Users\\hb; before starting R, you do get:

 Sys.getenv(R_LIBS_USER)
R_LIBS_USER
C:\\Users\\hb;/R/win-library/2.12


My $.02

/henrik


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

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


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


Re: [R] R newbie: how to replace string/regular expression

2011-03-19 Thread eben
I would read up on the 'gsub' command in R help. It does what you would like.

--
View this message in context: 
http://r.789695.n4.nabble.com/R-newbie-how-to-replace-string-regular-expression-tp873169p3390170.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] problem running a function

2011-03-19 Thread Phil Spector

Try

RN()

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Sat, 19 Mar 2011, garciap wrote:


Dear people,

I'm trying to do some analysis of a data using the models by Royle  Donazio
in their fantastic book, particular the following function:
http://www.mbr-pwrc.usgs.gov/pubanalysis/roylebook/panel4pt1.fn

that applied to my data and in the console is as follows:

`desman.y` - structure(c(3L,4L,3L,2L,1L), .Names = c(1, 2, 3, 4,
5))

RN-function(y=desman.y,J=5,nsites=39,Nmax=100){

+
+ lik-function(parms){
+  r-expit(parms[1])
+  lambda-exp(parms[2])
+  pvec-1-(1-r)^(0:Nmax)
+  gN-dpois(0:Nmax,lambda)
+  gN-gN/sum(gN)
+  lik-rep(NA,nsites)
+  for(i in 1:nsites){
+ lik[i]-sum(dbinom(y[i],J,pvec)*gN)
+  }
+ -1*sum(log(lik))
+}
+ 
+
+   tmp-nlm(lik,c(0,0),hessian=TRUE)
+   ests-tmp$estimate
+   aic-tmp$minimum*2 + 2*length(ests)
+   se- sqrt(diag(solve(tmp$hessian)))
+   list(ests=ests,se=se,aic=aic)
+   }

but when I try to see the results (i.e., the list in the function), I've the
follow errors:


summary(RN)

Error in object[[i]] : object of type 'closure' is not subsettable

or obtains something like:


print(RN)

function(y=desman.y,J=5,nsites=39,Nmax=100){
  
   lik-function(parms){
r-expit(parms[1])
lambda-exp(parms[2])
pvec-1-(1-r)^(0:Nmax)
gN-dpois(0:Nmax,lambda)
gN-gN/sum(gN)
lik-rep(NA,nsites)
for(i in 1:nsites){
   lik[i]-sum(dbinom(y[i],J,pvec)*gN)
}
   -1*sum(log(lik))
  }
   

 tmp-nlm(lik,c(0,0),hessian=TRUE)
 ests-tmp$estimate
 aic-tmp$minimum*2 + 2*length(ests)
 se- sqrt(diag(solve(tmp$hessian)))
 list(ests=ests,se=se,aic=aic)
 }




this second one seems like the analyses are not done at all.

Any suggestion? Many thanks,

Pablo

--
View this message in context: 
http://r.789695.n4.nabble.com/problem-running-a-function-tp3390117p3390117.html
Sent from the R help mailing list archive at Nabble.com.

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



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


Re: [R] How would you avoid loops in this simple example?

2011-03-19 Thread Petr Savicky
On Sat, Mar 19, 2011 at 10:27:11AM -0700, zerfetzen wrote:
 I'm trying to code more R-like and avoid loops. Here is an example I'm having
 a hard time getting away from loops with, and the real matrices are rather
 large, and the computation is too time-consuming.
 
 ### Dimensions
 N - 2
 M - 3
 P - 4
 ### Array and Matrices
 nu - array(NA,dim=c(N,M,P))
 Lambda - matrix(1:12,P,M)
 F - matrix(1:8,N,P)
 ### Loop to avoid
 for (i in 1:N) {for (m in 1:M) {for (p in 1:P) {
  nu[i,m,p] - Lambda[p,m] * F[i,p]
 }}}

Try the following

  Lambda1 - aperm(array(Lambda, dim=c(P, M, N)), perm=c(3, 2, 1))
  F1 - aperm(array(F, dim=c(N, P, M)), perm=c(1, 3, 2))
  nu1 - Lambda1 * F1
  identical(nu, nu1)
  [1] TRUE

The function array() recycles its first argument, if the 
required dimension of the output is larger. The function
aperm() then puts the indices to the required order.

Hope this helps.

Petr Savicky.

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


Re: [R] GAMLSS Question

2011-03-19 Thread Tóth Dénes

Hi,

predictAll should do what you want. See ?predict.gamlss.

HTH,
  Denes





 Dear All:

 I have succeeded in fitting a GAMLSS.dist model to growth data I am
 working
 with it.

 My aim is to create a matrix of  predicted percentiles and the
 corresponding
 the fitted model's sigma mu nu by agebins.

 Q:
 How do it generate these parameters as in L M S per Cole and Green 1992?

 Here are my working codes.

   Name of fitted model is gamlssfit

 Agebin-seq(6,36,6)
centmatx
 -centiles.pred(gamlssfit,xname=agemos,xvalues=Agebin,cent=c(10,25,50,75,90))

 Although I got matrix of the percentiles by agebins, I want to obtain the
 L
 M S/sigma mu nu corresponding to the same agebins.


 Any help here will be appreciated.

 Thanks,

 Y Addo




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

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


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


Re: [R] Libraries issue

2011-03-19 Thread Ben Ward

Hi,

Got it fixed now, thanks everyone, still confused as to why it's never 
done that before, but at least it's fine now.


Ben W.

On 19/03/2011 19:38, Henrik Bengtsson wrote:

Hi.

On Sat, Mar 19, 2011 at 12:17 PM, peter dalgaardpda...@gmail.com  wrote:

On Mar 19, 2011, at 17:37 , Ben Ward wrote:


Hi, I've just discovered R keeps installing my packages into
C:\Users\Ben instead of C:\\Users\\Ben;/R/win-library/2.12 which is
what is returned by running Sys.getenv(R_LIBS_USER).


Er, I'm rusty on Windows, but that's what it is supposed to do, isn't it? It's 
a path with two semicolon separated directories.

Unless explicitly requested to be so, most likely it is indeed meant
to be without the semicolon, i.e. C:\\Users\\Ben/R/win-library/2.12
(or normalized C:\\Users\\Ben\R\win-library\2.12, but that doesn't
matter here).  This is in line with what is said in help(.libPaths):

By default R_LIBS is unset, and R_LIBS_USER is set to subdirectory
‘R/win-library/x.y’ of the home directory, for R x.y.z.

Here are my Windows environment variables:


Sys.getenv(R_LIBS_USER)

R_LIBS_USER
C:\\Users\\hb/R/win-library/2.12


Sys.getenv(HOME)

HOME
C:\\Users\\hb

There should certainly not be any semicolons in the latter.  If you
set HOME to C:\\Users\\hb; before starting R, you do get:


Sys.getenv(R_LIBS_USER)

 R_LIBS_USER
C:\\Users\\hb;/R/win-library/2.12


My $.02

/henrik


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

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





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


Re: [R] problem running a function

2011-03-19 Thread Ben Bolker
garciap garciap at usal.es writes:

 
 Dear people,
 
 I'm trying to do some analysis of a data using the models by Royle  Donazio
 in their fantastic book, particular the following function:
 http://www.mbr-pwrc.usgs.gov/pubanalysis/roylebook/panel4pt1.fn
 

[snip]

 I'm guessing you're fairly new to R, because you seem confused about
how functions work.  You don't need to redefine the function with
your particular data: instead, you 'call' the function with your
data inserted in the call.

  Below I've taken the definition of RN from the URL you provided;
I change the 'expit' function to 'plogis', which is an
equivalent function already built into R; and tried to run the RN()
function on your data.  I ran into some trouble running the function
before I realized that you had specified 'nsites' different from
the length of your y vector; I don't know under what circumstances
that would ever make sense, since the function is trying to 
calculate values from each element of y between 1 and nsites ...
Then the function did run, although it gave lots of warnings
and couldn't compute the standard error for lambda.  It also gave
a very small value for r and a very large value for lambda; I suspect
you don't have enough data to do a very good job estimating in this
case ...

RN-function(y,J=11,nsites=length(y),Nmax=100,old=TRUE){

  lik-function(parms){
r-plogis(parms[1])
lambda-exp(parms[2])
pvec-1-(1-r)^(0:Nmax)
gN-dpois(0:Nmax,lambda)
gN-gN/sum(gN)
if (old) {
  likvec - numeric(nsites)
  for(i in 1:nsites){
likvec[i]-sum(dbinom(y[i],J,pvec)*gN)
  }
} else {
  likvec - rowSums(sweep(outer(y,pvec,dbinom,size=J),2,
   gN,*))
}
res - -sum(log(likvec))
res
  }

  tmp-nlm(f=lik,
   p=c(0,0),
   hessian=TRUE)
  ests-tmp$estimate
  aic-tmp$minimum*2 + 2*length(ests)
  se- sqrt(diag(solve(tmp$hessian)))
  list(ests=ests,se=se,aic=aic)
}

desman - RN(y=c(3,4,3,2,1),J=5)

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


[R] Problems using NLS in conjunction with non-parameteric bootstrapping

2011-03-19 Thread mweckel
Hello,

I have been successfully using nls to fit a non-linear, self-limiting
function to several sets of data collected in 2010 (example found below). 
To generate confidence intervals for parameter estimates, I've been
attempting to bootstrap my sample. Unfortunately, I have meet with
singularity gradients and failures to converge. I have altered maxiter and
minFactor statements, used several different starting parameters, and the
plinear and port algorithm to no avail.  I used this same approach on a 2009
data set with no problems. 

I'm assuming that one or more of my bootstrap samples is causing the
problem. If this is the case, are there any suggestions on how I can proceed
with bootstrapping to generate CI? 


Thank you in advance,
Mark 

y - c(3.46,1.00,2.0,2.23,4.24,1.00,4.58,
4.69,3.00,5.10,2.83,3.46,1.73,2.46,1.41,2.24,3.00,1.73)
x - c(0.39,0.05,0.10,0.20,0.53,0.17,0.61,
0.40,0.30,0.40,0.42,0.35,0.28,0.40,0.12,0.25,0.71,0.15)

mydata - data.frame(x,y)
names(mydata) - c(x,y) # variable names 

%x=Trap success; proportion of total trap nights where at least one deer was
photographed
%y=Square root transformation of total number of deer photographed 


#asymptotic equation y = (a*x)/(b+x)
NlMFunc1 - function(x, a, b) {(a*x)/(b+x)}
NlMFunc1 - nls(y ~ NlMFunc1(x, alpha, beta), 
data = RPOvTS, start = list(alpha = 10, beta = 1), control = list(maxiter =
1, minFactor=1/20048), 
trace = T)
summary(NlMFunc1)
logLik(NlMFunc1)


#Generate non-parametric bootstrap estimates of alpha and beta
#using bootstrapping 


BootF=function (data,i){
# take a random sample of size 18 from a SqRtFemPhoto
# sample with replacement
d - data[i,]
NlmResampF- function(x, a, b) {(a*x)/(b+x)}
NlmResampF - nls(y ~ NlmResampF (x, alpha, beta), 
data = d, start = list(alpha = 10, beta = 1),
control = list(maxiter = 1, minFactor=1/20048, 
trace = T))

c(logLik(NlmResampF ), coef(NlmResampF )) }
#summary(NlmResampF )
#logLik(NlmResampF )


library(boot)   
Female.boot-boot(data=mydata, statistic=BootF,
R=1000)
Female.boot$t 

--
View this message in context: 
http://r.789695.n4.nabble.com/Problems-using-NLS-in-conjunction-with-non-parameteric-bootstrapping-tp3390208p3390208.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] create a matrix with values from data.frame

2011-03-19 Thread Nicolas Gutierrez

Hello,

I'm trying to create a matrix (95x55) with data from a data.frame pop:

 xloc yloc  go  indEne totW
 123  20   516   1 0.02   20.21
 223  20  1143   1 0.02   20.21
 323  20   250   1 0.02   20.21
 422  15   251   1 0.02   18.69
 522  15   598   1 0.02   18.69
 621  19   250   1 0.02   20.21
 722  20   251   1 0.02   18.69
 822  20   598   1 0.02   18.69

where xloc is the x dimension,  yloc the y dimension, and totW the 
values for each cell (xloc,yloc) in my matrix (55x95):


I'm trying:

Bio=with(pop, (table(factor(totW, levels = 1:55), factor(totW, levels = 
1:95


But I don't get what I want. Hints? Thanks!

Nic

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


Re: [R] persuade tabulate function to count NAs in a data frame

2011-03-19 Thread Jim Lemon

On 03/20/2011 01:58 AM, Bodnar Laszlo EB_HU wrote:

Hi,

I'd like to ask you a question again. It is basically about data frames, NAs 
and tabulate function.


Hi Bodnar,
The freq function in the prettyR package might do what you want.

Jim

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


Re: [R] create a matrix with values from data.frame

2011-03-19 Thread David Winsemius


On Mar 19, 2011, at 5:29 PM, Nicolas Gutierrez wrote:


Hello,

I'm trying to create a matrix (95x55) with data from a data.frame pop:

xloc yloc  go  indEne totW
123  20   516   1 0.02   20.21
223  20  1143   1 0.02   20.21
323  20   250   1 0.02   20.21
422  15   251   1 0.02   18.69
522  15   598   1 0.02   18.69
621  19   250   1 0.02   20.21
722  20   251   1 0.02   18.69
822  20   598   1 0.02   18.69

where xloc is the x dimension,  yloc the y dimension, and totW the  
values for each cell (xloc,yloc) in my matrix (55x95):


I'm trying:

Bio=with(pop, (table(factor(totW, levels = 1:55), factor(totW,  
levels = 1:95


You probably should be using `cut` rather than `factor`. (Both will  
create factor-class variables.)  Factor will give you a different  
level at each unique value while it appears that you want integer  
valued cuts. It's also unclear why you would be applying these cuts  
to totW twice You have three rows with identical (23,20) x,y  
coordinates and two each for (22,15) and (22,20), although the go  
values are different.





But I don't get what I want. Hints? Thanks!


Better advice might follow if you said what you were really trying to  
do and what the final answer should look like.




Nic

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] create a matrix with values from data.frame

2011-03-19 Thread jim holtman
Here is one way to fill in the value using indexing; it appears that
you data has the same xloc/yloc values

 x
  xloc yloc   go ind  Ene  totW
1   23   20  516   1 0.02 20.21
2   23   20 1143   1 0.02 20.21
3   23   20  250   1 0.02 20.21
4   22   15  251   1 0.02 18.69
5   22   15  598   1 0.02 18.69
6   21   19  250   1 0.02 20.21
7   22   20  251   1 0.02 18.69
8   22   20  598   1 0.02 18.69
 x.mat - matrix(NA, 95, 55)  # create matrix
 x.mat[cbind(x$xloc, x$yloc)] - x$totW
 which(!is.na(x.mat), arr.ind =TRUE)
 row col
[1,]  22  15
[2,]  21  19
[3,]  22  20
[4,]  23  20



On Sat, Mar 19, 2011 at 5:29 PM, Nicolas Gutierrez nicol...@uw.edu wrote:
 Hello,

 I'm trying to create a matrix (95x55) with data from a data.frame pop:

  xloc yloc      go  ind    Ene     totW
  1    23  20   516   1     0.02   20.21
  2    23  20  1143   1     0.02   20.21
  3    23  20   250   1     0.02   20.21
  4    22  15   251   1     0.02   18.69
  5    22  15   598   1     0.02   18.69
  6    21  19   250   1     0.02   20.21
  7    22  20   251   1     0.02   18.69
  8    22  20   598   1     0.02   18.69

 where xloc is the x dimension,  yloc the y dimension, and totW the values
 for each cell (xloc,yloc) in my matrix (55x95):

 I'm trying:

 Bio=with(pop, (table(factor(totW, levels = 1:55), factor(totW, levels =
 1:95

 But I don't get what I want. Hints? Thanks!

 Nic

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

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


Re: [R] Plotting graph problem!!

2011-03-19 Thread Jim Lemon

On 03/20/2011 04:33 AM, andrew456 wrote:

Thanks a lot for teaching me!!! By the way,one more question,how do i plot a
boxplot of that??


Hi Andrew,
As you seem to be an R newbie and some of the replies may have been 
cryptic to a newbie, try this:


boxplot(a$Life.Expectancies.at.Birth)

To explain the above a little bit, when reading in a text file, R does 
some silent substitutions, like sticking full stops (.) in where there 
were spaces in the field labels. The dollar sign operator means return 
the list element of a - a data frame column in this case - that has 
the name after the dollar sign. That gives the boxplot function a 
vector of numeric values and it knows what to do. These things are so 
familiar to most of us that we don't bother to explain them. You will 
probably encounter more of these little mysteries as you progress with 
R. Good luck.


Jim

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


Re: [R] create a matrix with values from data.frame

2011-03-19 Thread Nicolas Gutierrez

Thanks Jim and David.. that was easy!

Nic

On 3/19/2011 3:00 PM, jim holtman wrote:

x.mat- matrix(NA, 95, 55)  # create matrix

 x.mat[cbind(x$xloc, x$yloc)]- x$totW
 which(!is.na(x.mat), arr.ind =TRUE)


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


[R] I want to create an object to use for the plot command

2011-03-19 Thread AOLeary
I'm using the TSA package (along with all prerequisites) to do some GARCH
work and for some reason, something which used to work for me has decided to
up and stop. The code is as follows, after loading the package:


gs - garch.sim(alpha=c(1.9,0.1), beta=c(0.71, -0.083, -0.016),rnd =
rnorm, n = 400, ntrans=500) 

gs1 - garch.sim(alpha=c(1.9,0.1), beta=c(0.7, -0.08, -0.016),rnd = rnorm, n
= 400, ntrans=500) 

gts=ts(gs)

gts1=ts(gs1)

dgts=gts1-gts

test - garch(dgts, order=c(0,0))

plot(test)


However, I get the following error:


Error in plot(test) : object 'test' not found


What's extra annoying is that I had been using this type of code before and
it was working fine, I honestly don't know what the problem is, I've used R
reasonable extensively before but never with these packages so I'm not sure
what I might have done wrong.

If anyone could take the time to help me out, I'd really appreciate it.

Yours etc,
Aodhán



--
View this message in context: 
http://r.789695.n4.nabble.com/I-want-to-create-an-object-to-use-for-the-plot-command-tp3390383p3390383.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Referring to objects themselves

2011-03-19 Thread Russ Abbott
Is it possible to refer to an object from within a method, as in *this *in
Java?  I can't find anything about this in the documentation.  Sorry if I
missed it.

Thanks.

*-- Russ Abbott*
*_*
***  Professor, Computer Science*
*  California State University, Los Angeles*

*  Google voice: 747-*999-5105
*  blog: *http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
*_*

[[alternative HTML version deleted]]

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


Re: [R] I want to create an object to use for the plot command

2011-03-19 Thread David Winsemius


On Mar 19, 2011, at 7:02 PM, AOLeary wrote:

I'm using the TSA package (along with all prerequisites) to do some  
GARCH
work and for some reason, something which used to work for me has  
decided to

up and stop. The code is as follows, after loading the package:


gs - garch.sim(alpha=c(1.9,0.1), beta=c(0.71, -0.083,  
-0.016),rnd =

rnorm, n = 400, ntrans=500)

gs1 - garch.sim(alpha=c(1.9,0.1), beta=c(0.7, -0.08, -0.016),rnd =  
rnorm, n

= 400, ntrans=500)

gts=ts(gs)

gts1=ts(gs1)

dgts=gts1-gts

test - garch(dgts, order=c(0,0))

plot(test)


However, I get the following error:


Actually you failed to note that you got an earlier error from the  
garch() function:


Error in sigt[1:max(order[1], order[2])] - rep.int(NA, max(order[1],  :
  replacement has length zero

Which raises the question... what does it mean to specify a GARCH  
model of order c(0,0)?


--
David.





Error in plot(test) : object 'test' not found


What's extra annoying is that I had been using this type of code  
before and
it was working fine, I honestly don't know what the problem is, I've  
used R
reasonable extensively before but never with these packages so I'm  
not sure

what I might have done wrong.

If anyone could take the time to help me out, I'd really appreciate  
it.


Yours etc,
Aodhán



--
View this message in context: 
http://r.789695.n4.nabble.com/I-want-to-create-an-object-to-use-for-the-plot-command-tp3390383p3390383.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Gabor Grothendieck
On Sat, Mar 19, 2011 at 6:34 PM, Russ Abbott russ.abb...@gmail.com wrote:
 Is it possible to refer to an object from within a method, as in *this *in
 Java?  I can't find anything about this in the documentation.  Sorry if I
 missed it.


Assuming you are referring to S3, the first argument to a method is
the object (unless specified otherwise in the UseMethod call but that
is rarely done).


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] I want to create an object to use for the plot command

2011-03-19 Thread AOLeary
Hm, thank you David, that is a good point.

I'm trying to model it as a white noise model, essentially. Now that I think
of it there's probably an easier way to do this that I haven't thought of
yet. 

I was trying it this way based on something I'd remembered reading from
Engle's original paper on ARCH models where an ARCH(0,0) model would
correspond to a white noise process. It may be that the GARCH implementation
in R has a different specification.

In any case, thank you for pointing that out. A simple error I hadn't
noticed at all.

Yours etc,
Aodhán

--
View this message in context: 
http://r.789695.n4.nabble.com/I-want-to-create-an-object-to-use-for-the-plot-command-tp3390383p3390444.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Russ Abbott
Actually, I guess I'm not really talking about objects. I was looking
through the scoping demo. It uses this function.

 open.account - function(total) {

+

+ list(

+deposit = function(amount) {

+if(amount = 0)

+stop(Deposits must be positive!\n)

+total - total + amount

+cat(amount,deposited. Your balance is, total, \n\n)

+},

+withdraw = function(amount) {

+if(amount  total)

+stop(You don't have that much money!\n)

+total - total - amount

+cat(amount,withdrawn.  Your balance is, total, \n\n)

+},

+balance = function() {

+cat(Your balance is, total, \n\n)

+}

+)

+ }


I wanted to re-write the function so that instead of referring to *total *in
*deposit *and *withdraw *I could refer to *balance*. Something like this,


withdraw = function(amount) {
+if(amount  total)
+stop(You don't have that much money!\n)
 +total - total - amount
+cat(amount,withdrawn.  Your balance is, *this,balance()*,
\n\n)

But that doesn't work. Is it possible to do this?

Thanks.

*-- Russ Abbott*
*_*
***  Professor, Computer Science*
*  California State University, Los Angeles*

*  Google voice: 747-*999-5105
*  blog: *http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
*_*



On Sat, Mar 19, 2011 at 4:40 PM, Gabor Grothendieck ggrothendi...@gmail.com
 wrote:

 On Sat, Mar 19, 2011 at 6:34 PM, Russ Abbott russ.abb...@gmail.com
 wrote:
  Is it possible to refer to an object from within a method, as in *this
 *in
  Java?  I can't find anything about this in the documentation.  Sorry if I
  missed it.
 

 Assuming you are referring to S3, the first argument to a method is
 the object (unless specified otherwise in the UseMethod call but that
 is rarely done).


 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com


[[alternative HTML version deleted]]

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


[R] How to draw a map of Europe?

2011-03-19 Thread Sally Luo
Hi R users,

I need to draw a map of select European countries with country names shown
on the map.  Does anyone know how to do this in R?

Also, is it possible to draw a historical map of European countries using R?

Thanks a lot for your help.

Maomao

[[alternative HTML version deleted]]

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Janko Thyson
You might want to check out Reference Classes (?SetRefClass). The object
itself is stored in '.self' and can be referenced that way.

HTH,
Janko

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Russ Abbott
Gesendet: Samstag, 19. März 2011 23:35
An: r-help@r-project.org
Betreff: [R] Referring to objects themselves

Is it possible to refer to an object from within a method, as in *this *in
Java?  I can't find anything about this in the documentation.  Sorry if I
missed it.

Thanks.

*-- Russ Abbott*
*_*
***  Professor, Computer Science*
*  California State University, Los Angeles*

*  Google voice: 747-*999-5105
*  blog: *http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
*_*

[[alternative HTML version deleted]]

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

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Gabor Grothendieck
On Sat, Mar 19, 2011 at 8:02 PM, Russ Abbott russ.abb...@gmail.com wrote:
 Actually, I guess I'm not really talking about objects. I was looking
 through the scoping demo. It uses this function.

 open.account - function(total) {

 +

 +     list(

 +        deposit = function(amount) {

 +            if(amount = 0)

 +                stop(Deposits must be positive!\n)

 +            total - total + amount

 +            cat(amount,deposited. Your balance is, total, \n\n)

 +        },

 +        withdraw = function(amount) {

 +            if(amount  total)

 +                stop(You don't have that much money!\n)

 +            total - total - amount

 +            cat(amount,withdrawn.  Your balance is, total, \n\n)

 +        },

 +        balance = function() {

 +            cat(Your balance is, total, \n\n)

 +        }

 +        )

 + }

 I wanted to re-write the function so that instead of referring to total in
 deposit and withdraw I could refer to balance. Something like this,

 withdraw = function(amount) {
 +            if(amount  total)
 +                stop(You don't have that much money!\n)
 +            total - total - amount
 +            cat(amount,withdrawn.  Your balance is, this,balance(),
 \n\n)

 But that doesn't work. Is it possible to do this?
 Thanks.


Try this:

open.account - function(total) {
this - environment()
list(...same list as before...)
}

Now within the body of any of the methods in the list, this$total
refers to the balance.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Kenn Konstabel
You could (in addition to the other suggestions) try package proto (. refers
to self but see also the package's vignette)

account - proto(
deposit = function(., amount) {
if(amount = 0)  stop(Deposits must be positive!\n)
.$total - .$total + amount
cat(amount,deposited. )
.$balance()
},
withdraw = function(., amount) {
if(amount  .$total)  stop(You don't have that much money!\n)
.$total - .$total - amount
cat(amount,withdrawn. )
.$balance()
 },
balance = function(.) {
cat(Your balance is, .$total, \n\n)
   },
new = function(., total) .$proto(total = total)
 )

a - account$new(10)
a$withdraw(10)
a$balance()


On Sun, Mar 20, 2011 at 2:02 AM, Russ Abbott russ.abb...@gmail.com wrote:

 Actually, I guess I'm not really talking about objects. I was looking
 through the scoping demo. It uses this function.

  open.account - function(total) {

 +

 + list(

 +deposit = function(amount) {

 +if(amount = 0)

 +stop(Deposits must be positive!\n)

 +total - total + amount

 +cat(amount,deposited. Your balance is, total, \n\n)

 +},

 +withdraw = function(amount) {

 +if(amount  total)

 +stop(You don't have that much money!\n)

 +total - total - amount

 +cat(amount,withdrawn.  Your balance is, total, \n\n)

 +},

 +balance = function() {

 +cat(Your balance is, total, \n\n)

 +}

 +)

 + }


 I wanted to re-write the function so that instead of referring to *total
 *in
 *deposit *and *withdraw *I could refer to *balance*. Something like this,


 withdraw = function(amount) {
 +if(amount  total)
 +stop(You don't have that much money!\n)
  +total - total - amount
 +cat(amount,withdrawn.  Your balance is, *this,balance()*,
 \n\n)

 But that doesn't work. Is it possible to do this?

 Thanks.

 *-- Russ Abbott*
 *_*
 ***  Professor, Computer Science*
 *  California State University, Los Angeles*

 *  Google voice: 747-*999-5105
 *  blog: *http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
 *_*



 On Sat, Mar 19, 2011 at 4:40 PM, Gabor Grothendieck 
 ggrothendi...@gmail.com
  wrote:

  On Sat, Mar 19, 2011 at 6:34 PM, Russ Abbott russ.abb...@gmail.com
  wrote:
   Is it possible to refer to an object from within a method, as in *this
  *in
   Java?  I can't find anything about this in the documentation.  Sorry if
 I
   missed it.
  
 
  Assuming you are referring to S3, the first argument to a method is
  the object (unless specified otherwise in the UseMethod call but that
  is rarely done).
 
 
  --
  Statistics  Software Consulting
  GKX Group, GKX Associates Inc.
  tel: 1-877-GKX-GROUP
  email: ggrothendieck at gmail.com
 

 [[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


Re: [R] How to draw a map of Europe?

2011-03-19 Thread Mike Marchywka








 Date: Sat, 19 Mar 2011 19:32:43 -0500
 From: shali...@gmail.com
 To: r-help@r-project.org
 Subject: [R] How to draw a map of Europe?

 Hi R users,

 I need to draw a map of select European countries with country names shown
 on the map. Does anyone know how to do this in R?

 Also, is it possible to draw a historical map of European countries using R?

This came up on this list a while ago and I was just using that example
for some work I'm doing but I have only copied what was posted
and added minor things to it. I can't give you actual answer
but you are probably just a few key words away from a google searhc.
 The term you are probably looking for
is shapefile. Try that on google. For example,

http://www.google.com/#sclient=psyhl=enq=shapefile+cran+europe

turns up things that may help.





 Thanks a lot for your help.

 Maomao

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


[R] Problems with package npmc

2011-03-19 Thread carloskij
Hi there,

I am having a problem with package npmc. If I use the included datasets
(brain, kronen) everything is fine, but if I try and use my dataset I
receive an error message:

Error in probval.GenzBretz(algorithm, n, df, lower, upper, infin, corr,  : 
  NAs in foreign function call (arg 2)
In addition: Warning message:
In probval.GenzBretz(algorithm, n, df, lower, upper, infin, corr,  :
  NAs introduced by coercion 

I couldn't solve the problem.

C.

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

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Bert Gunter
See also the proto package, I believe.

-- Bert

On Sat, Mar 19, 2011 at 5:51 PM, Janko Thyson
janko.thyson.rst...@googlemail.com wrote:
 You might want to check out Reference Classes (?SetRefClass). The object
 itself is stored in '.self' and can be referenced that way.

 HTH,
 Janko

 -Ursprüngliche Nachricht-
 Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
 Auftrag von Russ Abbott
 Gesendet: Samstag, 19. März 2011 23:35
 An: r-help@r-project.org
 Betreff: [R] Referring to objects themselves

 Is it possible to refer to an object from within a method, as in *this *in
 Java?  I can't find anything about this in the documentation.  Sorry if I
 missed it.

 Thanks.

 *-- Russ Abbott*
 *_*
 ***  Professor, Computer Science*
 *  California State University, Los Angeles*

 *  Google voice: 747-*999-5105
 *  blog: *http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
 *_*

        [[alternative HTML version deleted]]

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

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




-- 
Bert Gunter
Genentech Nonclinical Biostatistics

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Russ Abbott
Thanks for all the suggestions. I realize that this isn't the most important
thing in the world -- and as a newcomer to R I gather it's not the way most
people use R anyway.

But I tried to do what looked like the simplest suggestion.

open.account.2 - function(total) {
   this - environment()
   list(
 deposit = function(amount) {
   if(amount = 0)
 stop(Deposits must be positive!\n)
   total - total + amount
   cat(amount, deposited.  Your balance is, this$balance(),
\n\n)
 },
 withdraw = function(amount) {
   if(amount  total)
 stop(You don't have that much money!\n)
   total - total - amount
   cat(amount, withdrawn.  Your balance is, this$balance(),
\n\n)
 },
 balance = function() {
   cat(Your balance is, this$total, \n\n)
 }
   )
 }

When I ran it, this is what happened.

 x - open.account.2(100)
 x$balance()

Your balance is 100

OK so far. But

 x$deposit(50)
Error in cat(amount, deposited.  Your balance is, this$balance(), \n\n)
:
  attempt to apply non-function


Am I doing this the wrong way?

Thanks for your interest.

*-- Russ *



On Sat, Mar 19, 2011 at 6:33 PM, Bert Gunter gunter.ber...@gene.com wrote:

 See also the proto package, I believe.

 -- Bert

 On Sat, Mar 19, 2011 at 5:51 PM, Janko Thyson
 janko.thyson.rst...@googlemail.com wrote:
  You might want to check out Reference Classes (?SetRefClass). The object
  itself is stored in '.self' and can be referenced that way.
 
  HTH,
  Janko
 
  -Ursprüngliche Nachricht-
  Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 Im
  Auftrag von Russ Abbott
  Gesendet: Samstag, 19. März 2011 23:35
  An: r-help@r-project.org
  Betreff: [R] Referring to objects themselves
 
  Is it possible to refer to an object from within a method, as in *this
 *in
  Java?  I can't find anything about this in the documentation.  Sorry if I
  missed it.
 
  Thanks.
 
  *-- Russ Abbott*
  *_*
  ***  Professor, Computer Science*
  *  California State University, Los Angeles*
 
  *  Google voice: 747-*999-5105
  *  blog: *http://russabbott.blogspot.com/
   vita:  http://sites.google.com/site/russabbott/
  *_*
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 



 --
 Bert Gunter
 Genentech Nonclinical Biostatistics


[[alternative HTML version deleted]]

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


Re: [R] How to draw a map of Europe?

2011-03-19 Thread David Winsemius


On Mar 19, 2011, at 8:32 PM, Sally Luo wrote:


Hi R users,

I need to draw a map of select European countries with country names  
shown

on the map.  Does anyone know how to do this in R?


Adding a tiny bit to the material produced from a search and finding  
something from Roger Bivand in response to Rense Nieuwenhuis:


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

require(maps)

 country2001 - c(Austria, Belgium, Switzerland,
 Czechoslovakia, Germany, Denmark, Spain, Finland, France,
 UK, Greece, Hungary, Ireland, Israel, Italy,
 Luxembourg, Netherlands, Norway, Poland, Portugal,
 Sweden, Slovenia)
 color2001 - c(green, yellow,red,red, red, red, red,
 red, green, red, red, red, red, red, red, red,
 red, blue, red, red, red, orange)

europe$names[grep(Sicily, europe$names)] - Italy:Sicily
europe$names[grep(Sardinia, europe$names)] - Italy:Sardinia
match - match.map(europe,country2001)
color - color2001[match]
map(database=world, fill=TRUE, col=color,  
xlim=c(-25,70),ylim=c(35,71))


text(0, 45, France)




Also, is it possible to draw a historical map of European countries  
using R?


Thanks a lot for your help.

Maomao

[[alternative HTML version deleted]]

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Kenn Konstabel
you can omit the list and do the following:

open.account.2 - function(total) {
 deposit - function(amount) {
  if(amount = 0)
stop(Deposits must be positive!\n)
  total - total + amount
  cat(amount, deposited.  Your balance is, this$balance(),\n\n)
}
 withdraw - function(amount) {
  if(amount  total)
stop(You don't have that much money!\n)
  total - total - amount
  cat(amount, withdrawn.  Your balance is, this$balance(),\n\n)
}
balance - function() {
  cat(Your balance is, this$total, \n\n)
}
this - environment()
}


But notice that the function balance returns nothing (because of the cat)
and balance message will be printed (cat'ed) doubly - this is easy to fix.
(but you don't really need this in this case as you can use balance
instead of this$balance)

The last row does two things: invisibly returns the environment (necessary
for things like x$balance()) and assigns it to this

Regards,

Kenn

On Sun, Mar 20, 2011 at 3:45 AM, Russ Abbott russ.abb...@gmail.com wrote:

 Thanks for all the suggestions. I realize that this isn't the most
 important
 thing in the world -- and as a newcomer to R I gather it's not the way most
 people use R anyway.

 But I tried to do what looked like the simplest suggestion.

 open.account.2 - function(total) {
   this - environment()
list(
 deposit = function(amount) {
   if(amount = 0)
 stop(Deposits must be positive!\n)
   total - total + amount
cat(amount, deposited.  Your balance is, this$balance(),
 \n\n)
 },
 withdraw = function(amount) {
   if(amount  total)
 stop(You don't have that much money!\n)
   total - total - amount
cat(amount, withdrawn.  Your balance is, this$balance(),
 \n\n)
 },
 balance = function() {
   cat(Your balance is, this$total, \n\n)
 }
   )
 }

 When I ran it, this is what happened.

  x - open.account.2(100)
  x$balance()

 Your balance is 100

 OK so far. But

  x$deposit(50)
 Error in cat(amount, deposited.  Your balance is, this$balance(), \n\n)
 :
  attempt to apply non-function


 Am I doing this the wrong way?

 Thanks for your interest.

 *-- Russ *



 On Sat, Mar 19, 2011 at 6:33 PM, Bert Gunter gunter.ber...@gene.com
 wrote:

  See also the proto package, I believe.
 
  -- Bert
 
  On Sat, Mar 19, 2011 at 5:51 PM, Janko Thyson
  janko.thyson.rst...@googlemail.com wrote:
   You might want to check out Reference Classes (?SetRefClass). The
 object
   itself is stored in '.self' and can be referenced that way.
  
   HTH,
   Janko
  
   -Ursprüngliche Nachricht-
   Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org
 ]
  Im
   Auftrag von Russ Abbott
   Gesendet: Samstag, 19. März 2011 23:35
   An: r-help@r-project.org
   Betreff: [R] Referring to objects themselves
  
   Is it possible to refer to an object from within a method, as in *this
  *in
   Java?  I can't find anything about this in the documentation.  Sorry if
 I
   missed it.
  
   Thanks.
  
   *-- Russ Abbott*
   *_*
   ***  Professor, Computer Science*
   *  California State University, Los Angeles*
  
   *  Google voice: 747-*999-5105
   *  blog: *http://russabbott.blogspot.com/
vita:  http://sites.google.com/site/russabbott/
   *_*
  
  [[alternative HTML version deleted]]
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
 
 
 
  --
  Bert Gunter
  Genentech Nonclinical Biostatistics
 

 [[alternative HTML version deleted]]


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



[[alternative HTML version deleted]]

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


Re: [R] Part of a density plot

2011-03-19 Thread Jim Silverton
Suupose I have
y - rbeta(1, 2, 5)
and I only want to see only the density plot from x = 0 to x = 1
How do I do this?

-- 
Thanks,
Jim.

[[alternative HTML version deleted]]

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Kenn Konstabel
On Sun, Mar 20, 2011 at 4:13 AM, Kenn Konstabel lebats...@gmail.com wrote:

 you can omit the list and do the following:


 /.../

  (but you don't really need this in this case as you can use balance
 instead of this$balance)


P.S. using this would make some difference in one case:

instead of
  total - total + amount # need - here
you can have
   this$total - this$total + amount # can use -

[[alternative HTML version deleted]]

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


Re: [R] How would you avoid loops in this simple example?

2011-03-19 Thread zerfetzen
Thanks for the help, and now I have some functions to learn. Both suggestions
work great, really appreciate it.

--
View this message in context: 
http://r.789695.n4.nabble.com/How-would-you-avoid-loops-in-this-simple-example-tp3390017p3390549.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to draw a map of Europe?

2011-03-19 Thread Spencer Graves
  I've created historical maps using R, but it required careful 
research, translating the boundaries into longitude and latitude shape 
files, then plotting them, similar to the example that David just 
provided.  It seemed to be the easiest way I knew to produce the desired 
result, but it still took a moderate level of effort.



  Hope this helps.
  Spencer Graves


On 3/19/2011 6:51 PM, David Winsemius wrote:


On Mar 19, 2011, at 8:32 PM, Sally Luo wrote:


Hi R users,

I need to draw a map of select European countries with country names 
shown

on the map.  Does anyone know how to do this in R?


Adding a tiny bit to the material produced from a search and finding 
something from Roger Bivand in response to Rense Nieuwenhuis:


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

require(maps)

 country2001 - c(Austria, Belgium, Switzerland,
 Czechoslovakia, Germany, Denmark, Spain, Finland, France,
 UK, Greece, Hungary, Ireland, Israel, Italy,
 Luxembourg, Netherlands, Norway, Poland, Portugal,
 Sweden, Slovenia)
 color2001 - c(green, yellow,red,red, red, red, red,
 red, green, red, red, red, red, red, red, red,
 red, blue, red, red, red, orange)

europe$names[grep(Sicily, europe$names)] - Italy:Sicily
europe$names[grep(Sardinia, europe$names)] - Italy:Sardinia
match - match.map(europe,country2001)
color - color2001[match]
map(database=world, fill=TRUE, col=color, xlim=c(-25,70),ylim=c(35,71))

text(0, 45, France)




Also, is it possible to draw a historical map of European countries 
using R?


Thanks a lot for your help.

Maomao

[[alternative HTML version deleted]]


David Winsemius, MD
West Hartford, CT

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

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



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


Re: [R] Part of a density plot

2011-03-19 Thread Ravi Varadhan
Take a look at pvladens() function in bootruin package.

Ravi.



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

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


- Original Message -
From: Jim Silverton jim.silver...@gmail.com
Date: Saturday, March 19, 2011 10:16 pm
Subject: Re: [R] Part of a density plot
To: r-help@r-project.org


 Suupose I have
  y - rbeta(1, 2, 5)
  and I only want to see only the density plot from x = 0 to x = 1
  How do I do this?
  
  -- 
  Thanks,
  Jim.
  
   [[alternative HTML version deleted]]
  
  __
  R-help@r-project.org mailing list
  
  PLEASE do read the posting guide 
  and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Part of a density plot

2011-03-19 Thread Peter Ehlers

On 2011-03-19 19:15, Jim Silverton wrote:

Suupose I have
y- rbeta(1, 2, 5)
and I only want to see only the density plot from x = 0 to x = 1
How do I do this?


I'm not quite sure what you want, but this may be it:

 plot(density(y), xlim = c(0, 1), xaxs = 'i')

Peter Ehlers

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Russ Abbott
Wonderful! Thanks.  I think I've got it.

You can even put

   this - environment() at the top

as long as

   this

is returned at the end.

I gather that the environment keeps accumulating elements even though it is
assigned to 'this' at the beginning.

I had thought that $ worked only on lists, but I guess it works on
environment objects also.


 typeof(x)
[1] environment
 is.list(x)
[1] FALSE



*-- Russ *
*_*
***  Professor, Computer Science*
*  California State University, Los Angeles*

*  Google voice: 747-*999-5105
*  blog: *http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
*_*



On Sat, Mar 19, 2011 at 7:21 PM, Kenn Konstabel lebats...@gmail.com wrote:

 On Sun, Mar 20, 2011 at 4:13 AM, Kenn Konstabel lebats...@gmail.comwrote:

  you can omit the list and do the following:


 /.../

  (but you don't really need this in this case as you can use balance
 instead of this$balance)


 P.S. using this would make some difference in one case:

 instead of
   total - total + amount # need - here
 you can have
this$total - this$total + amount # can use -



[[alternative HTML version deleted]]

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


Re: [R] Referring to objects themselves

2011-03-19 Thread Gabor Grothendieck
On Sat, Mar 19, 2011 at 9:45 PM, Russ Abbott russ.abb...@gmail.com wrote:
 Thanks for all the suggestions. I realize that this isn't the most important
 thing in the world -- and as a newcomer to R I gather it's not the way most
 people use R anyway.

 But I tried to do what looked like the simplest suggestion.

 open.account.2 - function(total) {
       this - environment()
       list(
         deposit = function(amount) {
           if(amount = 0)
             stop(Deposits must be positive!\n)
           total - total + amount
           cat(amount, deposited.  Your balance is, this$balance(),
 \n\n)
         },
         withdraw = function(amount) {
           if(amount  total)
             stop(You don't have that much money!\n)
           total - total - amount
           cat(amount, withdrawn.  Your balance is, this$balance(),
 \n\n)
         },
         balance = function() {
           cat(Your balance is, this$total, \n\n)
         }
       )
     }

 When I ran it, this is what happened.

 x - open.account.2(100)
 x$balance()

 Your balance is 100

 OK so far. But

 x$deposit(50)
 Error in cat(amount, deposited.  Your balance is, this$balance(), \n\n)
 :
  attempt to apply non-function


 Am I doing this the wrong way?

 Thanks for your interest.


balance is a component of the list. Its not directly a component of
this.  If you name the list you can refer to it as
this$methods$balance


open.account.2 - function(total) {
       this - environment()
       methods - list(...whatever...)
 }




-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Problems with package npmc

2011-03-19 Thread Peter Ehlers

On 2011-03-19 17:27, carloskij wrote:

Hi there,

I am having a problem with package npmc. If I use the included datasets
(brain, kronen) everything is fine, but if I try and use my dataset I
receive an error message:


So somehow your own dataset does not comply with
the requirements of npmc. Since we don't have your
data, only you can tell what's wrong.



Error in probval.GenzBretz(algorithm, n, df, lower, upper, infin, corr,  :
   NAs in foreign function call (arg 2)
In addition: Warning message:
In probval.GenzBretz(algorithm, n, df, lower, upper, infin, corr,  :
   NAs introduced by coercion


The error msg comes from mvtnorm. Obviously, it's not
happy with the arguments it's getting.

Provide more details as per the posting guide.
A *minimal* reproducible example (i.e. data + code)
would be best.

Peter Ehlers



I couldn't solve the problem.

C.

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

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


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


Re: [R] Referring to objects themselves

2011-03-19 Thread Henrik Bengtsson
For most standard things we do in R, one do not need this feature.  R
is a functional language.  Everything is passed around as
pass-by-value (but in a smart way so that under the hood you get
pass-by-reference in most cases).   Reference variables become useful
first when you for instance have more complex and larger objects, and
also when you work toward external resources, e.g. data bases,
persistent memory, web sites etc.

If you need true pass-by-reference, it is possible to obtain this in R
at a low-resolution granularity, which means, you can do it for basic
R data types (vectors, lists, ...) but not (really) for single
elements of such data types.  In R the 'environment' data type acts as
a container for other data types.  You can update the objects inside
the environment and pass it around as if it was a reference variable.

As already suggested, the proto and the R.oo packages utilize
environment.  Recently Reference Classes joined and is now part of
core R. (There are other difference between these too.)

So, if you're new to R and don't really need reference variables (most
people don't), rethink how you think of classes and objects in R (=
think functional language).  Though, you would learn lots by playing
around with environments and scopes and R's method dispatching
mechanisms.

/Henrik

On Sat, Mar 19, 2011 at 6:45 PM, Russ Abbott russ.abb...@gmail.com wrote:
 Thanks for all the suggestions. I realize that this isn't the most important
 thing in the world -- and as a newcomer to R I gather it's not the way most
 people use R anyway.

 But I tried to do what looked like the simplest suggestion.

 open.account.2 - function(total) {
       this - environment()
       list(
         deposit = function(amount) {
           if(amount = 0)
             stop(Deposits must be positive!\n)
           total - total + amount
           cat(amount, deposited.  Your balance is, this$balance(),
 \n\n)
         },
         withdraw = function(amount) {
           if(amount  total)
             stop(You don't have that much money!\n)
           total - total - amount
           cat(amount, withdrawn.  Your balance is, this$balance(),
 \n\n)
         },
         balance = function() {
           cat(Your balance is, this$total, \n\n)
         }
       )
     }

 When I ran it, this is what happened.

 x - open.account.2(100)
 x$balance()

 Your balance is 100

 OK so far. But

 x$deposit(50)
 Error in cat(amount, deposited.  Your balance is, this$balance(), \n\n)
 :
  attempt to apply non-function


 Am I doing this the wrong way?

 Thanks for your interest.

 *-- Russ *



 On Sat, Mar 19, 2011 at 6:33 PM, Bert Gunter gunter.ber...@gene.com wrote:

 See also the proto package, I believe.

 -- Bert

 On Sat, Mar 19, 2011 at 5:51 PM, Janko Thyson
 janko.thyson.rst...@googlemail.com wrote:
  You might want to check out Reference Classes (?SetRefClass). The object
  itself is stored in '.self' and can be referenced that way.
 
  HTH,
  Janko
 
  -Ursprüngliche Nachricht-
  Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 Im
  Auftrag von Russ Abbott
  Gesendet: Samstag, 19. März 2011 23:35
  An: r-help@r-project.org
  Betreff: [R] Referring to objects themselves
 
  Is it possible to refer to an object from within a method, as in *this
 *in
  Java?  I can't find anything about this in the documentation.  Sorry if
  I
  missed it.
 
  Thanks.
 
  *-- Russ Abbott*
  *_*
  ***  Professor, Computer Science*
  *  California State University, Los Angeles*
 
  *  Google voice: 747-*999-5105
  *  blog: *http://russabbott.blogspot.com/
   vita:  http://sites.google.com/site/russabbott/
  *_*
 
         [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 



 --
 Bert Gunter
 Genentech Nonclinical Biostatistics


        [[alternative HTML version deleted]]


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



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

Re: [R] Referring to objects themselves

2011-03-19 Thread Russ Abbott
Actually I'm a big Haskell fan. So I think of functional programming very
positively.  However, the environment() function doesn't seem to be treated
functionally.  If I write
this - environment()
at the top of the previous example, the other functions and the variables
they are bound to are inserted into the environment which had already been
bound to 'this' afterwards.

In fact, even when it is left at the end that line inserts 'this' into the
environment, which strictly speaking it shouldn't do. So there seem to be
some not-quite-functional processes going on.

*-- Russ*



On Sat, Mar 19, 2011 at 8:56 PM, Henrik Bengtsson h...@biostat.ucsf.eduwrote:

 For most standard things we do in R, one do not need this feature.  R
 is a functional language.  Everything is passed around as
 pass-by-value (but in a smart way so that under the hood you get
 pass-by-reference in most cases).   Reference variables become useful
 first when you for instance have more complex and larger objects, and
 also when you work toward external resources, e.g. data bases,
 persistent memory, web sites etc.

 If you need true pass-by-reference, it is possible to obtain this in R
 at a low-resolution granularity, which means, you can do it for basic
 R data types (vectors, lists, ...) but not (really) for single
 elements of such data types.  In R the 'environment' data type acts as
 a container for other data types.  You can update the objects inside
 the environment and pass it around as if it was a reference variable.

 As already suggested, the proto and the R.oo packages utilize
 environment.  Recently Reference Classes joined and is now part of
 core R. (There are other difference between these too.)

 So, if you're new to R and don't really need reference variables (most
 people don't), rethink how you think of classes and objects in R (=
 think functional language).  Though, you would learn lots by playing
 around with environments and scopes and R's method dispatching
 mechanisms.

 /Henrik

 On Sat, Mar 19, 2011 at 6:45 PM, Russ Abbott russ.abb...@gmail.com
 wrote:
  Thanks for all the suggestions. I realize that this isn't the most
 important
  thing in the world -- and as a newcomer to R I gather it's not the way
 most
  people use R anyway.
 
  But I tried to do what looked like the simplest suggestion.
 
  open.account.2 - function(total) {
this - environment()
list(
  deposit = function(amount) {
if(amount = 0)
  stop(Deposits must be positive!\n)
total - total + amount
cat(amount, deposited.  Your balance is, this$balance(),
  \n\n)
  },
  withdraw = function(amount) {
if(amount  total)
  stop(You don't have that much money!\n)
total - total - amount
cat(amount, withdrawn.  Your balance is, this$balance(),
  \n\n)
  },
  balance = function() {
cat(Your balance is, this$total, \n\n)
  }
)
  }
 
  When I ran it, this is what happened.
 
  x - open.account.2(100)
  x$balance()
 
  Your balance is 100
 
  OK so far. But
 
  x$deposit(50)
  Error in cat(amount, deposited.  Your balance is, this$balance(),
 \n\n)
  :
   attempt to apply non-function
 
 
  Am I doing this the wrong way?
 
  Thanks for your interest.
 
  *-- Russ *
 
 
 
  On Sat, Mar 19, 2011 at 6:33 PM, Bert Gunter gunter.ber...@gene.com
 wrote:
 
  See also the proto package, I believe.
 
  -- Bert
 
  On Sat, Mar 19, 2011 at 5:51 PM, Janko Thyson
  janko.thyson.rst...@googlemail.com wrote:
   You might want to check out Reference Classes (?SetRefClass). The
 object
   itself is stored in '.self' and can be referenced that way.
  
   HTH,
   Janko
  
   -Ursprüngliche Nachricht-
   Von: r-help-boun...@r-project.org [mailto:
 r-help-boun...@r-project.org]
  Im
   Auftrag von Russ Abbott
   Gesendet: Samstag, 19. März 2011 23:35
   An: r-help@r-project.org
   Betreff: [R] Referring to objects themselves
  
   Is it possible to refer to an object from within a method, as in *this
  *in
   Java?  I can't find anything about this in the documentation.  Sorry
 if
   I
   missed it.
  
   Thanks.
  
   *-- Russ Abbott*
   *_*
   ***  Professor, Computer Science*
   *  California State University, Los Angeles*
  
   *  Google voice: 747-*999-5105
   *  blog: *http://russabbott.blogspot.com/
vita:  http://sites.google.com/site/russabbott/
   *_*
  
  [[alternative HTML version deleted]]
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
   __
   R-help@r-project.org mailing list
   

Re: [R] Referring to objects themselves

2011-03-19 Thread Gabor Grothendieck
On Sun, Mar 20, 2011 at 12:10 AM, Russ Abbott russ.abb...@gmail.com wrote:
 Actually I'm a big Haskell fan. So I think of functional programming very
 positively.  However, the environment() function doesn't seem to be treated
 functionally.  If I write
    this - environment()
 at the top of the previous example, the other functions and the variables
 they are bound to are inserted into the environment which had already been
 bound to 'this' afterwards.

 In fact, even when it is left at the end that line inserts 'this' into the
 environment, which strictly speaking it shouldn't do. So there seem to be
 some not-quite-functional processes going on.


this - environment() does not create an environment.  It merely
allows this to refer to the environment that was already there and is
what holds the variables created during the execution of the function.


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


[R] R as a non-functional language

2011-03-19 Thread Russ Abbott
I'm reading Torgo (2010) *Data Mining with
R*http://www.liaad.up.pt/~ltorgo/DataMiningWithR/code.htmlin
preparation for a class I'll be teaching next quarter.  Here's an
example
that is very non-functional.

 pH - c(4.5,7,7.3,8.2,6.3)
 names(pH) - c('area1','area2','mud','dam','middle')
 pH
 area1  area2muddam middle
   4.57.07.38.26.3


This sort of thing seems to be quite common in R.

*-- Russ *

[[alternative HTML version deleted]]

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


Re: [R] R as a non-functional language

2011-03-19 Thread Gabor Grothendieck
On Sun, Mar 20, 2011 at 12:20 AM, Russ Abbott russ.abb...@gmail.com wrote:
 I'm reading Torgo (2010) *Data Mining with
 R*http://www.liaad.up.pt/~ltorgo/DataMiningWithR/code.htmlin
 preparation for a class I'll be teaching next quarter.  Here's an
 example
 that is very non-functional.

 pH - c(4.5,7,7.3,8.2,6.3)
 names(pH) - c('area1','area2','mud','dam','middle')
 pH
  area1  area2    mud    dam middle
   4.5    7.0    7.3    8.2    6.3


 This sort of thing seems to be quite common in R.

Try this:

pH - setNames(c(4.5,7,7.3,8.2,6.3), c('area1','area2','mud','dam','middle'))




-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] R as a non-functional language

2011-03-19 Thread Bill.Venables
The idiom I prefer is

pH - structure(c(4.5,7,7.3,8.2,6.3), 
names = c('area1','area2','mud','dam','middle')) 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Gabor Grothendieck
Sent: Sunday, 20 March 2011 2:33 PM
To: russ.abb...@gmail.com
Cc: r-help@r-project.org
Subject: Re: [R] R as a non-functional language

On Sun, Mar 20, 2011 at 12:20 AM, Russ Abbott russ.abb...@gmail.com wrote:
 I'm reading Torgo (2010) *Data Mining with
 R*http://www.liaad.up.pt/~ltorgo/DataMiningWithR/code.htmlin
 preparation for a class I'll be teaching next quarter.  Here's an
 example
 that is very non-functional.

 pH - c(4.5,7,7.3,8.2,6.3)
 names(pH) - c('area1','area2','mud','dam','middle')
 pH
  area1  area2    mud    dam middle
   4.5    7.0    7.3    8.2    6.3


 This sort of thing seems to be quite common in R.

Try this:

pH - setNames(c(4.5,7,7.3,8.2,6.3), c('area1','area2','mud','dam','middle'))




-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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

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


Re: [R] R as a non-functional language

2011-03-19 Thread Russ Abbott
I'm afraid I disagree.  As a number of people have shown, it's certainly
possible to get the end result

 pH - c(4.5,7,7.3,8.2,6.3)
 names(pH) - c('area1','area2','mud','dam','middle')
 pH
 area1  area2muddam middle
   4.57.07.38.26.3

using a single expression. But what makes this non-functional is that the
names() function operates on a reference to the pH object/entity/element. In
other words, the names() function has a side effect, which is not permitted
in strictly functional programming.

I don't know if R has threads. But imagine it did and that one ran

 names(pH) - c('area1','area2','mud','dam','middle')

and

  names(pH) - c('areaA','areaB','dirt','blockage','center')

in simultaneous threads. Since they are both operating on the same pH
element, it is uncertain what the result would be. That's one of the things
that functional programming prevents.

*-- Russ *



On Sat, Mar 19, 2011 at 10:22 PM, bill.venab...@csiro.au wrote:

 PS the form

 names(p) - c(...)

 is still functional, of course.  It is just a bit of syntactic sugar for
 the clumsier

 p - `names-`(p, c(...))

 e.g.
  pH - `names-`(pH, letters[1:5])
  pH
  a   b   c   d   e
 4.5 7.0 7.3 8.2 6.3
 



 -Original Message-
 From: Venables, Bill (CMIS, Dutton Park)
 Sent: Sunday, 20 March 2011 3:09 PM
 To: 'Gabor Grothendieck'; 'russ.abb...@gmail.com'
 Cc: 'r-help@r-project.org'
 Subject: RE: [R] R as a non-functional language

 The idiom I prefer is

 pH - structure(c(4.5,7,7.3,8.2,6.3),
names = c('area1','area2','mud','dam','middle'))

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Gabor Grothendieck
 Sent: Sunday, 20 March 2011 2:33 PM
 To: russ.abb...@gmail.com
 Cc: r-help@r-project.org
 Subject: Re: [R] R as a non-functional language

 On Sun, Mar 20, 2011 at 12:20 AM, Russ Abbott russ.abb...@gmail.com
 wrote:
  I'm reading Torgo (2010) *Data Mining with
  R*http://www.liaad.up.pt/~ltorgo/DataMiningWithR/code.htmlin
  preparation for a class I'll be teaching next quarter.  Here's an
  example
  that is very non-functional.
 
  pH - c(4.5,7,7.3,8.2,6.3)
  names(pH) - c('area1','area2','mud','dam','middle')
  pH
   area1  area2muddam middle
4.57.07.38.26.3
 
 
  This sort of thing seems to be quite common in R.

 Try this:

 pH - setNames(c(4.5,7,7.3,8.2,6.3),
 c('area1','area2','mud','dam','middle'))




 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com

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


[[alternative HTML version deleted]]

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


[R] Using the Mahalanobis Function

2011-03-19 Thread Tyler Rinker




Hello all,
 
I am a 2 month newbie to R and am stumped.  I have a data set that I've run 
multivariate stats on using the manova function (I included the data set).  Now 
it comes time for a table of effect sizes with significance.  The univariate 
tests are easy.  Where I run into trouble filling in the table of effect sizes 
is the Mahalanobis D as an effect size.  I've included the table so you can see 
what group's I'm comparing.  I know there's a great function for filling in ?1 
and ?2 : mahalanobis(x, center, cov, inverted=FALSE, ...)

The problem is I lack the knowledge around cluster analysis of what goes into 
the function for [x, center,  cov.]  I have only a basic understanding of this 
topic (a picture of a measured distance between two clusters on a graph).  
Could someone please use my data set or a similar one (a multivariate with at 
least 3 outcome variables) and actually run this function (mahalanobis).  Then 
please send me your output from [R] starting from the data set all the way to 
the statistic.  PS I know the Mahalanobis D should be ?1=3.93  ?2=3.04.
 
The Y,M,O in the data set stands for young, middle, old.
 
I am running the latest version of R on a windows 7 machine.  
 





Effect Sizes



Contrasts

Dependent Variables

 

 


Friends

Parents

Strangers

All


Young-Middle

-1.8768797*

-3.2842941*

-1.1094004*

?1


Middle-Old

1.34900725*

1.54919532*

-2.0107882*

?2
 
  Gender Age Friend.Agression Parent.Agression Stranger.Agression
1   f   y87  8
2   f   y56  8
3   f   y63  7
4   f   y55  7
5   f   m   15   13 10
6   f   m   13   11  9
7   f   m   12   12  9
8   f   m   18   10  7
9   f   o   11   11 10
10  f   o   104 12
11  f   o   129 12
12  f   o98 14
13  m   y   137  7
14  m   y95 10
15  m   y   114  4
16  m   y   153  4
17  m   m   14   12  8
18  m   m   10   15 11
19  m   m   12   11  8
20  m   m   109  9
21  m   o   108 11
22  m   o   13   11 13
23  m   o98 12
24  m   o79 16
  
[[alternative HTML version deleted]]

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