[R] tuning parameter in lasso

2009-09-27 Thread huang min
Dear All,

I understand in package lasso2 or lars, the default way to select the tuning
parameter is the CV. How can I manually set the tuning parameter $\lambda$?
I cannot figure out this according to the help file. Thank you.

Huang

[[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] Teach me how to transpose in R

2009-09-27 Thread cls59



Hyo Lee wrote:
 
 
 Teach me how to deal with this problem.
 Thank you very much.
 
 -Hyo
 
 


A good thing to try if you're stuck finding the right function in R is
searching with ??. For example, if you type:

??transpose

The base routine t(), which performs a matrix transpose, is one of the first
things that comes up.

Hope that helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Teach-me-how-to-transpose-in-R-tp25630869p25631393.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] QQ plotting of various distributions...

2009-09-27 Thread Petar Milin
Thanks for the answer. Now, only problem is to to get parameter(s) of a 
given function. For gamma, I shall try with gammafit() from mhsmm 
package. Also, I shall look for others appropriate parameter estimates. 
Will use SuppDists too.


Best,
PM

Sunil Suchindran wrote:

#same shape

some_data - rgamma(500,shape=6,scale=2)
test_data - rgamma(500,shape=6,scale=2)
plot(sort(some_data),sort(test_data))
# You can also use qqplot(some_data,test_data)
abline(0,1)

# different shape

some_data - rgamma(500,shape=6,scale=2)
test_data - rgamma(500,shape=4,scale=2)
plot(sort(some_data),sort(test_data))
abline(0,1)

It is helpful to assess the sampling variability, by
creating repeated sets of test_data, and plotting
all of these along with your observations to create
a confidence envelope.

The SuppDists provides Inverse Gauss.


On Thu, Sep 17, 2009 at 11:46 AM, Petar Milin pmi...@ff.uns.ac.rs wrote:

Hello!
I am trying with this question again:
I would like to test few distributional assumptions for some
behavioral response data. There are few theories about true
distribution of those data, like: normal, lognormal, gamma,
ex-Gaussian (exponential-Gaussian), Wald (inverse Gaussian) etc. The
best way would be via qq-plot, to show to students differences.
First two are trivial:
qqnorm(dat$X)
qqnorm(log(dat$X))
Then, things are getting more hairy. I am not sure how to make
plots for the rest. I tried gamma with:
qqmath(~ X, data=dat, distribution=function(X)
� qgamma(X, shape, scale))
Which should be the same as:
plot(qgamma(ppoints(dat$X), shape, scale), sort(dat$X))
Shape and scale parameters I got via mhsmm package that has
gammafit() for shape and scale parameters estimation.
Am I on right track? Does anyone know how to plot the rest:
ex-Gaussian (exponential-Gaussian), Wald (inverse Gaussian)?

Thanks,
PM

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




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


[R] need help in mixed poisson regression

2009-09-27 Thread hossain zamani
Dear all,
 I have a mixed Poisson regression model . my function is:

## P(N=k)=[(a+2)/a 
][(lambda^k)]*[((a+2/a+1)+lambda)^(-k-1)-(a+2+lambda)^(-k-1)]; 
lambda=a0+a1*x1+a2*x2

This is same as a Poisson-inverse
gaussian or Poisson-lognormal regression.I want to estimate the
parameters by fitting this model on my data and also I need loglike value. 
Since some of the explanatory variables (x1,x2,...) may be nominal or ordinal; 
which package in R can be used?
I am looking for any answer.
with the best wishes
Zamani.H   


  
[[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] for cycle with uncontinuous numbers

2009-09-27 Thread Marcio Resende

Hi nice people,
I would like to do a for cycle but i wish it to assume only the numers 50,
100, 200, 300, 900 and 2343
I tried to do something like

x - c(50,100,200,300,900,2343)
for (i in x){
#.
}

But it didn´t work
Could anybody help me?
Thanks in advance
Marcio
-- 
View this message in context: 
http://www.nabble.com/for-cycle-with-uncontinuous-numbers-tp25630831p25630831.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] Teach me how to transpose in R

2009-09-27 Thread Marcio Resende

Hi Hyo,
I am kinda of new in R but I think if you use
x - as.matrix(data2) #with the numer of collumns you wish
y - t(x)

it should work

Hope I´ve helped

Márcio



Hyo Lee wrote:
 
 Hi guys,
 I need your help!!
 
 My goal is to make a csv file from ncdf file.
 This is the code i've used :
 
 hyo=open.ncdf(C:/CRUTEM3.nc)
 hyo
 [1] file C:/CRUTEM3.nc has 4 dimensions:
 [1] longitude   Size: 72
 [1] latitude   Size: 36
 [1] unspecified   Size: 1
 [1] t   Size: 1916
 [1] 
 [1] file C:/CRUTEM3.nc has 1 variables:
 [1] float temp[longitude,latitude,unspecified,t]  Longname:Temperature T
 Missval:2.0004008175e+20
 data2=get.var.ncdf(hyo)
 write.csv(data2,file=C:/ple.csv)
 
 
 But the problem is, I expected this data would be 17000 * 72  (row* col) ;
 but, it is the other way around. 72*17000
 Because the maximum col number in excel is 16383, this cvs file doesn't
 show
 all data. Obviously, I need to transpose the matrix..
 I tried to use transpose function but failed.
 
 bbb=t(data2)
 Error in t.default(data2) : argument is not a matrix
 ccc=t(hyo)
 ccc
 [1] file  has  dimensions:
 Error in if (nc$ndims  0) for (i in 1:nc$ndims) { :
   argument is of length zero
 
 Teach me how to deal with this problem.
 Thank you very much.
 
 -Hyo
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/Teach-me-how-to-transpose-in-R-tp25630869p25630947.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] for cycle with uncontinuous numbers

2009-09-27 Thread Tobias Verbeke

Hi nice people,


:-)


I would like to do a for cycle but i wish it to assume only the numers 50,
100, 200, 300, 900 and 2343
I tried to do something like

x - c(50,100,200,300,900,2343)
for (i in x){
#.
}

But it didn´t work


If you would use a reproducible code example we
could point out where the error comes from;
otherwise we can only tell this should work;
try

x - c(50,100,200,300,900,2343)
for (i in x){
  cat(i^2, \n)
}
# 2500
# 1
# 4
# 9
# 81
# 5489649

HTH,
Tobias

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

2009-09-27 Thread Julius Tesoro
Hi everyone. I posted this on R-sig-geo but got no response. 

 
Can select.spatial() be used in an existing spplot? I have tried selecting 
points (eq) from a plot generated from sp. However, when I invoke 
select.spatial(eq). It generates only the points without the background 
containing the faults. I need the background to select which earthquakes 
coalesce on which fault. Is there an alternative?

eq.pts-list(sp.points,eq, col=blue, lwd=0.5, pch = 4)
   
spplot(faults,Dip, xlim = c(11,12),
ylim = c(376,389),
sp.layout=list(eq.pts),
col = heat.colors(3))

select.spatial(eq)

Cheers,

Julius Tesoro

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] multiple lattice, xyplot levelplot on same page

2009-09-27 Thread Felix Andrews
Ky,

The error you report is a problem with the c() method for trellis
plots: it allows for a different panel function in each panel, but
only one prepanel function. Because of this, the
prepanel.default.levelplot function is not getting what it expects to
recompute the panel dimensions. It may be possible to extend the
function to handle this, but for now you have a few options:

(1) Set subscripts = TRUE in the xyplot:
p1 - update(p1, subscripts = TRUE)
update(c(p2, p1, x.same = TRUE), layout = c(1, 2))

(2) Put the xyplot first, but then re-order the panels by indexing:
update(c(p1, p2, x.same = TRUE), layout = c(1, 2))[2:1]

(3) Take out the x.same=TRUE argument, if you can set the x scales to
be the same beforehand. In your example, the xyplot and levelplot had
the same x axis limits anyway, but presumably that is not the case in
your real problem.
update(c(p2, p1), layout = c(1, 2))

(4) Use a completely different mechanism: draw the two plots in the
desired position (after setting the x axes to be identical beforehand,
if desired). See ?plot.trellis
 This latter mechanism was designed in to trellis from the
beginning, whereas the c() method is basically a hack. It also has the
advantage of retaining complete control over each plot independently.


By the way, I can't understand what you are trying to do with the
par.settings$layout.width argument. It doesn't seem to have any
effect. Ditto for the 'y = c(1/4, 3/4))' argument.

 Also, I seem to have lost control of par settings such as las = 1

This is a base graphics (?par) parameter, which does not apply to
grid or lattice graphics. The equivalent of las in lattice is the
scales$rot argument. See ?xyplot

Hope that helps
-Felix


2009/9/26 Ky Mathews k.math...@usyd.edu.au:
 Dear R-users,

 I'd like to place an xyplot() at the top of a page and a levelplot() at the 
 bottom of the same page, and have the x-axes be the same.

 I've come close to finding a solution through Rarchive, and can produce an 
 upside-down version of what I'd like (levelplot() on the top - see code 
 below).

 However, the following error occurs when I try and plot the xyplot() at the 
 top:

 Error in prepanel.default.function(x = 0:10, y = c(0, 1, 4, 9, 16, 25,  :
   element 1 is empty;
    the part of the args list of 'length' being evaluated was:
    (subscripts)

 Any pointers in the right direction would be much appreciated.

 #OS: Windows XP 2002 SP3; R: 2.9.2; lattice 0.17-25; latticeExtra 0.6-1

 Thanks and regards,
 Ky

 ###
 #Rcode for xyplot and lattice plot on the same page.
 library(lattice)
 library(latticeExtra)

  #xyplot
  x1 - 0:10
  x2 - x1^2

  p1 - xyplot(x2 ~ x1
   , par.settings = list(layout.width = list(panel=1,  ylab = 2
   , axis.left =1.0, left.padding=1
   , ylab.axis.padding=1, axis.panel=1)))


  #levelplot
  y.df - data.frame(y1 = rep(x1, times = 3)
   , y2 = rep(c('E1', 'E2', 'E3'), each = length(x1))
   , y3 = c(x1, x1+2, x1-1))
  p2 - levelplot(y3 ~ y1*y2, data = y.df,
     , par.settings = list(layout.width = list(panel=1,  ylab = 2
     , axis.left =1.0, left.padding=1
     , ylab.axis.padding=1, axis.panel=1)))

 #Printing the plots on the same page
 #This is what I found on an Rarchive post (thank-you)
  #it works if the levelplot (p2) is at the top of the page
  #i.e.
   update(c(p1, p2, x.same = TRUE)
    , layout = c(1, 2)
    , ylab = list(c(p1, p2)
    , y = c(1/4, 3/4))
    , par.settings = list(layout.heights = list(panel = c(1, 1

  #however, the following error appears if the order is reversed (which is 
 what I would like)
  update(c(p2, p1, x.same = TRUE)
    , layout = c(1, 2)
    , ylab = list(c(p2, p1)
    , y = c(1/4, 3/4))
    , par.settings = list(layout.heights = list(panel = c(1, 1

 The following error appears:
 #Error in prepanel.default.function(x = 0:10, y = c(0, 1, 4, 9, 16, 25,  :
 #  element 1 is empty;
 #   the part of the args list of 'length' being evaluated was:
 #   (subscripts)

 Also, I seem to have lost control of par settings such as las = 1

 #---
 Dr Ky L. Mathews
 Co-ordinator, CIMMYT ICARDA Communications Project
 Research Fellow,
 Plant Breeding Institute, The University of Sydney, Australia

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




-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 

Re: [R] Fw: Re: Multiple Normal Curves

2009-09-27 Thread KABELI MEFANE
Hi Jim
 
Sorry to bother you but i don't seem to understand what you are saying. I have 
the simulated data as follows:
 
Hypermarket - matrix(rnorm(100, mean=5, sd=5000))
Supermarket - matrix(rnorm(400, mean=34000, sd=3000))
Minimarket  - matrix(rnorm(1000, mean=1,sd=2000))
Cornershop  - matrix(rnorm(1500, mean=2500, sd=500))
Spazashop   - matrix(rnorm(2000, mean=1000, sd=250))
dat=data.frame(type=c(rep(Hypermarket,100), rep(Supermarket,400),
rep(Minimarket,1000),rep(Cornershop,1500), rep(Spazashop,2000)),
value=c(Hypermarket, Supermarket, Minimarket, Cornershop,Spazashop))
 
Now, i want to do multiple histograms and normal curves on the same plot as you 
rightfully pointed out, but i cannot plot all of them even when i have done the 
following i can only do one. 

Hypermarket-rnorm(100, mean=5, sd=3000)
par(las=1)
hist(Hypermarket, breaks=seq(0, 6, 500), freq=F)
x- seq(0, 6, 1000)
lines(x, dnorm(x, 5, 3000))
 
As for the code below, i dicided to leave it as i does not allow me to do more 
than three curves. 
 
I would appreciate all the help.

Kabeli

--- On Thu, 24/9/09, Jim Lemon j...@bitwrit.com.au wrote:


From: Jim Lemon j...@bitwrit.com.au
Subject: Re: [R] Fw: Re: Multiple Normal Curves
To: KABELI MEFANE kabelimef...@yahoo.co.uk, r-help@r-project.org
Date: Thursday, 24 September, 2009, 12:53 PM


On 09/24/2009 08:57 PM, KABELI MEFANE wrote:
 Sorry about the subject
 
 --- On Thu, 24/9/09, KABELI MEFANEkabelimef...@yahoo.co.uk  wrote:
 
 
 From: KABELI MEFANEkabelimef...@yahoo.co.uk
 Subject: Re: [R] Multiply Normal Curves
 To: R-help@r-project.org
 Date: Thursday, 24 September, 2009, 11:48 AM
 
 
 R -helpers
   i have been trying to do this problem without must success,i managed to do 
a graph for x, but it is not what i want to define,(i want to specify number 
of observations as well). I have also been able to do simple rendom sample.
   data.frame(ID=c(1,2,3),mu=c(1,34000,5),sigma=c(2000,3000,5000))
 curve(dnorm(x,mean=parms$mu[1],sd=parms$sigma[1]),from=2000,
 to=8, ylab=density, col=red)
 curve(dnorm(x,mean=parms$mu[2],sd=parms$sigma[2]),from=1000,
 to=8, ylab=density, col=blue, add=TRUE)
 curve(dnorm(x,mean=parms$mu[3],sd=parms$sigma[3]),from=1000,
 to=8, ylab=density, col=forestgreen, add=TRUE)
 ###
 
 R-helpers
   I have been learning a little bit of R. I am simulating and i want to draw 
a normal curve for all my variables so that i will see the overlaps and reduce 
them, after that i want to draw a gragh of all the values that are in the data 
frame to see if it follows a normal distribution also. Lastly i will try to 
sample from this data. Please help and make suggestions.
 
    
Hi Kabeli,
I think you want to get multiple histograms and normal curves on the same plot. 
You can do something like that if you get a table of frequencies for each of 
your three sets of values using cut or hist, combine these vectors of 
frequencies into a matrix and pass this to barplot. Then draw your normal 
curves using curve on top of the grouped bars.

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] QQ plotting of various distributions...

2009-09-27 Thread Eric Thompson
The supposed example of a Q-Q plot is most certainly not how to make a
Q-Q plot. I don't even know where to start

First off, the two Q:s in the title of the plot stand for quantile,
not random. The answer supplied simply plots two sorted samples of
a distribution against each other. While this may resemble the general
shape of a QQ plot, that is where the similarities end.

Some general advice: be careful who you take advice from on the
internet. The Wikipedia entry for Q-Q plot may be a good start if you
don't know what a Q-Q plot is, although you should also use it with
caution.

Lets say you have some samples that may be normally distributed:

set.seed(1)
x - rnorm(30)

# now try with R's built in function
qqnorm(x, xlim = c(-3, 3), ylim = c(-3, 3))

# Now try Sunil's Q-Q plot method, but for rnorm
# rather than rgamma
some_data - x
test_data - rnorm(30)
points(sort(some_data),sort(test_data), col = blue)

# Note that the points are NOT the same!

This should have been obvious for the simple reason that the QQ plot
should not be influenced by the random number generator that you are
using! A QQ plot is uniquely reproducible. The more general (and
correct) way to get the QQ plot involves choosing a plotting position
and the quantile function (e.g. qnorm or qgamma functions in R) of the
pertinent distribution:

# Sort the data:
x.s - sort(x)
n - length(x)

# Plotting position (must be careful here in general!)
p - ppoints(n)

# Compute the quantile
x.q - qnorm(p)

points(x.q, x.s, col = red)

# and they fall exactly on the points generated by qqnorm().

Now, you should be able to generalize this for any distribution. Hope
this helps.


Eric Thompson




2009/9/27 Petar Milin pmi...@ff.uns.ac.rs:
 Thanks for the answer. Now, only problem is to to get parameter(s) of a
 given function. For gamma, I shall try with gammafit() from mhsmm package.
 Also, I shall look for others appropriate parameter estimates. Will use
 SuppDists too.

 Best,
 PM

 Sunil Suchindran wrote:

 #same shape

 some_data - rgamma(500,shape=6,scale=2)
 test_data - rgamma(500,shape=6,scale=2)
 plot(sort(some_data),sort(test_data))
 # You can also use qqplot(some_data,test_data)
 abline(0,1)

 # different shape

 some_data - rgamma(500,shape=6,scale=2)
 test_data - rgamma(500,shape=4,scale=2)
 plot(sort(some_data),sort(test_data))
 abline(0,1)

 It is helpful to assess the sampling variability, by
 creating repeated sets of test_data, and plotting
 all of these along with your observations to create
 a confidence envelope.

 The SuppDists provides Inverse Gauss.


 On Thu, Sep 17, 2009 at 11:46 AM, Petar Milin pmi...@ff.uns.ac.rs wrote:

    Hello!
    I am trying with this question again:
    I would like to test few distributional assumptions for some
    behavioral response data. There are few theories about true
    distribution of those data, like: normal, lognormal, gamma,
    ex-Gaussian (exponential-Gaussian), Wald (inverse Gaussian) etc. The
    best way would be via qq-plot, to show to students differences.
    First two are trivial:
    qqnorm(dat$X)
    qqnorm(log(dat$X))
    Then, things are getting more hairy. I am not sure how to make
    plots for the rest. I tried gamma with:
    qqmath(~ X, data=dat, distribution=function(X)
    � qgamma(X, shape, scale))
    Which should be the same as:
    plot(qgamma(ppoints(dat$X), shape, scale), sort(dat$X))
    Shape and scale parameters I got via mhsmm package that has
    gammafit() for shape and scale parameters estimation.
    Am I on right track? Does anyone know how to plot the rest:
    ex-Gaussian (exponential-Gaussian), Wald (inverse Gaussian)?

    Thanks,
    PM

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



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


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


Re: [R] Lattice, stripplot (xyplot), plotting data with median line, numeric x-axis

2009-09-27 Thread Felix Andrews
Hi David,

stripplot is for numeric vs categorical data
(and is a thin wrapper around xyplot).

Just change stripplot to xyplot and it will work.

-Felix


2009/9/27 Afshartous, David dafshart...@med.miami.edu:
 All,

 On p.52 of Deepayan Sarkar's Lattice book there is a nice plot of showing
 residuals with median lines superimposed or various groups:

 library(lattice)
 stripplot(sqrt(abs(residuals(lm(yield~variety+year+site ~ site,

 data = barley, groups = year, jitter.data = TRUE, type = c(p, a), fun =
 median)


 Suppose we wanted to make a similar plot for a numeric x-axis.  Is there any
 way to do this with stripplot or does one have to xyplot and presumably
 panel functionality to get the median line?  This does not work:

 barley$site.numeric =as.numeric(barley$site)

 stripplot(sqrt(abs(residuals(lm(yield~variety+year+site ~ site.numeric,
    data = barley, groups = year, jitter.data = TRUE, type = c(p, a),
 fun = median)


 Any tips much appreciated.  For my data I had made my x-axis a factor but
 forgot that this doesn't work since the intervals are not equally spaced.

 Thanks!
 David

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




-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 1670
E: felix.andr...@anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/

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

2009-09-27 Thread Felix Andrews
Use packet.number() to identify which data subset you are dealing with
(inside the panel function):

xyplot(y~x|a,
   panel=function(...){
   panel.loess(...)
   panel.text(0,2,label=c('best','better','bad','worst')[packet.number()])
   })

There is also panel.number() which is similar but refers to the panel
position rather than data set. The difference shows up if you
re-arrange the panels from the default ordering.


2009/9/27 Osman Al-Radi osman.al.r...@gmail.com:
 Hello,

 Thanks for your suggestion. It works in my simplified example. However, it
 didn't work in my real code. It is probably because I neglected to include
 the group argument in the example. I apologize for that.

 Below is the real code, if you need the actual data I can include it too.

 # this works well
 xyplot(PaCO2~time|group, group=animal,layout=c(3,1,1),aspect=1,
    panel=function(...){
        panel.loess(...)
        panel.superpose(...)}
    ,data=pig,subset=time5  time181,
    xlab='Time (minutes)',
    ylab='PaCO2 (mmHg)')


 # this gives the following error Error in using packet 1 data, X argument
 missing with no #default in each of the plot panel

 xyplot(PaCO2~time|group, group=animal,layout=c(3,1,1),aspect=1,
    panel=function(x,y,subscripts,...){
        panel.loess(...)
        panel.superpose(...)
        panel.text(100,110,label=c(' ','p=0.007','p=0.006')[tail(subscripts,
 1)])}
    ,data=pig, subset=time5  time181,
    xlab='Time (minutes)',
    ylab='PaCO2 (mmHg)')


  Thanks tremendously for your help. I don't know why its soo hard just to
 add some text!

 Osman
 Osman O. Al-Radi, MD, MSc, FRCSC
 Staff Cardiovascular Surgeon
 Co-medical director, Tissue Bank
 The Hospital for Sick Children
 University of Toronto, Canada


 On Thu, Sep 24, 2009 at 2:18 PM, Henrique Dallazuanna www...@gmail.comwrote:

 Try this:

 xyplot(y ~ x | a,
   panel=function(x, y, subscripts, ...){
       panel.loess(x, y)
       panel.text(0, 2,
 label=c('best','better','bad','worst')[tail(subscripts, 1)/100])
   })

 On Thu, Sep 24, 2009 at 2:45 PM, Osman Al-Radi osman.al.r...@gmail.com
 wrote:
  Dear R-help,
 
  I would like to add text to each of four panels in a plot generated by
  xyplot in lattice library. A sample code is given below, the plot
 generated
  has the first label repeated in all panels!
 
  How can I get the labels to be different in each panel?
 
  library(lattice)
  x - rnorm(400)
  y - rnorm(400)
  a - gl(4, 100)
 
  xyplot(y~x|a,
     panel=function(...){
         panel.loess(...)
         panel.text(0,2,label=c('best','better','bad','worst'))})
 
  Thanks
 
  Osman
 
 
 
  Osman O. Al-Radi, MD, MSc, FRCSC
  Staff Cardiovascular Surgeon
  Co-medical director, Tissue Bank
  The Hospital for Sick Children
  University of Toronto, Canada
 
         [[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.
 



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


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





-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 1670
E: felix.andr...@anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/

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


Re: [R] Adding variables

2009-09-27 Thread tzygmund mcfarlane
Jim,

Both my emails contained reproducible code (the first one wasn't
completely reproducible - it required one to know that attenu is a
base R dataset).

Anyway, thanks for your help.

On Sat, Sep 26, 2009 at 8:11 PM, jim holtman jholt...@gmail.com wrote:
 I assumed (since you did not provide reproducible code) that 'mag' was
 a matrix.  If 'station' is a matrix, then

 mag + rowSums(station)

 will work.  If that does not work, then you need to tell us what your
 data objects are.

 On Sat, Sep 26, 2009 at 11:39 AM, tzygmund mcfarlane
 tzygm...@googlemail.com wrote:
 Hi Jim,

 I might be missing something but your command gives the error:
 Error in rowSums(mag) : 'x' must be an array of at least two dimensions

 #
 data(attenu)
 attach(attenu)
 rowSums(mag) + rowSums(station)
 attenu$new-rowSums(cbind(mag, station))
 #

 Thanks


 On Sat, Sep 26, 2009 at 4:30 PM, jim holtman jholt...@gmail.com wrote:
 Probably more efficient if you remove the 'cbind' which would create a
 combined matrix.  Use the following:

 rowSums(mag) + rowSums(station)

 On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane
 tzygm...@googlemail.com wrote:
 Hi,

 For very large matrices, is this the most efficient way to add two
 variables together?

 #
 attach(attenu)
 new-rowSums(cbind(mag, station))
 #

 Also, could I be directed to some resources for working with very
 large datasets?

 Thanks

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




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

 What is the problem that you are trying to solve?





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

 What is the problem that you are trying to solve?


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


Re: [R] QQ plotting of various distributions...

2009-09-27 Thread Duncan Murdoch

Eric Thompson wrote:

The supposed example of a Q-Q plot is most certainly not how to make a
Q-Q plot. I don't even know where to start

First off, the two Q:s in the title of the plot stand for quantile,
not random. The answer supplied simply plots two sorted samples of
a distribution against each other. While this may resemble the general
shape of a QQ plot, that is where the similarities end.
  


The empirical quantiles of a sample are simply the sorted values.  You 
can plot empirical quantiles of one sample versus some version of 
quantiles from a distribution (what qqnorm does) or versus empirical 
quantiles of another sample (what Sunil did).  The randomness in his 
demonstration did two things: it generated some data, and it showed the 
variability of the plot under repeated sampling.

Some general advice: be careful who you take advice from on the
internet. 


That's good advice.

Duncan Murdoch


The Wikipedia entry for Q-Q plot may be a good start if you
don't know what a Q-Q plot is, although you should also use it with
caution.

Lets say you have some samples that may be normally distributed:

set.seed(1)
x - rnorm(30)

# now try with R's built in function
qqnorm(x, xlim = c(-3, 3), ylim = c(-3, 3))

# Now try Sunil's Q-Q plot method, but for rnorm
# rather than rgamma
some_data - x
test_data - rnorm(30)
points(sort(some_data),sort(test_data), col = blue)

# Note that the points are NOT the same!

This should have been obvious for the simple reason that the QQ plot
should not be influenced by the random number generator that you are
using! A QQ plot is uniquely reproducible. The more general (and
correct) way to get the QQ plot involves choosing a plotting position
and the quantile function (e.g. qnorm or qgamma functions in R) of the
pertinent distribution:

# Sort the data:
x.s - sort(x)
n - length(x)

# Plotting position (must be careful here in general!)
p - ppoints(n)

# Compute the quantile
x.q - qnorm(p)

points(x.q, x.s, col = red)

# and they fall exactly on the points generated by qqnorm().

Now, you should be able to generalize this for any distribution. Hope
this helps.


Eric Thompson




2009/9/27 Petar Milin pmi...@ff.uns.ac.rs:
  

Thanks for the answer. Now, only problem is to to get parameter(s) of a
given function. For gamma, I shall try with gammafit() from mhsmm package.
Also, I shall look for others appropriate parameter estimates. Will use
SuppDists too.

Best,
PM

Sunil Suchindran wrote:


#same shape

some_data - rgamma(500,shape=6,scale=2)
test_data - rgamma(500,shape=6,scale=2)
plot(sort(some_data),sort(test_data))
# You can also use qqplot(some_data,test_data)
abline(0,1)

# different shape

some_data - rgamma(500,shape=6,scale=2)
test_data - rgamma(500,shape=4,scale=2)
plot(sort(some_data),sort(test_data))
abline(0,1)

It is helpful to assess the sampling variability, by
creating repeated sets of test_data, and plotting
all of these along with your observations to create
a confidence envelope.

The SuppDists provides Inverse Gauss.


On Thu, Sep 17, 2009 at 11:46 AM, Petar Milin pmi...@ff.uns.ac.rs wrote:

   Hello!
   I am trying with this question again:
   I would like to test few distributional assumptions for some
   behavioral response data. There are few theories about true
   distribution of those data, like: normal, lognormal, gamma,
   ex-Gaussian (exponential-Gaussian), Wald (inverse Gaussian) etc. The
   best way would be via qq-plot, to show to students differences.
   First two are trivial:
   qqnorm(dat$X)
   qqnorm(log(dat$X))
   Then, things are getting more hairy. I am not sure how to make
   plots for the rest. I tried gamma with:
   qqmath(~ X, data=dat, distribution=function(X)
   � qgamma(X, shape, scale))
   Which should be the same as:
   plot(qgamma(ppoints(dat$X), shape, scale), sort(dat$X))
   Shape and scale parameters I got via mhsmm package that has
   gammafit() for shape and scale parameters estimation.
   Am I on right track? Does anyone know how to plot the rest:
   ex-Gaussian (exponential-Gaussian), Wald (inverse Gaussian)?

   Thanks,
   PM

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


  

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




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

Re: [R] Re ad in multiple datasets

2009-09-27 Thread Gabor Grothendieck
Try this:

filenames - sprintf(data%d.csv, 1:20)
DFs - sapply(filenames, read.csv, simplify = FALSE)

which will return a list of data frames, DFs, each named by its
filename so that DFs[[1]] or DFs[[data1.csv]] give the data frame
read from data1.csv, etc. and names(DFs) gives a vector of their names
as does filenames.

On Sat, Sep 26, 2009 at 11:47 PM, legen lege...@gmail.com wrote:

 Hello, all:

 I have twenty datasets named as: data1.csv, data2.csv, …, data20.csv. I am
 trying to read all of them into R by using loop and function read.table(),
 but I don't know how to handle the name of datasets. Has anybody have
 encountered a similar problem? Or do you have any suggestions? Your help
 would be greatly appreciated.

 Legen

 --
 View this message in context: 
 http://www.nabble.com/Read-in-multiple-datasets-tp25630688p25630688.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


[R] Gini importance measure in RF package

2009-09-27 Thread Chrysanthi A.
Dear all,

I am working with randomForest package and I am interested in examining the
Gini importance measures that are used as a general indicator of feature
relevance. Is there a possibility of getting the Gini measure that is being
estimated in each tree by the output of the getTree() function?

Thanks a lot,

Chrysanthi

[[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] Adding variables

2009-09-27 Thread David Winsemius
Well, I had never seen any help pages use attenu as an example. Like  
Jim I assumed that you were offering code that was operating on some  
private copy of data, If you look at the number of datasets, I think  
it unreasonable to expect the great majority of potentially helpful  
persons to know all of them either.


So why were you trying to add a factor variable to a numeric, anyway?  
If your hope was to convert those codes to numeric then it's a FAQ:


http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f

If the problem were more basic, and you did not know what was in that  
dataset then the answer might have bee:


str(attenu)

--
David




On Sep 27, 2009, at 7:47 AM, tzygmund mcfarlane wrote:


Jim,

Both my emails contained reproducible code (the first one wasn't
completely reproducible - it required one to know that attenu is a
base R dataset).

Anyway, thanks for your help.

On Sat, Sep 26, 2009 at 8:11 PM, jim holtman jholt...@gmail.com  
wrote:
I assumed (since you did not provide reproducible code) that 'mag'  
was

a matrix.  If 'station' is a matrix, then

mag + rowSums(station)

will work.  If that does not work, then you need to tell us what your
data objects are.

On Sat, Sep 26, 2009 at 11:39 AM, tzygmund mcfarlane
tzygm...@googlemail.com wrote:

Hi Jim,

I might be missing something but your command gives the error:
Error in rowSums(mag) : 'x' must be an array of at least two  
dimensions


#
data(attenu)
attach(attenu)
rowSums(mag) + rowSums(station)
attenu$new-rowSums(cbind(mag, station))
#

Thanks


On Sat, Sep 26, 2009 at 4:30 PM, jim holtman jholt...@gmail.com  
wrote:
Probably more efficient if you remove the 'cbind' which would  
create a

combined matrix.  Use the following:

rowSums(mag) + rowSums(station)

On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane
tzygm...@googlemail.com wrote:

Hi,

For very large matrices, is this the most efficient way to add two
variables together?

#
attach(attenu)
new-rowSums(cbind(mag, station))
#

Also, could I be directed to some resources for working with very
large datasets?

Thanks

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





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

What is the problem that you are trying to solve?







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

What is the problem that you are trying to solve?



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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Adding variables

2009-09-27 Thread Henrique Dallazuanna
The station column has non numeric values, so you need convert to
numeric before:

with(attenu, as.numeric(as.character(station)) + mag)

On Sun, Sep 27, 2009 at 8:47 AM, tzygmund mcfarlane
tzygm...@googlemail.com wrote:
 Jim,

 Both my emails contained reproducible code (the first one wasn't
 completely reproducible - it required one to know that attenu is a
 base R dataset).

 Anyway, thanks for your help.

 On Sat, Sep 26, 2009 at 8:11 PM, jim holtman jholt...@gmail.com wrote:
 I assumed (since you did not provide reproducible code) that 'mag' was
 a matrix.  If 'station' is a matrix, then

 mag + rowSums(station)

 will work.  If that does not work, then you need to tell us what your
 data objects are.

 On Sat, Sep 26, 2009 at 11:39 AM, tzygmund mcfarlane
 tzygm...@googlemail.com wrote:
 Hi Jim,

 I might be missing something but your command gives the error:
 Error in rowSums(mag) : 'x' must be an array of at least two dimensions

 #
 data(attenu)
 attach(attenu)
 rowSums(mag) + rowSums(station)
 attenu$new-rowSums(cbind(mag, station))
 #

 Thanks


 On Sat, Sep 26, 2009 at 4:30 PM, jim holtman jholt...@gmail.com wrote:
 Probably more efficient if you remove the 'cbind' which would create a
 combined matrix.  Use the following:

 rowSums(mag) + rowSums(station)

 On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane
 tzygm...@googlemail.com wrote:
 Hi,

 For very large matrices, is this the most efficient way to add two
 variables together?

 #
 attach(attenu)
 new-rowSums(cbind(mag, station))
 #

 Also, could I be directed to some resources for working with very
 large datasets?

 Thanks

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




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

 What is the problem that you are trying to solve?





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

 What is the problem that you are trying to solve?


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




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

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


Re: [R] Adding variables

2009-09-27 Thread tzygmund mcfarlane
 So why were you trying to add a factor variable to a numeric, anyway?

For no other reason than to illustrate the task of addition. It is,
admittedly, meaningless.

 Well, I had never seen any help pages use attenu as an example.

I literally went to:
http://stat.ethz.ch/R-manual/R-patched/library/datasets/html/00Index.html
and picked a random dataset. I haven't enough R experience to know
which datasets are more commonly used to illustrate issues than
others.

My original question was about the efficiency of simple arithmetic for
large datasets and managing them. While the advice I have received so
far is very good for my R style, I was wondering if you might add
something regarding this.

PS. Thanks Henrique, but again the example was chosen completely at
random to provide reproducible code  I wasn't thinking about numeric
and factor variables.

On Sun, Sep 27, 2009 at 3:14 PM, David Winsemius dwinsem...@comcast.net wrote:
 Well, I had never seen any help pages use attenu as an example. Like Jim I
 assumed that you were offering code that was operating on some private copy
 of data, If you look at the number of datasets, I think it unreasonable to
 expect the great majority of potentially helpful persons to know all of them
 either.

 So why were you trying to add a factor variable to a numeric, anyway? If
 your hope was to convert those codes to numeric then it's a FAQ:

 http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f

 If the problem were more basic, and you did not know what was in that
 dataset then the answer might have bee:

 str(attenu)

 --
 David




 On Sep 27, 2009, at 7:47 AM, tzygmund mcfarlane wrote:

 Jim,

 Both my emails contained reproducible code (the first one wasn't
 completely reproducible - it required one to know that attenu is a
 base R dataset).

 Anyway, thanks for your help.

 On Sat, Sep 26, 2009 at 8:11 PM, jim holtman jholt...@gmail.com wrote:

 I assumed (since you did not provide reproducible code) that 'mag' was
 a matrix.  If 'station' is a matrix, then

 mag + rowSums(station)

 will work.  If that does not work, then you need to tell us what your
 data objects are.

 On Sat, Sep 26, 2009 at 11:39 AM, tzygmund mcfarlane
 tzygm...@googlemail.com wrote:

 Hi Jim,

 I might be missing something but your command gives the error:
 Error in rowSums(mag) : 'x' must be an array of at least two dimensions

 #
 data(attenu)
 attach(attenu)
 rowSums(mag) + rowSums(station)
 attenu$new-rowSums(cbind(mag, station))
 #

 Thanks


 On Sat, Sep 26, 2009 at 4:30 PM, jim holtman jholt...@gmail.com wrote:

 Probably more efficient if you remove the 'cbind' which would create a
 combined matrix.  Use the following:

 rowSums(mag) + rowSums(station)

 On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane
 tzygm...@googlemail.com wrote:

 Hi,

 For very large matrices, is this the most efficient way to add two
 variables together?

 #
 attach(attenu)
 new-rowSums(cbind(mag, station))
 #

 Also, could I be directed to some resources for working with very
 large datasets?

 Thanks

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




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

 What is the problem that you are trying to solve?





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

 What is the problem that you are trying to solve?


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

 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT



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


Re: [R] Adding variables

2009-09-27 Thread Gabor Grothendieck
with(attenu, mag + as.numeric(station))

is nearly twice as fast:

 system.time(for(i in 1:1000) with(attenu, mag + as.numeric(station)))
   user  system elapsed
   0.050.020.06

 system.time(for(i in 1:1000) rowSums(cbind(mag, station)))
   user  system elapsed
   0.090.000.10

See ?system.time, ?Rprof and http://code.google.com/p/rbenchmark/
for timing commands.

On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane
tzygm...@googlemail.com wrote:
 Hi,

 For very large matrices, is this the most efficient way to add two
 variables together?

 #
 attach(attenu)
 new-rowSums(cbind(mag, station))
 #

 Also, could I be directed to some resources for working with very
 large datasets?

 Thanks

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


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


Re: [R] Adding variables

2009-09-27 Thread tzygmund mcfarlane
Thank you Gabor ( Henrique)!

On Sun, Sep 27, 2009 at 3:26 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 with(attenu, mag + as.numeric(station))

 is nearly twice as fast:

 system.time(for(i in 1:1000) with(attenu, mag + as.numeric(station)))
   user  system elapsed
   0.05    0.02    0.06

 system.time(for(i in 1:1000) rowSums(cbind(mag, station)))
   user  system elapsed
   0.09    0.00    0.10

 See ?system.time, ?Rprof and http://code.google.com/p/rbenchmark/
 for timing commands.

 On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane
 tzygm...@googlemail.com wrote:
 Hi,

 For very large matrices, is this the most efficient way to add two
 variables together?

 #
 attach(attenu)
 new-rowSums(cbind(mag, station))
 #

 Also, could I be directed to some resources for working with very
 large datasets?

 Thanks

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



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

2009-09-27 Thread Juliet Hannah
I think it's helpful to show the sampling variability in a QQ plot
under repeated
sampling. An example is given
in Venables, Ripley pg 86. The variance is higher at the tails. Even when the
distributions are the same, the QQ plot does not have to resemble a straight
line because of sampling. I don't think you can think of any one of these as the
correct plot.

Also, if the two
data sets have an equal number of points, the empirical qq plot is
simply a plot of
one sorted data set against the other. (Kundu, Statistical Computing, pg 42).


On Sun, Sep 27, 2009 at 9:06 AM, Duncan Murdoch murd...@stats.uwo.ca wrote:
 Eric Thompson wrote:

 The supposed example of a Q-Q plot is most certainly not how to make a
 Q-Q plot. I don't even know where to start

 First off, the two Q:s in the title of the plot stand for quantile,
 not random. The answer supplied simply plots two sorted samples of
 a distribution against each other. While this may resemble the general
 shape of a QQ plot, that is where the similarities end.


 The empirical quantiles of a sample are simply the sorted values.  You can
 plot empirical quantiles of one sample versus some version of quantiles from
 a distribution (what qqnorm does) or versus empirical quantiles of another
 sample (what Sunil did).  The randomness in his demonstration did two
 things: it generated some data, and it showed the variability of the plot
 under repeated sampling.


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


Re: [R] Adding variables

2009-09-27 Thread Gabor Grothendieck
Note that Henrique's code does not give the same result as the
expression you posted although its possible that his is what you
really intended.

On Sun, Sep 27, 2009 at 10:27 AM, tzygmund mcfarlane
tzygm...@googlemail.com wrote:
 Thank you Gabor ( Henrique)!

 On Sun, Sep 27, 2009 at 3:26 PM, Gabor Grothendieck
 ggrothendi...@gmail.com wrote:
 with(attenu, mag + as.numeric(station))

 is nearly twice as fast:

 system.time(for(i in 1:1000) with(attenu, mag + as.numeric(station)))
   user  system elapsed
   0.05    0.02    0.06

 system.time(for(i in 1:1000) rowSums(cbind(mag, station)))
   user  system elapsed
   0.09    0.00    0.10

 See ?system.time, ?Rprof and http://code.google.com/p/rbenchmark/
 for timing commands.

 On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane
 tzygm...@googlemail.com wrote:
 Hi,

 For very large matrices, is this the most efficient way to add two
 variables together?

 #
 attach(attenu)
 new-rowSums(cbind(mag, station))
 #

 Also, could I be directed to some resources for working with very
 large datasets?

 Thanks

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




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

2009-09-27 Thread gunnar.p

Dear all,
I have several text files looking like this:
  9063032 19700201 22:00 174.067
  9063032 19700201 23:00 174.076
  9063032 19700202 00:00 174.085
  9063032 19700202 01:00 174.091
  9063032 19700202 02:00 174.094
  9063032 19700202 03:00 174.091
  9063032 19700202 04:00 174.082
  9063032 19700202 05:00 174.079

And I run this loop: 
for (j in 1:nr.of.files)
{
   #Import:
   DF - read.table(path,header=FALSE,na.string='-',
colClasses=c(NULL,character,character,numeric))
   z  - zoo(DF$V4,chron(dates=DF$V2,times=paste(DF$V3,0,sep=:),
 format=c(dates=ymd,times=h:m:s)))   
   #getting daily values:
   x  - aggregate(z,trunc,mean)   
   #summing everything up in one nr.of.files-dimensional zoo-object
   if (j  1) final - merge(final,x) else final - x
}

Unfortunately I get the following error message:
  Fehler in matrix(unlist(lapply(dots, origin)), nrow = 3) : 
   Versuch ein Attribut von NULL zu setzen
   (Error ... Trying to set an attribute NULL)

There is no error when I first run merge() and then aggregate(), but this is
not possible due to the rest of the program.
Does any one have a clue?

regards, gunnar
(R vers.2.9.1 (Debian Lenny, XFCE 4.4, EMACS 22.2.1, ESS 5.3.8))

-- 
View this message in context: 
http://www.nabble.com/zoo%3A-merging-aggregated-zoo-objects-fails-tp25633345p25633345.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] for cycle with uncontinuous numbers

2009-09-27 Thread Marcio Resende

Hi Tobias, thanks for the help,
the code I am using is quite long, but basically what I tried to do was

test - matrix(0,6,1)
x - matrix( c(50,100,200,300,900,2343) ,ncol = 1)
for (i in x){ 
test [i] - (i) 
} 

but this code returns NA for all the elements which are not x




Tobias Verbeke-2 wrote:
 
 Hi nice people,
 
 :-)
 
 I would like to do a for cycle but i wish it to assume only the numers
 50,
 100, 200, 300, 900 and 2343
 I tried to do something like
 
 x - c(50,100,200,300,900,2343)
 for (i in x){
 #.
 }
 
 But it didn´t work
 
 If you would use a reproducible code example we
 could point out where the error comes from;
 otherwise we can only tell this should work;
 try
 
 x - c(50,100,200,300,900,2343)
 for (i in x){
cat(i^2, \n)
 }
 # 2500
 # 1
 # 4
 # 9
 # 81
 # 5489649
 
 HTH,
 Tobias
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/for-cycle-with-uncontinuous-numbers-tp25630831p25633906.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] Gini importance measure in RF package

2009-09-27 Thread Chrysanthi A.
Dear all,

I am working with randomForest package and I am interested in examining the
Gini importance measures that are used as a general indicator of feature
relevance. Is there a possibility of getting the Gini measure that is being
estimated in each tree by the output of the getTree() function?

Thanks a lot,

Chrysanthi

[[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] Problem with Random Forest predict

2009-09-27 Thread Chrysanthi A.
Dear all,

I am working with randomForest package and I am interested in examining the
Gini importance measures that are used as a general indicator of feature
relevance. Is there a possibility of getting the Gini measure that is being
estimated in each tree by the output of the getTree() function?

Thanks a lot,

Chrysanthi

[[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] Xterm escape sequences in Prompt

2009-09-27 Thread Dan DEDIU

Dear list,

I would like to know if there is any way to include xterm escape sequences in 
R's prompt using options( prompt= XXX, continue= XXX ), where XXX can contain, 
for example, \033[1;31mRed for chancing text color to red (see 
http://www.frexx.de/xterm-256-notes/).
If you do this, the color escape sequences work (with an appropriate terminal 
emulator, e.g., xterm under Linux), providing you with a colored R prompt. 
However, when using the command history (arrow up/down) the edit line gets 
messed up because the algorithm counts the escape sequence not as a single char 
but as multiple. Thus, I was wondering if there would be any way to tell 
options(prompt) not only the string but also the number of characters in the 
string (of course, defaulting to strlen).

The specific reason I ask this question is because I have recently written a 
gedit plug-in for R, allowing it to become a lightweight IDE for R 
(http://sourceforge.net/projects/rgedit/) and one feature I would like to have 
is colored prompts (to make the R console easier to navigate through). Alas, as 
I said before, using options() with escape sequences kind of works as long as 
you don't use the command history (implemented in my rgedit but disabled by 
default).

Thanks you in advance,
Dan

  
_


[[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] Optional libraries (libtiff, etc) not found

2009-09-27 Thread Wayne F

I installed the (binary) biOps package, which can use libtiff and libfftw.
Then I used macports to install the libraries (in /opt/local/lib). But I
restart R and biOps still does not see the libraries.

I've tried adding symbolic links from /opt/local/lib to /usr/local/lib, I've
added /opt/local/lib to LIBRARY_PATH, LD_LIBRARY_PATH, and
DYLD_LIBRARY_PATH, and it doesn't work.

Do you need to install biOps source in order for it to realize that the
libraries are there? Or something else?
-- 
View this message in context: 
http://www.nabble.com/Optional-libraries-%28libtiff%2C-etc%29-not-found-tp25634024p25634024.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] zoo: merging aggregated zoo-objects fails

2009-09-27 Thread Gabor Grothendieck
Please read the last line to every message on r-help.  In particular
make it reproducible and minimal.  The code you post should look like
this where you have cut down DF1, DF2 and DF3 to the smallest number
of rows that still exhibits the error.

DF1 - ...output from dput(DF1)
DF2 - ...output from dput(DF2)...
DF3 - ...output from dput(DF3)...

z1 - zoo(...)
z2 - zoo(...)
z3 - zoo(...)

m - merge(z1, z2)
m2 - merge(z3, m) # error

On Sun, Sep 27, 2009 at 8:42 AM, gunnar.p pr...@uni-potsdam.de wrote:

 Dear all,
 I have several text files looking like this:
  9063032 19700201 22:00 174.067
  9063032 19700201 23:00 174.076
  9063032 19700202 00:00 174.085
  9063032 19700202 01:00 174.091
  9063032 19700202 02:00 174.094
  9063032 19700202 03:00 174.091
  9063032 19700202 04:00 174.082
  9063032 19700202 05:00 174.079

 And I run this loop:
 for (j in 1:nr.of.files)
 {
   #Import:
   DF - read.table(path,header=FALSE,na.string='-',
                    colClasses=c(NULL,character,character,numeric))
   z  - zoo(DF$V4,chron(dates=DF$V2,times=paste(DF$V3,0,sep=:),
                         format=c(dates=ymd,times=h:m:s)))
   #getting daily values:
   x  - aggregate(z,trunc,mean)
   #summing everything up in one nr.of.files-dimensional zoo-object
   if (j  1) final - merge(final,x) else final - x
 }

 Unfortunately I get the following error message:
  Fehler in matrix(unlist(lapply(dots, origin)), nrow = 3) :
   Versuch ein Attribut von NULL zu setzen
   (Error ... Trying to set an attribute NULL)

 There is no error when I first run merge() and then aggregate(), but this is
 not possible due to the rest of the program.
 Does any one have a clue?

 regards, gunnar
 (R vers.2.9.1 (Debian Lenny, XFCE 4.4, EMACS 22.2.1, ESS 5.3.8))

 --
 View this message in context: 
 http://www.nabble.com/zoo%3A-merging-aggregated-zoo-objects-fails-tp25633345p25633345.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] for cycle with uncontinuous numbers

2009-09-27 Thread jim holtman
It is unclear exactly what you are trying to do.  Since your 'test'
matrix is only 6 rows in length, then when you extend it by trying to
store into 50 for example, it will fill in the rest of the new values
with NA.  Can you explain what you think the code is supposed to do?
It is doing exactly what you are asking it to do with the script you
provided.

On Sun, Sep 27, 2009 at 10:09 AM, Marcio Resende
mresende...@yahoo.com.br wrote:

 Hi Tobias, thanks for the help,
 the code I am using is quite long, but basically what I tried to do was

 test - matrix(0,6,1)
 x - matrix( c(50,100,200,300,900,2343) ,ncol = 1)
 for (i in x){
 test [i] - (i)
 }

 but this code returns NA for all the elements which are not x




 Tobias Verbeke-2 wrote:

 Hi nice people,

 :-)

 I would like to do a for cycle but i wish it to assume only the numers
 50,
 100, 200, 300, 900 and 2343
 I tried to do something like

 x - c(50,100,200,300,900,2343)
 for (i in x){
 #.
 }

 But it didn´t work

 If you would use a reproducible code example we
 could point out where the error comes from;
 otherwise we can only tell this should work;
 try

 x - c(50,100,200,300,900,2343)
 for (i in x){
    cat(i^2, \n)
 }
 # 2500
 # 1
 # 4
 # 9
 # 81
 # 5489649

 HTH,
 Tobias

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



 --
 View this message in context: 
 http://www.nabble.com/for-cycle-with-uncontinuous-numbers-tp25630831p25633906.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Generation of Multariate Gumbel Random Numbers VGAM or GUMBEL

2009-09-27 Thread Cristian Angelo Guevara
Dear R users:

I'm trying to generate multivariate random numbers where some
variables are correlated. I tried VGAM and GUMBEL, but I really don't
understand from the documentation, how to move from the single random
to the multivariate. Does anybody have any insight about about this?

Thanks in advance
Angelo

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

2009-09-27 Thread Douglas Bates
On Sat, Sep 26, 2009 at 11:33 PM, David Winsemius
dwinsem...@comcast.net wrote:
 I am contemplating bringing in and merging three NHANES-III datasets from
 the National Center for Health Statistics that are fixed format with record
 length=3348, line counts around 20,000 and described by SAS DATA steps. I
 have downloaded and linked similar datasets from the Continuous NHANES
 public data releases, but never ones with this many variables at once. In
 the prior effort I managed the task by some cut-paste-editing from the SAS
 code file into a corresponding read.fwf R call, but the earlier NHANES-III
 data is far more voluminous than the more recent Continuous version. I am
 wondering if anyone has experience with such a process and would be willing
 to share some advice? The SAS code can be seen here:

 ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/adult.sas

 The main code file Data step starts out...
    FILENAME ADULT D:\Questionnaire\DAT\ADULT.DAT LRECL=3348;
    *** LRECL includes 2 positions for CRLF, assuming use of PC SAS;
    DATA WORK;
      INFILE ADULT MISSOVER;
      LENGTH
        SEQN      7
        DMPFSEQ   5
        DMPSTAT   3
        DMARETHN  3
        DMARACER  3
        DMAETHNR  3
        HSSEX     3
 The corresponding positions in the INPUT section are
     INPUT
        SEQN     1-5
        DMPFSEQ  6-10
        DMPSTAT  11
        DMARETHN 12
        DMARACER 13
        DMAETHNR 14
        HSSEX    15
 The note about CRLF appears to be implying that those characters are being
 counted as part of the length of the first variable, SEQN, but that there
 are only 5 meaningful positions. I suppose I can find out by trial and error
 how to read such files, but it would save me some time if anyone in the
 audience has worked through this on this data before.
 One thought would be to import the data with the SAS work-alike program,
 WKS, (which I have not used before) and then to read in with read.xport from
 the foreign library. That would obviate the need to understand the character
 position issue, but probably has a time commitment to get it up and running
 and learn how to use it.
 Another thought would be to parse the fixed width SAS Data step code into
 pieces and build a data.frame from which I then extract the row.names,
 col.names, and colClasses from that centralized structure.

Are the data available to the public somewhere or could just a few
records be made available?

The reason I ask is because I imagine there are a lot of missing data
in each record (the data are arranged in the wide format for
longitudinal data and includes follow-up questions that will not apply
to most respondents).  The missing data indicator, if any, and the
format of the other fields will be important in deciding how to split
the data.

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

2009-09-27 Thread Marcio Resende

Dear John,
What I am trying to do is a genetic analysis and the i in my cycle are the
numbers of markers I am testing.
I know the code is not right, but what i wanted to do was to fill this 6 row
matrix with the numbers in x
So basically I wanted the cycle to loop only with the values on x
(50,100,200,300,900,2343) and not the the rest of the values
Do you know how to do it?

In the example I wanted my final test matrix to be
[50
100
200
300
900
2343]
dim(test) - still 6x1

Thanks for the help




jholtman wrote:
 
 It is unclear exactly what you are trying to do.  Since your 'test'
 matrix is only 6 rows in length, then when you extend it by trying to
 store into 50 for example, it will fill in the rest of the new values
 with NA.  Can you explain what you think the code is supposed to do?
 It is doing exactly what you are asking it to do with the script you
 provided.
 
 On Sun, Sep 27, 2009 at 10:09 AM, Marcio Resende
 mresende...@yahoo.com.br wrote:

 Hi Tobias, thanks for the help,
 the code I am using is quite long, but basically what I tried to do was

 test - matrix(0,6,1)
 x - matrix( c(50,100,200,300,900,2343) ,ncol = 1)
 for (i in x){
 test [i] - (i)
 }

 but this code returns NA for all the elements which are not x




 Tobias Verbeke-2 wrote:

 Hi nice people,

 :-)

 I would like to do a for cycle but i wish it to assume only the numers
 50,
 100, 200, 300, 900 and 2343
 I tried to do something like

 x - c(50,100,200,300,900,2343)
 for (i in x){
 #.
 }

 But it didn´t work

 If you would use a reproducible code example we
 could point out where the error comes from;
 otherwise we can only tell this should work;
 try

 x - c(50,100,200,300,900,2343)
 for (i in x){
    cat(i^2, \n)
 }
 # 2500
 # 1
 # 4
 # 9
 # 81
 # 5489649

 HTH,
 Tobias

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



 --
 View this message in context:
 http://www.nabble.com/for-cycle-with-uncontinuous-numbers-tp25630831p25633906.html
 Sent from the R help mailing list archive at Nabble.com.

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

 
 
 
 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/for-cycle-with-uncontinuous-numbers-tp25630831p25634676.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] Optional libraries (libtiff, etc) not found

2009-09-27 Thread David Winsemius
There is sufficient circumstantial evidence to suggest you are posting  
in the wrong mailing list. Follow-up should go there.  You also have  
not posted sessionInfo() output or the error messages you are getting  
when what-ever-it-is-that-you-have-done that didn't work. You  
should post in R-SIG-Mac and include the appropriate information  
requested in the Posting Guide (sessionInfo(), console output prior to  
error message, and error messages).


On Sep 27, 2009, at 10:23 AM, Wayne F wrote:



I installed the (binary) biOps package, which can use libtiff and  
libfftw.
Then I used macports to install the libraries (in /opt/local/lib).  
But I

restart R and biOps still does not see the libraries.


There is a binary package called devpack4 at:

http://cran.r-project.org/bin/macosx/tools/

I don't see libtiff in there, but libjpeg which biOps requires  
(according to the docs) is in there. If you are going to compile from  
sources you should read that information carefully.


I've tried adding symbolic links from /opt/local/lib to /usr/local/ 
lib, I've

added /opt/local/lib to LIBRARY_PATH, LD_LIBRARY_PATH, and
DYLD_LIBRARY_PATH, and it doesn't work.

Do you need to install biOps source in order for it to realize that  
the

libraries are there? Or something else?


I got this error when I tried to load the binary installed package:
 library(biOps)
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared library '/Library/Frameworks/R.framework/ 
Resources/library/biOps/libs/x86_64/biOps.so':
  dlopen(/Library/Frameworks/R.framework/Resources/library/biOps/libs/ 
x86_64/biOps.so, 6): Symbol not found: _TIFFClose
  Referenced from: /Library/Frameworks/R.framework/Resources/library/ 
biOps/libs/x86_64/biOps.so

  Expected in: dynamic lookup

Compiling from sources using the GUI Package Installer succeeded and  
the package loaded without error.


I did encounter some warnings in the check phase:

checking fftw3.h usability... no
checking fftw3.h presence... no
checking for fftw3.h... no
checking jpeglib.h usability... configure: WARNING: Can't find fftw3  
header

yes
checking jpeglib.h presence... yes
checking for jpeglib.h... yes
checking tiff.h usability... no
checking tiff.h presence... no
checking for tiff.h... no
configure: WARNING: Can't find libtiff header

My scan of the compilation messages suggested that the lack of tiff  
support was not remedied in the process but I cannot be sure about  
that (see below). In the past (say a year ago) I generally needed to  
compile from sources if I were using the 64-bit GUI, but that is an  
unusual occurrence more recently. Being a UNIX-noob, I cannot tell  
whether this error was due to my being in the 64 bit configuration.   
Whether the package will do anything useful now, I cannot say:


capabilities() still reported FALSE for tiff

The first example in hte documentation produces a black square
 jpeg()
 p - q - seq(-1, 1, length=20)
 r - 1 - outer(p^2, q^2, +) / 2
 plot(imagedata(r))
 dev.off()
null device
  1

The second example I tried produced a very pretty picture of a flower:

 x - readJpeg(system.file(samples, violet.jpg, package=biOps))
 cat(Image Type, imageType(x))
Image Type rgb

 x
size:  499 x 333
type:  rgb
 plot(x)

(And plotting to the tiff device produces a nice flower, despite what  
capabilities says.)


Best of luck;

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

 sessionInfo()
R version 2.9.2 (2009-08-24)
x86_64-apple-darwin9.8.0

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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


other attached packages:
[1] biOps_0.2.1 gdata_2.6.1 Design_2.3-0foreign_0.8-37   
Hmisc_3.7-0

[6] survival_2.35-7

loaded via a namespace (and not attached):
[1] cluster_1.12.0  grid_2.9.2  gtools_2.6.1lattice_0.17-25  
tools_2.9.2


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

2009-09-27 Thread Petar Milin
Thanks all! I did not want to cause any trouble and, God forbid, 
offense. I thought, I asked a simple question to improve my 
understanding and R-skills.


It seems that there ain't single gospel truth about QQs. :-)

Thanks, again!
Best,
PM

Juliet Hannah wrote:

I think it's helpful to show the sampling variability in a QQ plot
under repeated
sampling. An example is given
in Venables, Ripley pg 86. The variance is higher at the tails. Even when the
distributions are the same, the QQ plot does not have to resemble a straight
line because of sampling. I don't think you can think of any one of these as the
correct plot.

Also, if the two
data sets have an equal number of points, the empirical qq plot is
simply a plot of
one sorted data set against the other. (Kundu, Statistical Computing, pg 42).


On Sun, Sep 27, 2009 at 9:06 AM, Duncan Murdoch murd...@stats.uwo.ca wrote:

Eric Thompson wrote:

The supposed example of a Q-Q plot is most certainly not how to make a
Q-Q plot. I don't even know where to start

First off, the two Q:s in the title of the plot stand for quantile,
not random. The answer supplied simply plots two sorted samples of
a distribution against each other. While this may resemble the general
shape of a QQ plot, that is where the similarities end.


The empirical quantiles of a sample are simply the sorted values. �You can
plot empirical quantiles of one sample versus some version of quantiles from
a distribution (what qqnorm does) or versus empirical quantiles of another
sample (what Sunil did). �The randomness in his demonstration did two
things: it generated some data, and it showed the variability of the plot
under repeated sampling.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 with downloading workspace file from a web address

2009-09-27 Thread Uwe Ligges



Paul Smith wrote:

Dear All,

To load a previously saved workspace, one can do the following:

load(/path/to/the/saved/workspace/file)

However, if the path to the saved workspace file is a web address, one
gets the following error:

«Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file
'http://phhs80.googlepages.com/workspace20090922', probable reason 'No
such file or directory'»

To circumvent this problem, one can download the saved workspace file
to a local folder with download.file() and the option

mode=wb

active.

My question is: Should not load() have the same mode option so that
everything could be done only with load() (and not with two
instructions: downaload.file() and load())?



How did you try?

Does load(url(http://phhs80.googlepages.com/workspace20090922;)) work 
for you?


Uwe Ligges



Thanks in advance,

Paul

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

2009-09-27 Thread David Winsemius


On Sep 27, 2009, at 11:49 AM, Douglas Bates wrote:


On Sat, Sep 26, 2009 at 11:33 PM, David Winsemius
dwinsem...@comcast.net wrote:
I am contemplating bringing in and merging three NHANES-III  
datasets from
the National Center for Health Statistics that are fixed format  
with record
length=3348, line counts around 20,000 and described by SAS DATA  
steps. I
have downloaded and linked similar datasets from the Continuous  
NHANES
public data releases, but never ones with this many variables at  
once. In
the prior effort I managed the task by some cut-paste-editing from  
the SAS
code file into a corresponding read.fwf R call, but the earlier  
NHANES-III
data is far more voluminous than the more recent Continuous  
version. I am
wondering if anyone has experience with such a process and would be  
willing

to share some advice? The SAS code can be seen here:



ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/adult.sas



The main code file Data step starts out...
   FILENAME ADULT D:\Questionnaire\DAT\ADULT.DAT LRECL=3348;
   *** LRECL includes 2 positions for CRLF, assuming use of PC SAS;
   DATA WORK;
 INFILE ADULT MISSOVER;
 LENGTH
   SEQN  7
   DMPFSEQ   5
   DMPSTAT   3
   DMARETHN  3
   DMARACER  3
   DMAETHNR  3
   HSSEX 3
The corresponding positions in the INPUT section are
INPUT
   SEQN 1-5
   DMPFSEQ  6-10
   DMPSTAT  11
   DMARETHN 12
   DMARACER 13
   DMAETHNR 14
   HSSEX15
The note about CRLF appears to be implying that those characters  
are being
counted as part of the length of the first variable, SEQN, but that  
there
are only 5 meaningful positions. I suppose I can find out by trial  
and error
how to read such files, but it would save me some time if anyone in  
the

audience has worked through this on this data before.
One thought would be to import the data with the SAS work-alike  
program,
WKS, (which I have not used before) and then to read in with  
read.xport from
the foreign library. That would obviate the need to understand the  
character
position issue, but probably has a time commitment to get it up and  
running

and learn how to use it.
Another thought would be to parse the fixed width SAS Data step  
code into
pieces and build a data.frame from which I then extract the  
row.names,

col.names, and colClasses from that centralized structure.


Are the data available to the public somewhere or could just a few
records be made available?


Yes. Just trim the file name and the CDC ftp server accepts the path  
specification:


ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/

The file that goes with that SAS code is adult.dat

ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/adult.dat



The reason I ask is because I imagine there are a lot of missing data
in each record (the data are arranged in the wide format for
longitudinal data and includes follow-up questions that will not apply
to most respondents).  The missing data indicator, if any, and the
format of the other fields will be important in deciding how to split
the data.


Thanks for that. It was not designed as a longitudinal study, but  
rather as cross-sectional study that was spaced over several years.  
They did a re-exam of some sort, but that was not the primary purpose,  
nor will it be my particular interest. I have tried to determine by  
examination whether . or   is the missing value indicator and it  
appears that both may used although there are many more spaces. Most  
of the input suggests to my 15-year-old memories of SAS that the data  
is numeric but there are 17 variables where input spec is $nn


 varLines[grep([[:punct:]], varLines)]
 [1] HAX11AG  $6  HAX11AH  $6  HAX11AI   
$6
 [4] HAX11AJ  $6  HAX11AK  $6  HAX11AL   
$6
 [7] HAX11AM  $6  HAX11AN  $6  HAX11AO   
$6

[10] HAX11AP  $6  HAX11AQ  $6  HAX11AR  $6
[13] HAX11AS  $6  HAX11AT  $6  HAX11AU  $6
[16] HAX11AV  $6  HAZA1CC  $30

--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] for cycle with uncontinuous numbers

2009-09-27 Thread David Winsemius
You did not make test large enough to accept an index of 50 or any  
of the other numbers in x for that matter. On the first pass through  
that loop you to assigned to the 50 to the 50th element in test. If  
you wanted to assign 50 to the first element of test the you should  
look at the seq_along function:


 x - matrix( c(50,100,200,300,900,2343) ,ncol = 1)
 for (i in seq_along(x) ){
+ test [i] - x[i]
+ }
 test
 [,1]
[1,]   50
[2,]  100
[3,]  200
[4,]  300
[5,]  900
[6,] 2343



On Sep 27, 2009, at 11:45 AM, Marcio Resende wrote:



Dear John,
What I am trying to do is a genetic analysis and the i in my cycle  
are the

numbers of markers I am testing.
I know the code is not right, but what i wanted to do was to fill  
this 6 row

matrix with the numbers in x
So basically I wanted the cycle to loop only with the values on x
(50,100,200,300,900,2343) and not the the rest of the values
Do you know how to do it?

In the example I wanted my final test matrix to be
[50
100
200
300
900
2343]
dim(test) - still 6x1


And probably all zeroes, right?



Thanks for the help




jholtman wrote:


It is unclear exactly what you are trying to do.  Since your 'test'
matrix is only 6 rows in length, then when you extend it by trying to
store into 50 for example, it will fill in the rest of the new values
with NA.  Can you explain what you think the code is supposed to do?
It is doing exactly what you are asking it to do with the script you
provided.

On Sun, Sep 27, 2009 at 10:09 AM, Marcio Resende
mresende...@yahoo.com.br wrote:


Hi Tobias, thanks for the help,
the code I am using is quite long, but basically what I tried to  
do was


test - matrix(0,6,1)
x - matrix( c(50,100,200,300,900,2343) ,ncol = 1)
for (i in x){
test [i] - (i)
}

but this code returns NA for all the elements which are not x




Tobias Verbeke-2 wrote:



Hi nice people,


:-)

I would like to do a for cycle but i wish it to assume only the  
numers

50,
100, 200, 300, 900 and 2343
I tried to do something like

x - c(50,100,200,300,900,2343)
for (i in x){
#.
}

But it didn´t work


If you would use a reproducible code example we
could point out where the error comes from;
otherwise we can only tell this should work;
try

x - c(50,100,200,300,900,2343)
for (i in x){
   cat(i^2, \n)
}
# 2500
# 1
# 4
# 9
# 81
# 5489649

HTH,
Tobias

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




--
View this message in context:
http://www.nabble.com/for-cycle-with-uncontinuous-numbers-tp25630831p25633906.html
Sent from the R help mailing list archive at Nabble.com.

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





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

What is the problem that you are trying to solve?

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




--
View this message in context: 
http://www.nabble.com/for-cycle-with-uncontinuous-numbers-tp25630831p25634676.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
Heritage Laboratories
West Hartford, CT

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


Re: [R] Select.spatial on spplots

2009-09-27 Thread cls59



Julius Tesoro wrote:
 
 Hi everyone. I posted this on R-sig-geo but got no response. 
 
  
 Can select.spatial() be used in an existing spplot? I have tried selecting
 points (eq) from a plot generated from sp. However, when I invoke
 select.spatial(eq). It generates only the points without the background
 containing the faults. I need the background to select which earthquakes
 coalesce on which fault. Is there an alternative?
 
 eq.pts-list(sp.points,eq, col=blue, lwd=0.5, pch = 4)

 spplot(faults,Dip, xlim = c(11,12),
 ylim = c(376,389),
 sp.layout=list(eq.pts),
 col = heat.colors(3))
 
 select.spatial(eq)
 
 Cheers,
 
 Julius Tesoro
 
 


Unfortunately, it looks like select.spatial() wipes the plotting region by
executing it's own call to plot(). However, the function it's self is very,
very simple, just type:

select.spatial

To see what goes on inside. It looks like you could obtain point-wise
selection by just calling identify():

identify( coordinates( eq )[,1], coordinates( eq )[,2]

To use areas, call locator() and then process the results using
point.in.polygon().

As for whether this will work using a spplot-- I really couldn't say. I was
not able to reproduce a spplot using the information you provided-- lack of
a working example may be a reason you got nothing but silence on R-sig-geo.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Select.spatial-on-spplots-tp25632668p25635166.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] implementation of matrix logarithm (inverse of matrix exponential)

2009-09-27 Thread Charles C. Berry

On Sat, 26 Sep 2009, spencerg wrote:

Sylvester's formula (http://en.wikipedia.org/wiki/Sylvester%27s_formula) 
applies to a square matrix A = S L solve(S), where L = a diagonal matrix and 
S = matrix of eigenvectors.  Let f be an analytic function [for which f(A) 
is well defined].  Then f(A) = S f(L) solve(S). 

We can code this as follows: 


sylvester - function(x, f){
 n - nrow(x)
 eig - eigen(x)
 vi - solve(eig$vectors)
 with(eig, (vectors * rep(f(values), each=n)) %*% vi)
}


logm - function(x)sylvester(x, log)


Example: 


A - matrix(1:4, 2)
eA - expm(A)
logm(eA)


	  With Chuck Berry's example, we get the following: 


M - matrix( c(0,1,0,0), 2 )
sylvester(M, log)



The case I gave would be

sylvester( as.matrix( expm( M ) ), log )

for which the perfectly sensible answer is M,  not what appears here:



Error in solve.default(eig$vectors) :
 system is computationally singular: reciprocal condition number =
 1.00208e-292


	  This is a perfectly sensible answer in this case.  We get the same 
result from sylvester(M, exp), though expm(M) works fine. 

	  A better algorithm for this could be obtains by studying the code 
for expm in the Matrix package and the references in the associated help 
page.


I doubt that code already in R will handle cases requiring Jordan blocks 
for evaluation of the matrix logarithm (which cases arise in the context 
of discrete state, continuous time Markov chains) without requiring one to 
built that code more or less from scratch.


I'd be happy to hear that this is not so.

HTH,

Chuck



 Hope this helps. Spencer


Gabor Grothendieck wrote:

 Often one uses matrix logarithms on symmetric positive definite
 matrices so the assumption of being symmetric is sufficient in many
 cases.

 On Sat, Sep 26, 2009 at 7:28 PM, Charles C. Berry cbe...@tajo.ucsd.edu
 wrote:

  On Sat, 26 Sep 2009, Gabor Grothendieck wrote:
 
 
   OK. Try this:
  
  
library(Matrix)

M - matrix(c(2, 1, 1, 2), 2); M
   
  [,1] [,2]

   [1,]21
   [2,]12
  
  
  Right. expm( M ) is diagonalizable.
 
  But for
 
  M - matrix( c(0,1,0,0), 2 )
 
  you get the wrong result.
 
  Maybe I should have added that I do not see the machinery in R for 
  dealing

  with Jordan blocks.
 
  HTH,
 
  Chuck
 
 
 
 
# log of expm(M) is original matrix M

with(eigen(expm(M)), vectors %*% diag(log(values)) %*% t(vectors))
   
  [,1] [,2]

   [1,]21
   [2,]12
  
  
   On Sat, Sep 26, 2009 at 6:24 PM, Charles C. Berry 
   cbe...@tajo.ucsd.edu

   wrote:
  
On Sat, 26 Sep 2009, Gabor Grothendieck wrote:
   
   
 Try:

 expm( - M)

Mimosa probably meant say 'the inverse function'.
   
I do not see one in R.
   
Chuck
   
   
 On Sat, Sep 26, 2009 at 5:06 PM, Mimosa Zeus mimosa1...@yahoo.fr

 wrote:

  Dear R users,
 
  Does anyone has implemented the inverse of the matrix 
  exponential (expm

  in the package Matrix)?
 
  In Matlab, there're logm and expm, there's only expm in R.

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


Charles C. Berry(858) 534-2098

   Dept of Family/Preventive
Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego
92093-0901
   
   
   
   __

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

 Dept of Family/Preventive
  Medicine
  E mailto:cbe...@tajo.ucsd.edu   UC San Diego
  http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 
  92093-0901
 
 
 


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Fwd: generic methods - in particular the summary function

2009-09-27 Thread Christophe Dutang
Nobody wants to answer my question... is there something stupid in it?

Début du message réexpédié :

 De : Christophe Dutang duta...@gmail.com
 Date : 19 septembre 2009 11:26:51 HAEC
 À : r-help@r-project.org
 Objet : generic methods - in particular the summary function

 Hi all,

 I'm currently working on the fitdistrplus package (that basically  
 fit distributions). There is something I do not understand about the  
 generic function summary.

 In the current version on CRAN, there is no NAMESPACE saying

 S3method(summary, fitdist)

 .
 However if we use summary on an object send by fitdist function it  
 works fine...

 According to R-lang, we have
 
 The most common use of generic functions is to provide print and  
 summary methods for
 statistical ob jects, generally the output of some model fitting  
 process. To do this, each model
 attaches a class attribute to its output and then provides a special  
 method that takes that output
 and provides a nice readable version of it. The user then needs only  
 remember that print or
 summary will provide nice output for the results of any analysis.
 

 I would like to be sure, that if the summary.fitdist is not exported  
 in the NAMESPACE, then we must use declare it with S3method.

 Thanks in advance

 Christophe

 --
 Christophe Dutang
 Ph.D. student at ISFA, Lyon, France
 website: http://dutangc.free.fr


--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr







[[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] Fwd: generic methods - in particular the summary function

2009-09-27 Thread Uwe Ligges



Christophe Dutang wrote:

Nobody wants to answer my question... is there something stupid in it?


Maybe, or maybe just too much traffic on the lists these days.



Début du message réexpédié :


De : Christophe Dutang duta...@gmail.com
Date : 19 septembre 2009 11:26:51 HAEC
À : r-help@r-project.org
Objet : generic methods - in particular the summary function

Hi all,

I'm currently working on the fitdistrplus package (that basically  
fit distributions). There is something I do not understand about the  
generic function summary.


In the current version on CRAN, there is no NAMESPACE saying

S3method(summary, fitdist)

.
However if we use summary on an object send by fitdist function it  
works fine...


Yes, because your package's CRAN version does not have any namespace at 
all, hence nothing can be hidden in it.





According to R-lang, we have

The most common use of generic functions is to provide print and  
summary methods for
statistical ob jects, generally the output of some model fitting  
process. To do this, each model
attaches a class attribute to its output and then provides a special  
method that takes that output
and provides a nice readable version of it. The user then needs only  
remember that print or

summary will provide nice output for the results of any analysis.


I would like to be sure, that if the summary.fitdist is not exported  
in the NAMESPACE, then we must use declare it with S3method.


Right, and that's the way you should do it if you have a namespace (do 
not export the function but declare it as an S3 method). And yes, it is 
a good idea to add a namespace.


Best,
Uwe Ligges





Thanks in advance

Christophe

--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr



--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr







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

2009-09-27 Thread Uwe Ligges



Andrew Wang wrote:
I am trying to understand NLM package, so I generated this data set consisting y and x using 


y= a + b*x +c*x^2 + N(0,10), with a=3.5,b=4.5,c=5.5


Given y and x, I am trying to use NLM to have estimates of parameters a, b and c that minimize the least square error  


my code looks like
 
f- function(y,x,a,b,c) {sum((y-(a+b*x+c*x^2))^2)}

nlm(f, y, x, a=3, b=4,c=5)


But it comes up with rediculous result. My understanding of this NLM must be 
wrong.




See ?nlm for the arguments you have to pass to nlm() and how the 
function needs to be written. There are also some examples on that help 
page.


Uwe Ligges




Please help!

Andy

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 open only one file in a .gz file?

2009-09-27 Thread Uwe Ligges



Peng Yu wrote:

Hi,

Suppose that there are multiple files in a .gz file.


Well, the extension .gz regularly stand for a (single) gzip compressed 
file. Tyoically you will find more tan one file in a tar archive or a 
zip compressed archive. For the latter see ?unz.


Uwe Ligges




How to open only
one file in it? I don't find such options in the help.

Regards,
Peng

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Fwd: generic methods - in particular the summary function

2009-09-27 Thread David Winsemius


On Sep 27, 2009, at 12:52 PM, Christophe Dutang wrote:


Nobody wants to answer my question... is there something stupid in it?


I couldn't really say. Not being a user of fitdistrplus I don't have  
much baseline experience. Had you posted code that produced something  
to work on,  I might have made an effort at applying the methods I  
typically use, such as str(object), methods(function), and  
printing out the function code. But I am a rather low-level R-user,  
and as soon as you strart throwing around questions about NAMESPACE,  
my eyes glaze over and I move to the next question.


When I do install and load fitdistrplus and then execute:

methods(summary)

.. I see a new function which is not even invisible, called  
summary.fitdist. So it seems to be in my NAMESPACE   ... or at least  
what I dimly understand about such metaphysical entities. I get an  
error when I execute your suggestion:


 S3method(summary, fitdist)
Error: could not find function S3method

So I would have assumed that you had a package with that S3method  
function about which you had not informed us. Not sure this helps  
because, as I said, your question appeared more complex that I  
considered myself competent to answer.


--
David



Début du message réexpédié :


De : Christophe Dutang duta...@gmail.com
Date : 19 septembre 2009 11:26:51 HAEC
À : r-help@r-project.org
Objet : generic methods - in particular the summary function

Hi all,

I'm currently working on the fitdistrplus package (that basically
fit distributions). There is something I do not understand about the
generic function summary.

In the current version on CRAN, there is no NAMESPACE saying

S3method(summary, fitdist)

.
However if we use summary on an object send by fitdist function it
works fine...

According to R-lang, we have

The most common use of generic functions is to provide print and
summary methods for
statistical ob jects, generally the output of some model fitting
process. To do this, each model
attaches a class attribute to its output and then provides a special
method that takes that output
and provides a nice readable version of it. The user then needs only
remember that print or
summary will provide nice output for the results of any analysis.


I would like to be sure, that if the summary.fitdist is not exported
in the NAMESPACE, then we must use declare it with S3method.

Thanks in advance

Christophe

--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr



--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr







[[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
Heritage Laboratories
West Hartford, CT

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


Re: [R] error while plotting

2009-09-27 Thread Uwe Ligges



Nair, Murlidharan T wrote:

I am getting the following errors when I am trying to plot the data below. I 
cannot figure out the error.
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf


#I am using the following code
#==
library(multcomp)
sig.data-structure(list(X = 1:10, Cell.lines = structure(c(2L, 5L, 8L, 
9L, 3L, 6L, 10L, 1L, 4L, 7L), .Label = c(T(70%)a-N(0%)c, T(70%)a-N(0%)f, 
T(70%)a-N(0%)i, T(70%)c-N(0%)c, T(70%)c-N(0%)f, T(70%)c-N(0%)i, 
T(80%)a-N(0%)c, T(80%)a-N(0%)f, T(90%)-N(0%)f, T(90%)-N(0%)i
), class = factor), estimate = c(9859.74333, -5553.64802, 6227.17947, 
8063.6472, 6548.86032, -8864.53103, 4752.7642, 9057.72021, -6355.67115, 
5425.15635), lower = c(5560.57875, -9852.8126, 1928.01489, 3764.48262, 
2249.69575, -13163.69561, 453.59962, 4758.55563, -10654.83573, 
1125.99177), upper = c(14158.90791, -1254.48344, 10526.34405, 
12362.81178, 10848.0249, -4565.36645, 9051.92877, 13356.88479, 
-2056.50657, 9724.32092), p.val.raw = c(1.15e-08, 5.78e-05, 1.36e-05, 
3.21e-07, 6.91e-06, 6.97e-08, 0.000331, 4.87e-08, 1.04e-05, 7.63e-05
), p.val.bon = c(2.66e-06, 0.0133, 0.00315, 7.41e-05, 0.0016, 
1.61e-05, 0.0764, 1.13e-05, 0.0024, 0.0176), p.val.adj = c(2.65e-13, 
0.000592, 2.82e-05, 9.72e-08, 6.56e-05, 8.76e-09, 0.0117, 6.22e-09, 
6.44e-06, 0.000334)), .Names = c(X, Cell.lines, estimate, 
lower, upper, p.val.raw, p.val.bon, p.val.adj), class = data.frame, row.names = c(T(70%)a-N(0%)f, 
T(70%)c-N(0%)f, T(80%)a-N(0%)f, T(90%)-N(0%)f, T(70%)a-N(0%)i, 
T(70%)c-N(0%)i, T(90%)-N(0%)i, T(70%)a-N(0%)c, T(70%)c-N(0%)c, 
T(80%)a-N(0%)c))


rownames(sig.data)-sig.data[,2]
my.hmtest - structure(list(
  estimate = t(t(structure(sig.data[,estimate], .Names = 
rownames(sig.data,
  conf.int = sig.data[,4:5],
  ctype = ABCC4-2007),
  class = hmtest)
par(mex=0.5) #This helps to accomodate the margins when text is getting cut off
plot(my.hmtest, cex.axis=0.7)



There is not method plot.hmtest defined anywhere. Hence plot.default is 
used and that one does not know hoe to handle an object like the one you 
just defined.


Uwe Ligges



 


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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Check value interval in a if loop

2009-09-27 Thread Lucas Sevilla García

Hi R community

I have a little problem, and I tried to solve it by myself but I couldn't. I 
building an if loop, and I want to check a value inside an interval. This would 
be the case:

pvalue=0,2999

if(pvalue0.05 or pvalue0.1)

as you can see I would like to check in that if loop if my pvalue is inside of 
that interval(from 0.05 to 0.1), and I tried these options:

if(pvalue0.05 or pvalue0.1) (not possible because R don't recognise OR as 
operator)

if(pvalue0.05 || pvalue0.1) (this one is not good enough, cause it fulfills 
one condition pvalue0.05 but it doesn't get other contidion pvalue0.1)

does anyone know a way to stablish a inteval as an statement for my if loop.

Thanks in advance

Lucas
  
_


[[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] xtable - how to add a sum of values in a row column?

2009-09-27 Thread Ken-JP

Hi,

I saw this example for 2.10 Time series in the xtable gallery documentation.

http://cran.r-project.org/web/packages/xtable/vignettes/xtableGallery.pdf 

How would I add a column at the end Total which sums the row, with minimal
changes to the code below?

Thanks in advance.

- Ken

2.10 Time series
 temp.ts - ts(cumsum(1 + round(rnorm(100), 0)), start = c(1954,
+ 7), frequency = 12)
 temp.table - xtable(temp.ts, digits = 0)
 caption(temp.table) - Time series example
 print(temp.table, floating = FALSE)

Time series example
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1954 2 3 6 8 11 10
1955 11 13 15 16 16 18 20 22 21 22 24 24
1956 25 26 28 28 28 28 29 31 31 32 33 34
1957 35 36 38 39 39 41 42 42 41 42 43 45
1958 46 46 47 47 49 51 54 56 58 59 61 61
1959 62 61 62 62 62 63 62 64 64 66 67 68
1960 67 67 69 71 74 75 77 78 79 80 82 81
1961 84 86 87 88 89 91 94 94 94 94 96 97
1962 98 99 101 102 104 105 108 107 106 107


-- 
View this message in context: 
http://www.nabble.com/xtable---how-to-add-a-%22sum-of-values-in-a-row%22-column--tp25635552p25635552.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 open only one file in a .gz file?

2009-09-27 Thread Yihui Xie
gzfile() can handle a single file in *.gz. If you want to read one of
the files in a bunch of files, you may as well extract them first
using tar -zxvf yourarchive.tar.gz (sounds like a stupid solution),
or if you only want to use R, system() could help, e.g. system(tar
-zxvf yourarchive.tar.gz). You didn't tell us sessionInfo(), so I'm
not sure whether you are able to use the tar command.

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA



2009/9/27 Uwe Ligges lig...@statistik.tu-dortmund.de:


 Peng Yu wrote:

 Hi,

 Suppose that there are multiple files in a .gz file.

 Well, the extension .gz regularly stand for a (single) gzip compressed file.
 Tyoically you will find more tan one file in a tar archive or a zip
 compressed archive. For the latter see ?unz.

 Uwe Ligges



 How to open only
 one file in it? I don't find such options in the help.

 Regards,
 Peng


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] constraining covariance structure for random effects in lme

2009-09-27 Thread Nisha C. Gottfredson
I would like to impose a unique structure on the random effects 
covariance matrix in a multilevel model (i.e., a structure that is not 
included in the standard pdMat classes listed in Table 4.3 of Pinheiro 
and Bates' lme book).  Is there any way to manually impose equality 
constraints on the elements of the random effects covariance matrix?


Thank you.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Check value interval in a if loop

2009-09-27 Thread Uwe Ligges



Lucas Sevilla García wrote:

Hi R community

I have a little problem, and I tried to solve it by myself but I couldn't. I 
building an if loop, and I want to check a value inside an interval. This would 
be the case:

pvalue=0,2999

if(pvalue0.05 or pvalue0.1)

as you can see I would like to check in that if loop if my pvalue is inside of 
that interval(from 0.05 to 0.1), and I tried these options:

if(pvalue0.05 or pvalue0.1) (not possible because R don't recognise OR as 
operator)

if(pvalue0.05 || pvalue0.1) (this one is not good enough, cause it fulfills one 
condition pvalue0.05 but it doesn't get other contidion pvalue0.1)

does anyone know a way to stablish a inteval as an statement for my if loop.



1. if() is not used for constructing loops (and I think you know that)
2. You need an and operator rather than or, such as  (for vectors) 
or  (for scalar values).


Uwe Ligges




Thanks in advance

Lucas
 		 	   		  
_



[[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 CMD INSTALL --build: Folders /inst and /etc not in zip-file and WindowsXP locks /library/[package]/etc/

2009-09-27 Thread Uwe Ligges



Tobias Schoch wrote:

Dear R users,

My set-up: OS=Windows XP, R-2.9.2, Rtools210
I faced the follwing problem with the package compilation: There is no
/inst or /etc subdirectory in the package-zip-file. And the content of
the /etc subdirectory is lost, too. I tried a simplified test package.
The test package has the following structure (see also attachement: test
package as source file):

/test
   |---/inst
   | |---/etc
   |   |---menus.txt
   |
   |---/man
   | |---mymean.Rd
   | |---test-package.Rd
   |
   |---/R
   | |---mymean.R
   |
   |---NAMESPACE
   |---DESCRIPTION
   
The file menus.txt (inspired by the Rcmdr menu structure) contains one

single comment line. The file mymean.R contains a simple function that
computes the mean.

Situation A) [R CMD BUILD test] works fine and the tar-ball contains the
subdirectory /inst/etc/ and the file menus.txt.

Situation B) [R CMD INSTALL --build test] generates the test_1.0.zip file
without any error message. But: 1) This zip-file does neither contain the
/etc folder nor the menus.txt file. 2) The installation created the
folder /test in the library path /R-2.9.2/library/test/ , but this folder
is locked by WindowsXP. That is, the access is denied and can only be
resolved by re-defining the owner and the permission rights. 3) Having
removed the package from the library, and trying to install the zip-package
using install from local zip files... does the installation. But, the
/etc folder is empty; the file menus.txt is missing.



Probably the installation process in your Situation B) is never finished 
and hangs up due to misconfiguration of your tools or due to wrong 
permissions somewhere. I do not have any problem and explicitly tested 
with ./inst/etc/menus.txt (only difference is that I do not have exactly 
Rtools10 installed, but something that is extremely close).


Try to make a clean setup of all your tools and double check your PATH 
variable.


Best,
Uwe Ligges





Is there a known problem/bug in the R CMD INSTALL --build process dealing
with the subdirectories /inst and /etc and the contents of the these
folders? How to resolve the problem?

Thanks 
Tobias


http://www.nabble.com/file/p25609569/source_test.zip source_test.zip


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 with downloading workspace file from a web address

2009-09-27 Thread Paul Smith
2009/9/27 Uwe Ligges lig...@statistik.tu-dortmund.de:
 To load a previously saved workspace, one can do the following:

 load(/path/to/the/saved/workspace/file)

 However, if the path to the saved workspace file is a web address, one
 gets the following error:

 «Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
 In addition: Warning message:
 In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file
 'http://phhs80.googlepages.com/workspace20090922', probable reason 'No
 such file or directory'»

 To circumvent this problem, one can download the saved workspace file
 to a local folder with download.file() and the option

 mode=wb

 active.

 My question is: Should not load() have the same mode option so that
 everything could be done only with load() (and not with two
 instructions: downaload.file() and load())?


 How did you try?

 Does load(url(http://phhs80.googlepages.com/workspace20090922;)) work for
 you?

Thanks, Uwe, that works pretty fine!

Paul

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Check value interval in a if loop

2009-09-27 Thread Marcio Resende

Hi Lucas,
try:
if(pvalue0.05  pvalue0.1)

HTH
Marcio





Lucas Sevilla García wrote:
 
 
 Hi R community
 
 I have a little problem, and I tried to solve it by myself but I couldn't.
 I building an if loop, and I want to check a value inside an interval.
 This would be the case:
 
 pvalue=0,2999
 
 if(pvalue0.05 or pvalue0.1)
 
 as you can see I would like to check in that if loop if my pvalue is
 inside of that interval(from 0.05 to 0.1), and I tried these options:
 
 if(pvalue0.05 or pvalue0.1) (not possible because R don't recognise OR
 as operator)
 
 if(pvalue0.05 || pvalue0.1) (this one is not good enough, cause it
 fulfills one condition pvalue0.05 but it doesn't get other contidion
 pvalue0.1)
 
 does anyone know a way to stablish a inteval as an statement for my if
 loop.
 
 Thanks in advance
 
 Lucas
 
 _
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/Check-value-interval-in-a-if-loop-tp25635562p25635651.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] Clustering with R - efficient processing of large sparse data sets (text data)

2009-09-27 Thread dataguru
I checked the R procedure HCLUST (hierarchical clustering) but it
looks like it requires a full triangular n x n similarity matrix as
input, where n = number of observations. The number of variables is
200.

My data set has n = 50,000 observations (keywords), and I use ad-hoc
similarity measures, not available in R, to measure keyword
similarity. Here, the vast majority of the n x n similarities are
equal to zero.

So I am looking for a clustering procedure that would accept the
following alternate input:

x1, y1, s1
x2, y2, s2

...

xk, yk, sk

where xi, yi are 2 keywords with similarity si  0 (1 = i = k). This
input would contain k = 10,000 rows, which is much smaller than n x n
= 50,000 x 50,000 elements when using the similarity matrix. The
HCLUST function would crash if it used the dissimilarity matrix as
input.

Do you know how to use my small data input in R, instead of a very
large sparse similarity matrix? Or in SAS? I need a simple solution,
otherwise I'll just write myself the code that does hierarchical
clustering, in C or Perl, or use a library. It would take me 2 hours
to write the hierarchical clustering code from scratch, so I'm looking
for a simple solution that will take less than 2 hours to implement.

Follow up at 
http://www.analyticbridge.com/group/R_Packages/forum/topics/clustering-with-r-efficient

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Clustering with R - efficient processing of large sparse data sets (text data)

2009-09-27 Thread dataguru
I checked the R procedure HCLUST (hierarchical clustering) but it
looks like it requires a full triangular n x n similarity matrix as
input, where n = number of observations. The number of variables is
200.

My data set has n = 50,000 observations (keywords), and I use ad-hoc
similarity measures, not available in R, to measure keyword
similarity. Here, the vast majority of the n x n similarities are
equal to zero.

So I am looking for a clustering procedure that would accept the
following alternate input:

x1, y1, s1
x2, y2, s2

...

xk, yk, sk

where xi, yi are 2 keywords with similarity si  0 (1 = i = k). This
input would contain k = 10,000 rows, which is much smaller than n x n
= 50,000 x 50,000 elements when using the similarity matrix. The
HCLUST function would crash if it used the dissimilarity matrix as
input.

Do you know how to use my small data input in R, instead of a very
large sparse similarity matrix? Or in SAS? I need a simple solution,
otherwise I'll just write myself the code that does hierarchical
clustering, in C or Perl, or use a library. It would take me 2 hours
to write the hierarchical clustering code from scratch, so I'm looking
for a simple solution that will take less than 2 hours to implement.

Follow up at: 
http://www.analyticbridge.com/group/R_Packages/forum/topics/clustering-with-r-efficient

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] View this page R-Packages (Statistical Computing)

2009-09-27 Thread dataguru


Click on 
http://groups.google.com/group/r-help-archive/web/r-packages-statistical-computing
- or copy  paste it into your browser's address bar if that doesn't
work.

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


[R] View this page R-Packages (Statistical Computing)

2009-09-27 Thread dataguru


Click on 
http://groups.google.com/group/r-help-archive/web/r-packages-statistical-computing
- or copy  paste it into your browser's address bar if that doesn't
work.

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


Re: [R] Check value interval in a if loop

2009-09-27 Thread Jim Lemon

Lucas Sevilla García wrote:

Hi R community

I have a little problem, and I tried to solve it by myself but I 
couldn't. I building an if loop, and I want to check a value inside 
an interval. This would be the case:


pvalue=0,2999

if(pvalue0.05 or pvalue0.1)

as you can see I would like to check in that if loop if my pvalue is 
inside of that interval(from 0.05 to 0.1), and I tried these options:

Hi Lucas,
Your if statement is probably embedded in a loop like this:

for(mytest in 1:100) {
 pvalue-t.test(rnorm(50),rnorm(50))$p.value
 if(pvalue  0.05  pvalue  0.1) cat(Just missed!\n)
 else cat(I don't care\n)
}

so you only want it to test the current p value. If you want to get all 
the p values and test them later:


pvalue-rep(NA,100)
for(mytest in 1:100)
 pvalue[mytest]-t.test(rnorm(50),rnorm(50))$p.value
cat(c(Just missed\n,I don't care\n)
 [(pvalue  0.05  pvalue  0.1)+1])

Jim

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


[R] Count number of zeros in a collumn

2009-09-27 Thread Marcio Resende

I have a matrix 700x2000 which is sampled in each cycle from another matrix
788x2000 with the numbers 0,1 and 9

There is one specific collumn of this matrix, dart[,1977], that usually,
after the samplimg procedure has only 1 and 9 (because the zero frequency in
this collumn is low).
However, when this happens, I want to include an IF conditional in my code.
so basically what i wanted to do was to count the number of zeros in this
collumn to use this information in my conditional:

something like:

if (the number of zeros in collumn [,1977] is zero) ... else ...

I tried to find out indirectly by the rowsum but because of the sampling
procedure the rowsum is not always the same

Thank you very much
-- 
View this message in context: 
http://www.nabble.com/Count-number-of-zeros-in-a-collumn-tp25637516p25637516.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] QQ plotting of various distributions...

2009-09-27 Thread Eric Thompson
It seems I misunderstood Sunil's response and somewhat freaked out
because it appeared that he was giving the wrong method for making a
QQ plot, but was actually demonstrating the sampling variability. My
apologies to Sunil.



2009/9/27 Duncan Murdoch murd...@stats.uwo.ca:
 Eric Thompson wrote:

 The supposed example of a Q-Q plot is most certainly not how to make a
 Q-Q plot. I don't even know where to start

 First off, the two Q:s in the title of the plot stand for quantile,
 not random. The answer supplied simply plots two sorted samples of
 a distribution against each other. While this may resemble the general
 shape of a QQ plot, that is where the similarities end.


 The empirical quantiles of a sample are simply the sorted values.  You can
 plot empirical quantiles of one sample versus some version of quantiles from
 a distribution (what qqnorm does) or versus empirical quantiles of another
 sample (what Sunil did).  The randomness in his demonstration did two
 things: it generated some data, and it showed the variability of the plot
 under repeated sampling.

 Some general advice: be careful who you take advice from on the
 internet.

 That's good advice.

 Duncan Murdoch

 The Wikipedia entry for Q-Q plot may be a good start if you
 don't know what a Q-Q plot is, although you should also use it with
 caution.

 Lets say you have some samples that may be normally distributed:

 set.seed(1)
 x - rnorm(30)

 # now try with R's built in function
 qqnorm(x, xlim = c(-3, 3), ylim = c(-3, 3))

 # Now try Sunil's Q-Q plot method, but for rnorm
 # rather than rgamma
 some_data - x
 test_data - rnorm(30)
 points(sort(some_data),sort(test_data), col = blue)

 # Note that the points are NOT the same!

 This should have been obvious for the simple reason that the QQ plot
 should not be influenced by the random number generator that you are
 using! A QQ plot is uniquely reproducible. The more general (and
 correct) way to get the QQ plot involves choosing a plotting position
 and the quantile function (e.g. qnorm or qgamma functions in R) of the
 pertinent distribution:

 # Sort the data:
 x.s - sort(x)
 n - length(x)

 # Plotting position (must be careful here in general!)
 p - ppoints(n)

 # Compute the quantile
 x.q - qnorm(p)

 points(x.q, x.s, col = red)

 # and they fall exactly on the points generated by qqnorm().

 Now, you should be able to generalize this for any distribution. Hope
 this helps.


 Eric Thompson




 2009/9/27 Petar Milin pmi...@ff.uns.ac.rs:


 Thanks for the answer. Now, only problem is to to get parameter(s) of a
 given function. For gamma, I shall try with gammafit() from mhsmm
 package.
 Also, I shall look for others appropriate parameter estimates. Will use
 SuppDists too.

 Best,
 PM

 Sunil Suchindran wrote:


 #same shape

 some_data - rgamma(500,shape=6,scale=2)
 test_data - rgamma(500,shape=6,scale=2)
 plot(sort(some_data),sort(test_data))
 # You can also use qqplot(some_data,test_data)
 abline(0,1)

 # different shape

 some_data - rgamma(500,shape=6,scale=2)
 test_data - rgamma(500,shape=4,scale=2)
 plot(sort(some_data),sort(test_data))
 abline(0,1)

 It is helpful to assess the sampling variability, by
 creating repeated sets of test_data, and plotting
 all of these along with your observations to create
 a confidence envelope.

 The SuppDists provides Inverse Gauss.


 On Thu, Sep 17, 2009 at 11:46 AM, Petar Milin pmi...@ff.uns.ac.rs
 wrote:

   Hello!
   I am trying with this question again:
   I would like to test few distributional assumptions for some
   behavioral response data. There are few theories about true
   distribution of those data, like: normal, lognormal, gamma,
   ex-Gaussian (exponential-Gaussian), Wald (inverse Gaussian) etc. The
   best way would be via qq-plot, to show to students differences.
   First two are trivial:
   qqnorm(dat$X)
   qqnorm(log(dat$X))
   Then, things are getting more hairy. I am not sure how to make
   plots for the rest. I tried gamma with:
   qqmath(~ X, data=dat, distribution=function(X)
   � qgamma(X, shape, scale))
   Which should be the same as:
   plot(qgamma(ppoints(dat$X), shape, scale), sort(dat$X))
   Shape and scale parameters I got via mhsmm package that has
   gammafit() for shape and scale parameters estimation.
   Am I on right track? Does anyone know how to plot the rest:
   ex-Gaussian (exponential-Gaussian), Wald (inverse Gaussian)?

   Thanks,
   PM

   __
   R-help@r-project.org mailto:R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
   http://www.R-project.org/posting-guide.html
   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
 

Re: [R] Count number of zeros in a collumn

2009-09-27 Thread milton ruser
Hi Marcio,

How about if (min(dart[,1977])==0)...

cheers
milton

On Sun, Sep 27, 2009 at 4:54 PM, Marcio Resende mresende...@yahoo.com.brwrote:


 I have a matrix 700x2000 which is sampled in each cycle from another matrix
 788x2000 with the numbers 0,1 and 9

 There is one specific collumn of this matrix, dart[,1977], that usually,
 after the samplimg procedure has only 1 and 9 (because the zero frequency
 in
 this collumn is low).
 However, when this happens, I want to include an IF conditional in my code.
 so basically what i wanted to do was to count the number of zeros in this
 collumn to use this information in my conditional:

 something like:

 if (the number of zeros in collumn [,1977] is zero) ... else ...

 I tried to find out indirectly by the rowsum but because of the sampling
 procedure the rowsum is not always the same

 Thank you very much
 --
 View this message in context:
 http://www.nabble.com/Count-number-of-zeros-in-a-collumn-tp25637516p25637516.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.htmlhttp://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] RSQLite column names underscores

2009-09-27 Thread Christopher Bare
Hi,

When I use RSQLite's dbWriteTable(...) function, the columns in the db
table frequently end up having __1 (two underscores and a one) added
to them. The names are unique within the table and contain no weird
characters. For example a position column from a data.frame was
written to the DB as position__1.

Does anyone understand how this name munging happens and how I can
prevent or work around it? Having these suffixes added seemingly
arbitrarily makes it hard to construct the next query.

Thanks for any hints,

-chris

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] rsolnp- Error (Help!)

2009-09-27 Thread tushar_kul

Hi 

I am relatively new to R and was trying to run an optimization problem using
rsolnp. I am getting an error which seems to be not related to my construct
of the optimization equations.  

Error in if (max(tt[2] - 10 * tol, nineq) = 0) rho = 0 : 
  missing value where TRUE/FALSE needed

I have attached the file code. 

I would greatly appreciate any help. 

Many thanks 

http://www.nabble.com/file/p25637806/OptTS.txt OptTS.txt 


-- 
View this message in context: 
http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25637806.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] RSQLite column names underscores

2009-09-27 Thread Gabor Grothendieck
You are probably trying to use SQL reserved keywords as column names.
Try entering this at the R prompt:

library(RSQLite)
.SQL92Keywords

On Sun, Sep 27, 2009 at 5:25 PM, Christopher Bare
cb...@systemsbiology.org wrote:
 Hi,

 When I use RSQLite's dbWriteTable(...) function, the columns in the db
 table frequently end up having __1 (two underscores and a one) added
 to them. The names are unique within the table and contain no weird
 characters. For example a position column from a data.frame was
 written to the DB as position__1.

 Does anyone understand how this name munging happens and how I can
 prevent or work around it? Having these suffixes added seemingly
 arbitrarily makes it hard to construct the next query.

 Thanks for any hints,

 -chris

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

2009-09-27 Thread David Winsemius


On Sep 27, 2009, at 12:10 PM, David Winsemius wrote:



On Sep 27, 2009, at 11:49 AM, Douglas Bates wrote:


On Sat, Sep 26, 2009 at 11:33 PM, David Winsemius
dwinsem...@comcast.net wrote:
I am contemplating bringing in and merging three NHANES-III  
datasets from
the National Center for Health Statistics that are fixed format  
with record
length=3348, line counts around 20,000 and described by SAS DATA  
steps. I
have downloaded and linked similar datasets from the Continuous  
NHANES
public data releases, but never ones with this many variables at  
once. In
the prior effort I managed the task by some cut-paste-editing from  
the SAS
code file into a corresponding read.fwf R call, but the earlier  
NHANES-III
data is far more voluminous than the more recent Continuous  
version. I am
wondering if anyone has experience with such a process and would  
be willing

to share some advice? The SAS code can be seen here:



ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/adult.sas



The main code file Data step starts out...
  FILENAME ADULT D:\Questionnaire\DAT\ADULT.DAT LRECL=3348;
  *** LRECL includes 2 positions for CRLF, assuming use of PC SAS;
  DATA WORK;
INFILE ADULT MISSOVER;
LENGTH
  SEQN  7
  DMPFSEQ   5
  DMPSTAT   3
  DMARETHN  3
  DMARACER  3
  DMAETHNR  3
  HSSEX 3
The corresponding positions in the INPUT section are
   INPUT
  SEQN 1-5
  DMPFSEQ  6-10
  DMPSTAT  11
  DMARETHN 12
  DMARACER 13
  DMAETHNR 14
  HSSEX15
The note about CRLF appears to be implying that those characters  
are being
counted as part of the length of the first variable, SEQN, but  
that there
are only 5 meaningful positions. I suppose I can find out by trial  
and error
how to read such files, but it would save me some time if anyone  
in the

audience has worked through this on this data before.
One thought would be to import the data with the SAS work-alike  
program,
WKS, (which I have not used before) and then to read in with  
read.xport from
the foreign library. That would obviate the need to understand the  
character
position issue, but probably has a time commitment to get it up  
and running

and learn how to use it.
Another thought would be to parse the fixed width SAS Data step  
code into
pieces and build a data.frame from which I then extract the  
row.names,

col.names, and colClasses from that centralized structure.


Are the data available to the public somewhere or could just a few
records be made available?


Yes. Just trim the file name and the CDC ftp server accepts the path  
specification:


ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/

The file that goes with that SAS code is adult.dat

ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/adult.dat



The reason I ask is because I imagine there are a lot of missing data
in each record (the data are arranged in the wide format for
longitudinal data and includes follow-up questions that will not  
apply

to most respondents).  The missing data indicator, if any, and the
format of the other fields will be important in deciding how to split
the data.


Thanks for that. It was not designed as a longitudinal study, but  
rather as cross-sectional study that was spaced over several years.  
They did a re-exam of some sort, but that was not the primary  
purpose, nor will it be my particular interest. I have tried to  
determine by examination whether . or   is the missing value  
indicator and it appears that both may used although there are many  
more spaces. Most of the input suggests to my 15-year-old memories  
of SAS that the data is numeric but there are 17 variables where  
input spec is $nn


 varLines[grep([[:punct:]], varLines)]
[1] HAX11AG  $6  HAX11AH  $6  HAX11AI   
$6
[4] HAX11AJ  $6  HAX11AK  $6  HAX11AL   
$6
[7] HAX11AM  $6  HAX11AN  $6  HAX11AO   
$6
[10] HAX11AP  $6  HAX11AQ  $6  HAX11AR   
$6
[13] HAX11AS  $6  HAX11AT  $6  HAX11AU   
$6

[16] HAX11AV  $6  HAZA1CC  $30



My progress on this effort so far consists of having figured out how  
to extract the variable names and their associated lengths so I can  
set up a call to read.fwf(). This is waht I did on hte section of the  
SAS code following INPUT that contains those elements:


trim.ws - function(x) gsub(^[[:space:]]+|[[:space:]]+$, ,x)
# courtesy of a Grothendieck r-help posting of a couple or three years  
ago.


adult.var - data.frame(varnames =  
sapply( strsplit(trim.ws(varLines) ,  +) ,  [, 1:2)[1,], varlen=  
sapply( strsplit(trim.ws(varLines) ,  +) ,  [, 1:2)[2,])
#so that I can split the trimmed strings on an arbitrary number of  
spaces.


 adult.var[,][1:5,]
  varnames varlen
1 SEQN  7
2  DMPFSEQ  5
3  DMPSTAT  3
4 DMARETHN  3
5 DMARACER  3

 

Re: [R] implementation of matrix logarithm (inverse of matrix exponential)

2009-09-27 Thread Douglas Bates
There is a logm function in the expm package in the expm project on
R-forge.  See http://expm.R-forge.R-project.org/

Martin was the person who added that function so I will defer to his
explanations of what it does.  I know he has been traveling and it may
be a day or two before he can get to this thread.

On Sun, Sep 27, 2009 at 11:44 AM, Charles C. Berry cbe...@tajo.ucsd.edu wrote:
 On Sat, 26 Sep 2009, spencerg wrote:

    Sylvester's formula
 (http://en.wikipedia.org/wiki/Sylvester%27s_formula) applies to a square
 matrix A = S L solve(S), where L = a diagonal matrix and S = matrix of
 eigenvectors.  Let f be an analytic function [for which f(A) is well
 defined].  Then f(A) = S f(L) solve(S).
    We can code this as follows:
 sylvester - function(x, f){
  n - nrow(x)
  eig - eigen(x)
  vi - solve(eig$vectors)
  with(eig, (vectors * rep(f(values), each=n)) %*% vi)
 }


 logm - function(x)sylvester(x, log)


 Example:
 A - matrix(1:4, 2)
 eA - expm(A)
 logm(eA)


          With Chuck Berry's example, we get the following:
 M - matrix( c(0,1,0,0), 2 )
 sylvester(M, log)


 The case I gave would be

        sylvester( as.matrix( expm( M ) ), log )

 for which the perfectly sensible answer is M,  not what appears here:


 Error in solve.default(eig$vectors) :
  system is computationally singular: reciprocal condition number =
  1.00208e-292


          This is a perfectly sensible answer in this case.  We get the
 same result from sylvester(M, exp), though expm(M) works fine.
          A better algorithm for this could be obtains by studying the code
 for expm in the Matrix package and the references in the associated help
 page.

 I doubt that code already in R will handle cases requiring Jordan blocks for
 evaluation of the matrix logarithm (which cases arise in the context of
 discrete state, continuous time Markov chains) without requiring one to
 built that code more or less from scratch.

 I'd be happy to hear that this is not so.

 HTH,

 Chuck


     Hope this helps. Spencer


 Gabor Grothendieck wrote:

  Often one uses matrix logarithms on symmetric positive definite
  matrices so the assumption of being symmetric is sufficient in many
  cases.

  On Sat, Sep 26, 2009 at 7:28 PM, Charles C. Berry cbe...@tajo.ucsd.edu
  wrote:

   On Sat, 26 Sep 2009, Gabor Grothendieck wrote:
  OK. Try this:
 library(Matrix)
 M - matrix(c(2, 1, 1, 2), 2); M
      [,1] [,2]
    [1,]    2    1
    [2,]    1    2
   Right. expm( M ) is diagonalizable.
    But for
    M - matrix( c(0,1,0,0), 2 )
    you get the wrong result.
    Maybe I should have added that I do not see the machinery in R for 
    dealing
   with Jordan blocks.
    HTH,
    Chuck
 # log of expm(M) is original matrix M
 with(eigen(expm(M)), vectors %*% diag(log(values)) %*% t(vectors))
      [,1] [,2]
    [1,]    2    1
    [2,]    1    2
    On Sat, Sep 26, 2009 at 6:24 PM, Charles C. Berry  
    cbe...@tajo.ucsd.edu
    wrote:
   On Sat, 26 Sep 2009, Gabor Grothendieck wrote:
    Try:
  expm( - M)
 Mimosa probably meant say 'the inverse function'.
    I do not see one in R.
    Chuck
    On Sat, Sep 26, 2009 at 5:06 PM, Mimosa Zeus
   mimosa1...@yahoo.fr
  wrote:
   Dear R users,
    Does anyone has implemented the inverse of the
   matrix   exponential (expm
   in the package Matrix)?
    In Matlab, there're logm and expm, there's only expm
   in R.
   Cheers
   Mimosa
         [[alternative HTML
 version deleted]]
   
 __
   r-h...@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/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-h...@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible
 code.
 Charles C. Berry                            (858)
534-2098
                                            Dept of
Family/Preventive
 Medicine
 E mailto:cbe...@tajo.ucsd.edu               UC San Diego
 http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego
 92093-0901
 __
    r-h...@r-project.org mailing list
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide
    http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.
   Charles C. Berry               

Re: [R] array to matrix or data.frame

2009-09-27 Thread David Winsemius


On Sep 27, 2009, at 6:33 PM, Daniel Malter wrote:



Hi, I have an array of dimension 6:6:16. I want to stack the  
16

slices of the array into a matrix or a data frame of dimension
6:(6*16=96) in order to write it to a csv file. It seems I  
cannot
get the matrix or data.frame functions to put the values from the  
array in
the same order as they appear in the array easily, but I am almost  
sure

there is an easy way to do this.

#Here is code for a small 6:6:2 array.

x=rep(rep(1:6,each=6),2)
dim(x)=c(6,6,2)

x

#Matrix approach 1:

matrix(x,nrow=12,ncol=6,byrow=F)

#Matrix approach 2:

matrix(x,nrow=12,ncol=6,byrow=T)

#Data frame approach (cbinds rather than rbinds):

data.frame(x)

None of the above works as I would like to. The correct approach  
should
stack the same values all in the same column of the matrix or data  
frame. I
also could not get stack to work correctly and would appreciate  
your help.


apply(x, 2 , I)
  [,1] [,2] [,3] [,4] [,5] [,6]
 [1,]123456
 [2,]123456
 [3,]123456
 [4,]123456
 [5,]123456
 [6,]123456
 [7,]123456
 [8,]123456
 [9,]123456
[10,]123456
[11,]123456
[12,]123456

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] array to matrix or data.frame

2009-09-27 Thread Gabor Grothendieck
Try this:

matrix(aperm(x, c(1,3,2)), nc = 6)


On Sun, Sep 27, 2009 at 6:33 PM, Daniel Malter dan...@umd.edu wrote:

 Hi, I have an array of dimension 6:6:16. I want to stack the 16
 slices of the array into a matrix or a data frame of dimension
 6:(6*16=96) in order to write it to a csv file. It seems I cannot
 get the matrix or data.frame functions to put the values from the array in
 the same order as they appear in the array easily, but I am almost sure
 there is an easy way to do this.

 #Here is code for a small 6:6:2 array.

 x=rep(rep(1:6,each=6),2)
 dim(x)=c(6,6,2)

 x

 #Matrix approach 1:

 matrix(x,nrow=12,ncol=6,byrow=F)

 #Matrix approach 2:

 matrix(x,nrow=12,ncol=6,byrow=T)

 #Data frame approach (cbinds rather than rbinds):

 data.frame(x)

 None of the above works as I would like to. The correct approach should
 stack the same values all in the same column of the matrix or data frame. I
 also could not get stack to work correctly and would appreciate your help.

 Daniel



 --
 View this message in context: 
 http://www.nabble.com/array-to-matrix-or-data.frame-tp25638310p25638310.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


[R] dimension-preserving matrix coersion

2009-09-27 Thread Murat Tasan
i've written a function to coerce a matrix (e.g. from numeric to
logical), but i'd like to know if someone has a more elegant method
for this:

 m - matrix(c(0, 1, 1, 0), ncol = 2)
 m - as.logical(m)
 m
[1] FALSE TRUE TRUE FALSE

i'd like 'm' to still be a matrix with the original dimensions.  in my
function to do this, i coerce 'm' to a logical, then re-form it as a
matrix, which seems like an extra (possibly bug-introducing) step that
might be avoided if i knew of some hidden feature that might permit
this in one fell swoop.

any ideas?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] array to matrix or data.frame

2009-09-27 Thread Rolf Turner


On 28/09/2009, at 11:51 AM, David Winsemius wrote:

snip


apply(x, 2 , I)


snip

***Much*** sexier than my solution!

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] rsolnp- Error (Help!)

2009-09-27 Thread jim holtman
It means that your expression max(tt[2] - 10 * tol, nineq) is returning NA:

Notice I get the same error:

 if (1==1)1
[1] 1
 if (NA == 1) 1
Error in if (NA == 1) 1 : missing value where TRUE/FALSE needed

Check your script and see why it is NA.  you might need:

max(tt[2] - 10 * tol, nineq, na.rm=TRUE)

If your data has NAs.

On Sun, Sep 27, 2009 at 5:29 PM, tushar_kul tus...@gmail.com wrote:

 Hi

 I am relatively new to R and was trying to run an optimization problem using
 rsolnp. I am getting an error which seems to be not related to my construct
 of the optimization equations.

 Error in if (max(tt[2] - 10 * tol, nineq) = 0) rho = 0 :
  missing value where TRUE/FALSE needed

 I have attached the file code.

 I would greatly appreciate any help.

 Many thanks

 http://www.nabble.com/file/p25637806/OptTS.txt OptTS.txt


 --
 View this message in context: 
 http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25637806.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

What is the problem that you are trying to solve?

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

2009-09-27 Thread jim holtman
How about this:

 m - matrix(c(0, 1, 1, 0), ncol = 2)
 mode(m) - 'logical'
 m
  [,1]  [,2]
[1,] FALSE  TRUE
[2,]  TRUE FALSE



On Sun, Sep 27, 2009 at 6:59 PM, Murat Tasan mmu...@gmail.com wrote:
 i've written a function to coerce a matrix (e.g. from numeric to
 logical), but i'd like to know if someone has a more elegant method
 for this:

 m - matrix(c(0, 1, 1, 0), ncol = 2)
 m - as.logical(m)
 m
 [1] FALSE TRUE TRUE FALSE

 i'd like 'm' to still be a matrix with the original dimensions.  in my
 function to do this, i coerce 'm' to a logical, then re-form it as a
 matrix, which seems like an extra (possibly bug-introducing) step that
 might be avoided if i knew of some hidden feature that might permit
 this in one fell swoop.

 any ideas?

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




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

What is the problem that you are trying to solve?

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


Re: [R] dimension-preserving matrix coersion

2009-09-27 Thread Murat Tasan
HA!  yeah, that'll do it!  forgot that mode() can be used to set modes
as well as get them.

thanks much!

-murat

On Sep 27, 7:10 pm, jim holtman jholt...@gmail.com wrote:
 How about this:

  m - matrix(c(0, 1, 1, 0), ncol = 2)
  mode(m) - 'logical'
  m

       [,1]  [,2]
 [1,] FALSE  TRUE
 [2,]  TRUE FALSE







 On Sun, Sep 27, 2009 at 6:59 PM, Murat Tasan mmu...@gmail.com wrote:
  i've written a function to coerce a matrix (e.g. from numeric to
  logical), but i'd like to know if someone has a more elegant method
  for this:

  m - matrix(c(0, 1, 1, 0), ncol = 2)
  m - as.logical(m)
  m
  [1] FALSE TRUE TRUE FALSE

  i'd like 'm' to still be a matrix with the original dimensions.  in my
  function to do this, i coerce 'm' to a logical, then re-form it as a
  matrix, which seems like an extra (possibly bug-introducing) step that
  might be avoided if i knew of some hidden feature that might permit
  this in one fell swoop.

  any ideas?

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

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

 What is the problem that you are trying to solve?

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

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


[R] Determining name of calling function.

2009-09-27 Thread Rolf Turner


I have vague recollections of seeing this question discussed on r-help
previously, but I can't find the relevant postings.

I want to determine (from within a given function) the name of the  
function

calling that given function.

E.g. if I have a function foo() which calls a function bar(), and also
a function clyde() which calls bar(), I want to have, in the code of  
bar(),

an instruction which will return the character string foo if bar() was
called from foo() and the string clyde if bar() was called from  
clyde().


Without really understanding what I'm doing I cobbled together the  
following:


fname - as.character(sys.call(-1))[1]

This ***seems*** to work, at least in simple test cases.

But is it reliably robust?  Are there traps for young players that I am
not seeing?

My ``solution'' returns NA as the value of fname if bar() is called  
from the
command line, rather than being called by foo() or clyde().  This is  
acceptable.

I think 

Any avuncular advice from those younger and wiser than myself? :-)

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] array to matrix or data.frame

2009-09-27 Thread Daniel Malter

Works a charme; thanks much everybody. Daniel.


David Winsemius wrote:
 
 
 On Sep 27, 2009, at 6:33 PM, Daniel Malter wrote:
 

 Hi, I have an array of dimension 6:6:16. I want to stack the  
 16
 slices of the array into a matrix or a data frame of dimension
 6:(6*16=96) in order to write it to a csv file. It seems I  
 cannot
 get the matrix or data.frame functions to put the values from the  
 array in
 the same order as they appear in the array easily, but I am almost  
 sure
 there is an easy way to do this.

 #Here is code for a small 6:6:2 array.

 x=rep(rep(1:6,each=6),2)
 dim(x)=c(6,6,2)

 x

 #Matrix approach 1:

 matrix(x,nrow=12,ncol=6,byrow=F)

 #Matrix approach 2:

 matrix(x,nrow=12,ncol=6,byrow=T)

 #Data frame approach (cbinds rather than rbinds):

 data.frame(x)

 None of the above works as I would like to. The correct approach  
 should
 stack the same values all in the same column of the matrix or data  
 frame. I
 also could not get stack to work correctly and would appreciate  
 your help.
 
 apply(x, 2 , I)
[,1] [,2] [,3] [,4] [,5] [,6]
   [1,]123456
   [2,]123456
   [3,]123456
   [4,]123456
   [5,]123456
   [6,]123456
   [7,]123456
   [8,]123456
   [9,]123456
 [10,]123456
 [11,]123456
 [12,]123456
 
 -- 
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/array-to-matrix-or-data.frame-tp25638310p25638689.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] dimension-preserving matrix coersion

2009-09-27 Thread William Dunlap

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Murat Tasan
 Sent: Sunday, September 27, 2009 3:59 PM
 To: r-help@r-project.org
 Subject: [R] dimension-preserving matrix coersion
 
 i've written a function to coerce a matrix (e.g. from numeric to
 logical), but i'd like to know if someone has a more elegant method
 for this:
 
  m - matrix(c(0, 1, 1, 0), ncol = 2)
  m - as.logical(m)
  m
 [1] FALSE TRUE TRUE FALSE
 
 i'd like 'm' to still be a matrix with the original dimensions.  in my
 function to do this, i coerce 'm' to a logical, then re-form it as a
 matrix, which seems like an extra (possibly bug-introducing) step that
 might be avoided if i knew of some hidden feature that might permit
 this in one fell swoop.

  m - m != 0
will do it, as will
  mode(m) - logical

The former has the advantage that you don't have to use the
canonical mapping of 0-FALSE,anything else-TRUE, but
can use any standard comparison or vectorized logical operator.
It also seems cleaner in that it can be used inside a larger expression,
like m[m!=0].

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

 
 any ideas?
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Count number of zeros in a collumn

2009-09-27 Thread Murat Tasan
more generally, if you want to test for some minimum threshold T on
the number of zeros, try:

 if(length(which(dart[,1977] == 0))  T) { # some code to handle the 
 too-few-zeros-case }




On Sep 27, 4:54 pm, Marcio Resende mresende...@yahoo.com.br wrote:
 I have a matrix 700x2000 which is sampled in each cycle from another matrix
 788x2000 with the numbers 0,1 and 9

 There is one specific collumn of this matrix, dart[,1977], that usually,
 after the samplimg procedure has only 1 and 9 (because the zero frequency in
 this collumn is low).
 However, when this happens, I want to include an IF conditional in my code.
 so basically what i wanted to do was to count the number of zeros in this
 collumn to use this information in my conditional:

 something like:

 if (the number of zeros in collumn [,1977] is zero) ... else ...

 I tried to find out indirectly by the rowsum but because of the sampling
 procedure the rowsum is not always the same

 Thank you very much
 --
 View this message in 
 context:http://www.nabble.com/Count-number-of-zeros-in-a-collumn-tp25637516p2...
 Sent from the R help mailing list archive at Nabble.com.

 __
 r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://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] Determining name of calling function.

2009-09-27 Thread Gabor Grothendieck
Not sure if this is important to you but R functions don't have to
have names so what you get back won't be a name if the function was
anonymous.  In the example below an anonymous function calls fname and
the returned string is the calling sequence but that's not its name
since it has no name.  In fact, in a sense no R functions have names.
You can store them in variables and call that variable its name but
that is not an intrinsic part of the function itself.  A function is
just an environment, an argument list and a body -- no name.

 fname - function() as.character(sys.call(-1))[1]
 (function() fname())()
[1] (function() fname())


On Sun, Sep 27, 2009 at 7:24 PM, Rolf Turner r.tur...@auckland.ac.nz wrote:

 I have vague recollections of seeing this question discussed on r-help
 previously, but I can't find the relevant postings.

 I want to determine (from within a given function) the name of the function
 calling that given function.

 E.g. if I have a function foo() which calls a function bar(), and also
 a function clyde() which calls bar(), I want to have, in the code of bar(),
 an instruction which will return the character string foo if bar() was
 called from foo() and the string clyde if bar() was called from clyde().

 Without really understanding what I'm doing I cobbled together the
 following:

 fname - as.character(sys.call(-1))[1]

 This ***seems*** to work, at least in simple test cases.

 But is it reliably robust?  Are there traps for young players that I am
 not seeing?

 My ``solution'' returns NA as the value of fname if bar() is called from the
 command line, rather than being called by foo() or clyde().  This is
 acceptable.
 I think 

 Any avuncular advice from those younger and wiser than myself? :-)

        cheers,

                Rolf Turner

 ##
 Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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


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


[R] CRAN (and crantastic) updates this week

2009-09-27 Thread Crantastic
CRAN (and crantastic) updates this week

New packages


* bdoc (1.0)
  Michael Anderson
  http://crantastic.org/packages/bdoc

  This package contains a function that will classify DNA barcodes as
  well as a few test and reference data sets.

* bdsmatrix (1.0)
  Terry Therneau
  http://crantastic.org/packages/bdsmatrix

  This is a special case of sparse matrices, used by coxme and kinship

* CircSpatial (1.0)
  Bill Morphet
  http://crantastic.org/packages/CircSpatial

  The package is a collection of functions for color continuous high
  resolution images of circular spatial data, circular kriging, and
  simulation of circular random fields.

* cond (1.1-3)
  Alessandra R. Brazzale
  http://crantastic.org/packages/cond

  Higher order likelihood-based inference for logistic and loglinear
  models

* coxme (2.0)
  Terry Therneau
  http://crantastic.org/packages/coxme

  Cox proportional hazards models containing Gaussian random effects,
  also known as frailty models.

* csampling (1.1-3)
  Alessandra R. Brazzale
  http://crantastic.org/packages/csampling

  Monte Carlo conditional inference for the parameters of a linear
  nonnormal regression model

* desire (1.0.5)
  Olaf Mersmann
  http://crantastic.org/packages/desire

  Harrington and Derringer-Suich type desirability functions

* difR (1.0)
  Sebastien Beland
  http://crantastic.org/packages/difR

  The difR package contains several traditional methods to detect DIF in
  dichotomously scored items. Both uniform and non-uniform DIF effects
  can be detected, with methods relying upon item response models or
  not. Some methods deal with more than one focal group.

* DTDA (1.1)
  Carla Moreira
  http://crantastic.org/packages/DTDA

  This package implements different algorithms for analyzing randomly
  truncated data, one-sided and two-sided (i.e. doubly) truncated
  data.

* gRapHD (0.1.0)
  Gabriel Coelho Goncalves de Abreu
  http://crantastic.org/packages/gRapHD

  gRapHD is designed for efficient selection of high-dimensional
  undirected graphical models. The package provides tools for
  selecting trees, forests and decomposable models minimizing
  information criteria such as AIC or BIC, and for displaying the
  independence graphs of the models. It has also some useful tools for
  analysing graphical structures. It supports the use of discrete,
  continuous, or both types of variables.

* IQCC (1.0)
  Emanuel P. Barbosa
  http://crantastic.org/packages/IQCC

  Builds statistical control charts with exact limits for univariate and
  multivariate cases.

* marg (1.1-3)
  Alessandra R. Brazzale
  http://crantastic.org/packages/marg

  Likelihood inference based on higher order approximations for linear
  nonnormal regression models

* MCMChybridGP (2.1)
  Mark J. Fielding
  http://crantastic.org/packages/MCMChybridGP

  Hybrid Markov chain Monte Carlo (MCMC) to simulate from a multimodal
  target distribution.  A Gaussian process approximation makes this
  possible when derivatives are unknown. The Package serves to
  minimize the number of function evaluations in Bayesian calibration
  of computer models using parallel tempering.  It allows replacement
  of the true target distribution in high temperature chains, or
  complete replacement of the target.  Methods used are described in,
  Efficient MCMC schemes for Bayesian calibration of computer
  models, Fielding, Mark, Nott, David J. and Liong Shie-Yui (2009),
  in preparation. The authors gratefully acknowledge the support 
  contributions of the Singapore-Delft Water Alliance (SDWA).  The
  research presented in this work was carried out as part of the
  SDWA's Multi-Objective Multi-Reservoir Management research programme
  (R-264-001-272).

* nlreg (1.1-3)
  Alessandra R. Brazzale
  http://crantastic.org/packages/nlreg

  Likelihood inference based on higher order approximations for
  nonlinear models with possibly non constant variance

* nnclust (2.1)
  Thomas Lumley
  http://crantastic.org/packages/nnclust

  Finds nearest neighours and the minimum spanning tree for large data
  sets, does clustering using the minimum spanning tree.

* phybase (1.1)
  Liang Liu
  http://crantastic.org/packages/phybase

  This package provides functions to read, write, manipulate, estimate,
  and summarize phylogenetic trees including species trees which
  contain not only the topology and branch lengths but also population
  sizes. The input/output functions can read tree files in which trees
  are presented in parenthetic format. The trees are read in as a
  string and then transformed to a matrix which describes the
  relationship of nodes and branch lengths. The nodes matrix provides
  an easy access for developers to further manipulate the tree, while
  the tree string provides interface with other phylogenetic R
  packages such as ape. The input/output functions can also be used
  to change the format of tree files between NEXUS and PHYLIP. Some
  basic functions have already been 

Re: [R] Determining name of calling function.

2009-09-27 Thread Rolf Turner


On 28/09/2009, at 12:34 PM, Gabor Grothendieck wrote:


Not sure if this is important to you but R functions don't have to
have names so what you get back won't be a name if the function was
anonymous.  In the example below an anonymous function calls fname and
the returned string is the calling sequence but that's not its name
since it has no name.  In fact, in a sense no R functions have names.
You can store them in variables and call that variable its name but
that is not an intrinsic part of the function itself.  A function is
just an environment, an argument list and a body -- no name.


fname - function() as.character(sys.call(-1))[1]
(function() fname())()

[1] (function() fname())


snip

Good point.  Thanks.  I don't ***think*** that this issue will call
problems for me.  In my real application ``bar()'' will always be
called by a named function.  Still, it's something to keep in mind.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Count number of zeros in a collumn

2009-09-27 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Murat Tasan
 Sent: Sunday, September 27, 2009 4:27 PM
 To: r-help@r-project.org
 Subject: Re: [R] Count number of zeros in a collumn
 
 more generally, if you want to test for some minimum threshold T on
 the number of zeros, try:
 
  if(length(which(dart[,1977] == 0))  T) { # some code to 
 handle the too-few-zeros-case }

Note that
   sum( dart[,1977]==0 )
gives the same result as
   length(which( dart[,1977]==0 ))
with less typing and using less memory and time.
Arithmetic on logicals treats TRUE as 1 and FALSE
as 0.

(sum() forces you to decide what to do with NA's
in the data; which() always discards them.)

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

 
 
 
 
 On Sep 27, 4:54 pm, Marcio Resende mresende...@yahoo.com.br wrote:
  I have a matrix 700x2000 which is sampled in each cycle 
 from another matrix
  788x2000 with the numbers 0,1 and 9
 
  There is one specific collumn of this matrix, dart[,1977], 
 that usually,
  after the samplimg procedure has only 1 and 9 (because the 
 zero frequency in
  this collumn is low).
  However, when this happens, I want to include an IF 
 conditional in my code.
  so basically what i wanted to do was to count the number of 
 zeros in this
  collumn to use this information in my conditional:
 
  something like:
 
  if (the number of zeros in collumn [,1977] is zero) ... else ...
 
  I tried to find out indirectly by the rowsum but because of 
 the sampling
  procedure the rowsum is not always the same
 
  Thank you very much
  --
  View this message in 
 context:http://www.nabble.com/Count-number-of-zeros-in-a-collu
 mn-tp25637516p2...
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  r-h...@r-project.org mailing 
 listhttps://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting 
 guidehttp://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

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


[R] Bubble Plot

2009-09-27 Thread Marion Wittmann
Hello, 

 I am using the bubble plot and have been able to overlay two different data 
sets on the same graphic successfully. I would like to do the following and 
cannot: 

1) suppress the zero values such that there is no representation of them on my 
plot (i.e., the zeroes show up as the smallest dot size, and I can't change 
this)

2) Give values to y or x axes with values, and labels

My script looks as such:

coordinates(data) = ~y + x
a1 = bubble(data, Alive, zero.print = .,maxsize = 5.0, 
key.entries = 4*(1:6),col=c(0,3))
a2 = bubble(handcore, Dead, maxsize = 5.0, main = ,
key.entries =   5*(0:10),col=c(0,4))

print(b1, more = TRUE)
print(b2, more = FALSE)


Thanks in advance for your help. 

mw

Marion Wittmann, Ph.D.
Tahoe Environmental Research Center
University of California Davis

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

2009-09-27 Thread KABELI MEFANE
Hi Everybody
 
Its me again. I have been able to sample using SRS and stratified sampling when 
i have predefined groups as follows:
 
Hypermarket - matrix(rnorm(100, mean=5, sd=5000))
Supermarket - matrix(rnorm(400, mean=34000, sd=3000))
Minimarket  - matrix(rnorm(1000, mean=1,sd=2000))
Cornershop  - matrix(rnorm(1500, mean=2500, sd=500))
Spazashop   - matrix(rnorm(2000, mean=1000, sd=250))
dat=data.frame(type=c(rep(Hypermarket,100), rep(Supermarket,400),
rep(Minimarket,1000),rep(Cornershop,1500), rep(Spazashop,2000)),
value=c(Hypermarket, Supermarket, Minimarket, Cornershop,Spazashop))
dat
 
names(dat)=c(type,value)
#Number of observations for each outlet type in a population
dat$type - factor(dat$type, 
levels = c(Hypermarket,Supermarket,Minimarket,Cornershop,Spazashop))
(stratas-data.frame(table(dat$type)))
 
##sampling and proportional allocation
as.matrix(table(dat$type))
s=strata(dat,c(type),size=c(20,80,200,300,400), method=srswor)
dat.strat-getdata(dat,s)
dat.strat
 
Now i want to use the rectangular method to determine strata boundaries, 
thenfor the allocation use Neyman, so please help me achieve this. 
 


  
[[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] Data analysis package for positively skewed data

2009-09-27 Thread KABELI MEFANE
R-helpers
 
A curious question: Can you make suggestions  as to  what to use in R for 
the data from a sample of the following:
 
Hypermarket - matrix(rnorm(100, mean=5, sd=5000))
Supermarket - matrix(rnorm(400, mean=34000, sd=3000))
Minimarket  - matrix(rnorm(1000, mean=1,sd=2000))
Cornershop  - matrix(rnorm(1500, mean=2500, sd=500))
Spazashop   - matrix(rnorm(2000, mean=1000, sd=250))
dat=data.frame(type=c(rep(Hypermarket,100), rep(Supermarket,400),
rep(Minimarket,1000),rep(Cornershop,1500), rep(Spazashop,2000)),
value=c(Hypermarket, Supermarket, Minimarket, Cornershop,Spazashop))
#Sampling with without replacement 
n-1000
dat.srs-dat[sample(1:dim(dat)[1], size=n,replace=F),]
dat.srs   
#Number of observations for each outlet type in a sample
dat.srs$type - factor(dat.srs$type, 
levels = c(Hypermarket,Supermarket,Minimarket,Cornershop,Spazashop))

(numoutlets-data.frame(table(dat.srs$type)))
 
 
suggest a package that can help me get all the analysis info such as 
meean,var,std,dev,cv,ci,proportions,...



  
[[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] Converting SAS Data code to R.

2009-09-27 Thread David Winsemius


On Sep 27, 2009, at 6:01 PM, David Winsemius wrote:



On Sep 27, 2009, at 12:10 PM, David Winsemius wrote:



On Sep 27, 2009, at 11:49 AM, Douglas Bates wrote:


On Sat, Sep 26, 2009 at 11:33 PM, David Winsemius
dwinsem...@comcast.net wrote:
I am contemplating bringing in and merging three NHANES-III  
datasets from
the National Center for Health Statistics that are fixed format  
with record
length=3348, line counts around 20,000 and described by SAS DATA  
steps. I
have downloaded and linked similar datasets from the Continuous  
NHANES
public data releases, but never ones with this many variables at  
once. In
the prior effort I managed the task by some cut-paste-editing  
from the SAS
code file into a corresponding read.fwf R call, but the earlier  
NHANES-III
data is far more voluminous than the more recent Continuous  
version. I am
wondering if anyone has experience with such a process and would  
be willing

to share some advice? The SAS code can be seen here:



ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/adult.sas



The main code file Data step starts out...
 FILENAME ADULT D:\Questionnaire\DAT\ADULT.DAT LRECL=3348;
 *** LRECL includes 2 positions for CRLF, assuming use of PC SAS;
 DATA WORK;
   INFILE ADULT MISSOVER;
   LENGTH
 SEQN  7
 DMPFSEQ   5
 DMPSTAT   3
 DMARETHN  3
 DMARACER  3
 DMAETHNR  3
 HSSEX 3
The corresponding positions in the INPUT section are
  INPUT
 SEQN 1-5
 DMPFSEQ  6-10
 DMPSTAT  11
 DMARETHN 12
 DMARACER 13
 DMAETHNR 14
 HSSEX15
The note about CRLF appears to be implying that those characters  
are being
counted as part of the length of the first variable, SEQN, but  
that there
are only 5 meaningful positions. I suppose I can find out by  
trial and error
how to read such files, but it would save me some time if anyone  
in the

audience has worked through this on this data before.
One thought would be to import the data with the SAS work-alike  
program,
WKS, (which I have not used before) and then to read in with  
read.xport from
the foreign library. That would obviate the need to understand  
the character
position issue, but probably has a time commitment to get it up  
and running

and learn how to use it.
Another thought would be to parse the fixed width SAS Data step  
code into
pieces and build a data.frame from which I then extract the  
row.names,

col.names, and colClasses from that centralized structure.


Are the data available to the public somewhere or could just a few
records be made available?


Yes. Just trim the file name and the CDC ftp server accepts the  
path specification:


ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/

The file that goes with that SAS code is adult.dat

ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHANES/NHANESIII/1A/adult.dat



The reason I ask is because I imagine there are a lot of missing  
data

in each record (the data are arranged in the wide format for
longitudinal data and includes follow-up questions that will not  
apply

to most respondents).  The missing data indicator, if any, and the
format of the other fields will be important in deciding how to  
split

the data.


Thanks for that. It was not designed as a longitudinal study, but  
rather as cross-sectional study that was spaced over several years.  
They did a re-exam of some sort, but that was not the primary  
purpose, nor will it be my particular interest. I have tried to  
determine by examination whether . or   is the missing value  
indicator and it appears that both may used although there are many  
more spaces. Most of the input suggests to my 15-year-old memories  
of SAS that the data is numeric but there are 17 variables where  
input spec is $nn


 varLines[grep([[:punct:]], varLines)]
[1] HAX11AG  $6  HAX11AH  $6  HAX11AI   
$6
[4] HAX11AJ  $6  HAX11AK  $6  HAX11AL   
$6
[7] HAX11AM  $6  HAX11AN  $6  HAX11AO   
$6
[10] HAX11AP  $6  HAX11AQ  $6   
HAX11AR  $6
[13] HAX11AS  $6  HAX11AT  $6   
HAX11AU  $6

[16] HAX11AV  $6  HAZA1CC  $30



My progress on this effort so far consists of having figured out how  
to extract the variable names and their associated lengths so I can  
set up a call to read.fwf(). This is waht I did on hte section of  
the SAS code following INPUT that contains those elements:


trim.ws - function(x) gsub(^[[:space:]]+|[[:space:]]+$, ,x)
# courtesy of a Grothendieck r-help posting of a couple or three  
years ago.


adult.var - data.frame(varnames =  
sapply( strsplit(trim.ws(varLines) ,  +) ,  [, 1:2)[1,], varlen=  
sapply( strsplit(trim.ws(varLines) ,  +) ,  [, 1:2)[2,])
#so that I can split the trimmed strings on an arbitrary number of  
spaces.


 adult.var[,][1:5,]
 varnames varlen
1 SEQN  7
2  DMPFSEQ  5
3  DMPSTAT  3
4 

[R] Re ading Functions that are in a Vector

2009-09-27 Thread trumpetsaz

I am trying to write a function that will have an input of a vector of
functions. Here is a simplistic example.
sumstats - c(mean,sd)
sumstats[1]
#Gives this error
# sumstats[1]
#[[1]]
#function (x, ...) 
#UseMethod(mean)
#environment: namespace:base

I thought about restricting the input to character variables such as the
following
sumstats2 - c(mean,sd)
Is there a way to change mean to the function mean?
-- 
View this message in context: 
http://www.nabble.com/Reading-Functions-that-are-in-a-Vector-tp25639720p25639720.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] Data formatting for matplot

2009-09-27 Thread Tim Clark
Dear List,

I am wanting to produce a multiple line plot, and know I can do it with matplot 
but can't get my data in the format I need.  I have a dataframe with three 
columns; individuals ID, x, and y.  I have tried split() but it gives me a list 
of matrices, which is closer but not quite what I need.  For example:

id-rep(seq(1,5,1),length.out=100)
x-rnorm(100,5,1)
y-rnorm(100,20,5)

mydat-data.frame(id,x,y)
split.dat-split(mydat[,2:3],mydat[,1])

I would appreciate your help in either how to get this into a format acceptable 
to matplot or other options for creating a multiple line plot.

Thanks,

Tim



Tim Clark
Department of Zoology 
University of Hawaii

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


Re: [R] Data formatting for matplot

2009-09-27 Thread Henrique Dallazuanna
You can try this:

matplot(do.call(cbind, split.dat))

On Sun, Sep 27, 2009 at 11:42 PM, Tim Clark mudiver1...@yahoo.com wrote:
 Dear List,

 I am wanting to produce a multiple line plot, and know I can do it with 
 matplot but can't get my data in the format I need.  I have a dataframe with 
 three columns; individuals ID, x, and y.  I have tried split() but it gives 
 me a list of matrices, which is closer but not quite what I need.  For 
 example:

 id-rep(seq(1,5,1),length.out=100)
 x-rnorm(100,5,1)
 y-rnorm(100,20,5)

 mydat-data.frame(id,x,y)
 split.dat-split(mydat[,2:3],mydat[,1])

 I would appreciate your help in either how to get this into a format 
 acceptable to matplot or other options for creating a multiple line plot.

 Thanks,

 Tim



 Tim Clark
 Department of Zoology
 University of Hawaii

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




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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] implementation of matrix logarithm (inverse of matrix exponential)

2009-09-27 Thread Charles C. Berry

On Sun, 27 Sep 2009, Douglas Bates wrote:


There is a logm function in the expm package in the expm project on
R-forge.  See http://expm.R-forge.R-project.org/

Martin was the person who added that function so I will defer to his
explanations of what it does.  I know he has been traveling and it may
be a day or two before he can get to this thread.



Douglas,

Thanks for this note.

The logm() function in the expm package does the trick.

It seems to properly handle block structures for non-diagonalizable 
matrices:



require(expm)
M - matrix(c(0,1,0,0),2)
expm(M)

 [,1] [,2]
[1,]10
[2,]11

logm(expm(M))

 [,1] [,2]
[1,]00
[2,]10

And thanks to Vincent, Martin, et al for this package!

:-)

Chuck



On Sun, Sep 27, 2009 at 11:44 AM, Charles C. Berry cbe...@tajo.ucsd.edu wrote:

On Sat, 26 Sep 2009, spencerg wrote:


   Sylvester's formula
(http://en.wikipedia.org/wiki/Sylvester%27s_formula) applies to a square
matrix A = S L solve(S), where L = a diagonal matrix and S = matrix of
eigenvectors.  Let f be an analytic function [for which f(A) is well
defined].  Then f(A) = S f(L) solve(S).
   We can code this as follows:
sylvester - function(x, f){
 n - nrow(x)
 eig - eigen(x)
 vi - solve(eig$vectors)
 with(eig, (vectors * rep(f(values), each=n)) %*% vi)
}


logm - function(x)sylvester(x, log)


Example:
A - matrix(1:4, 2)
eA - expm(A)
logm(eA)


         With Chuck Berry's example, we get the following:
M - matrix( c(0,1,0,0), 2 )
sylvester(M, log)



The case I gave would be

       sylvester( as.matrix( expm( M ) ), log )

for which the perfectly sensible answer is M,  not what appears here:



Error in solve.default(eig$vectors) :
 system is computationally singular: reciprocal condition number =
 1.00208e-292


         This is a perfectly sensible answer in this case.  We get the
same result from sylvester(M, exp), though expm(M) works fine.
         A better algorithm for this could be obtains by studying the code
for expm in the Matrix package and the references in the associated help
page.


I doubt that code already in R will handle cases requiring Jordan blocks for
evaluation of the matrix logarithm (which cases arise in the context of
discrete state, continuous time Markov chains) without requiring one to
built that code more or less from scratch.

I'd be happy to hear that this is not so.

HTH,

Chuck



    Hope this helps. Spencer


Gabor Grothendieck wrote:


 Often one uses matrix logarithms on symmetric positive definite
 matrices so the assumption of being symmetric is sufficient in many
 cases.

 On Sat, Sep 26, 2009 at 7:28 PM, Charles C. Berry cbe...@tajo.ucsd.edu
 wrote:


 On Sat, 26 Sep 2009, Gabor Grothendieck wrote:

 OK. Try this:

 library(Matrix)

 M - matrix(c(2, 1, 1, 2), 2); M

    [,1] [,2]

 [1,]    2    1
 [2,]    1    2

 Right. expm( M ) is diagonalizable.

 But for
 M - matrix( c(0,1,0,0), 2 )
 you get the wrong result.
 Maybe I should have added that I do not see the machinery in R for 
 dealing

 with Jordan blocks.

 HTH,
 Chuck

 # log of expm(M) is original matrix M

 with(eigen(expm(M)), vectors %*% diag(log(values)) %*% t(vectors))

    [,1] [,2]

 [1,]    2    1
 [2,]    1    2

 On Sat, Sep 26, 2009 at 6:24 PM, Charles C. Berry  
 cbe...@tajo.ucsd.edu

 wrote:

 On Sat, 26 Sep 2009, Gabor Grothendieck wrote:

 Try:

 expm( - M)

 Mimosa probably meant say 'the inverse function'.

 I do not see one in R.
 Chuck

 On Sat, Sep 26, 2009 at 5:06 PM, Mimosa Zeus
mimosa1...@yahoo.fr

 wrote:

 Dear R users,

 Does anyone has implemented the inverse of the
matrix   exponential (expm

 in the package Matrix)?

 In Matlab, there're logm and expm, there's only expm
in R.

 Cheers
 Mimosa

        [[alternative HTML
version deleted]]


 __

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

 Charles C. Berry                            (858)
534-2098

                                            Dept of
Family/Preventive
 Medicine
 E mailto:cbe...@tajo.ucsd.edu               UC San Diego
 http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego
 92093-0901

 __

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

 Charles C. Berry                            (858) 534-2098

                                      

Re: [R] Data formatting for matplot

2009-09-27 Thread Gabor Grothendieck
Try this:

library(lattice)
xyplot(y ~ x, mydat, groups = id)


On Sun, Sep 27, 2009 at 10:42 PM, Tim Clark mudiver1...@yahoo.com wrote:
 Dear List,

 I am wanting to produce a multiple line plot, and know I can do it with 
 matplot but can't get my data in the format I need.  I have a dataframe with 
 three columns; individuals ID, x, and y.  I have tried split() but it gives 
 me a list of matrices, which is closer but not quite what I need.  For 
 example:

 id-rep(seq(1,5,1),length.out=100)
 x-rnorm(100,5,1)
 y-rnorm(100,20,5)

 mydat-data.frame(id,x,y)
 split.dat-split(mydat[,2:3],mydat[,1])

 I would appreciate your help in either how to get this into a format 
 acceptable to matplot or other options for creating a multiple line plot.

 Thanks,

 Tim



 Tim Clark
 Department of Zoology
 University of Hawaii

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


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


Re: [R] Re ading Functions that are in a Vector

2009-09-27 Thread Gabor Grothendieck
On Sun, Sep 27, 2009 at 10:36 PM, trumpetsaz stephaniezim...@gmail.com wrote:

 I am trying to write a function that will have an input of a vector of
 functions. Here is a simplistic example.
 sumstats - c(mean,sd)
 sumstats[1]
 #Gives this error
 # sumstats[1]
 #[[1]]
 #function (x, ...)
 #UseMethod(mean)
 #environment: namespace:base

That's not an error.  The code asked it to return the first function
so that's what it did.


 I thought about restricting the input to character variables such as the
 following
 sumstats2 - c(mean,sd)
 Is there a way to change mean to the function mean?

This gives a vector of functions given a vector of their names:

 sumstat1 - lapply(sumstats2, get)

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


Re: [R] Re ading Functions that are in a Vector

2009-09-27 Thread Rolf Turner


On 28/09/2009, at 3:36 PM, trumpetsaz wrote:



I am trying to write a function that will have an input of a vector of
functions. Here is a simplistic example.
sumstats - c(mean,sd)
sumstats[1]
#Gives this error
# sumstats[1]
#[[1]]
#function (x, ...)
#UseMethod(mean)
#environment: namespace:base

I thought about restricting the input to character variables such  
as the

following
sumstats2 - c(mean,sd)
Is there a way to change mean to the function mean?


You *can't* have a vector of functions, as far I know.  The entries
of a vector must be (numeric, character, or logical) scalars.

You *can* have a *list* of functions; this might be the way you
want to go.

To ``change mean to the function mean'' --- set ?get.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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


Re: [R] Re ading Functions that are in a Vector

2009-09-27 Thread David Winsemius


On Sep 27, 2009, at 11:07 PM, Rolf Turner wrote:



On 28/09/2009, at 3:36 PM, trumpetsaz wrote:



I am trying to write a function that will have an input of a vector  
of

functions. Here is a simplistic example.
sumstats - c(mean,sd)
sumstats[1]
#Gives this error
# sumstats[1]
#[[1]]
#function (x, ...)
#UseMethod(mean)
#environment: namespace:base

I thought about restricting the input to character variables such  
as the

following
sumstats2 - c(mean,sd)
Is there a way to change mean to the function mean?


You *can't* have a vector of functions, as far I know.  The entries
of a vector must be (numeric, character, or logical) scalars.

You *can* have a *list* of functions; this might be the way you
want to go.

To ``change mean to the function mean'' --- set ?get.



That is prezactly what he created:

 umstats - c(mean,sd)

 str(umstats)
List of 2
 $ :function (x, ...)
 $ :function (x, na.rm = FALSE)


And what's more it works if it is accessed with [[:

 umstats[[1]](c(1,2,3,4,5))
[1] 3



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Re ading Functions that are in a Vector

2009-09-27 Thread Rolf Turner


On 28/09/2009, at 4:30 PM, David Winsemius wrote:



On Sep 27, 2009, at 11:07 PM, Rolf Turner wrote:



On 28/09/2009, at 3:36 PM, trumpetsaz wrote:



I am trying to write a function that will have an input of a vector
of
functions. Here is a simplistic example.
sumstats - c(mean,sd)
sumstats[1]
#Gives this error
# sumstats[1]
#[[1]]
#function (x, ...)
#UseMethod(mean)
#environment: namespace:base

I thought about restricting the input to character variables such
as the
following
sumstats2 - c(mean,sd)
Is there a way to change mean to the function mean?


You *can't* have a vector of functions, as far I know.  The entries
of a vector must be (numeric, character, or logical) scalars.

You *can* have a *list* of functions; this might be the way you
want to go.

To ``change mean to the function mean'' --- set ?get.



That is prezactly what he created:


umstats - c(mean,sd)

str(umstats)

List of 2
  $ :function (x, ...)
  $ :function (x, na.rm = FALSE)


And what's more it works if it is accessed with [[:


umstats[[1]](c(1,2,3,4,5))

[1] 3


Never ceases to amaze me how R can get it right in settings and
with syntaxes that you would think can't ***possibly*** work!

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Fwd: generic methods - in particular the summary function

2009-09-27 Thread Christophe Dutang

Thanks for your answer.

Yes, I use now a proper NAMESPACE with function declared correctly.

Christophe

Le 27 sept. 2009 à 19:16, David Winsemius a écrit :



On Sep 27, 2009, at 12:52 PM, Christophe Dutang wrote:

Nobody wants to answer my question... is there something stupid in  
it?


I couldn't really say. Not being a user of fitdistrplus I don't have  
much baseline experience. Had you posted code that produced  
something to work on,  I might have made an effort at applying the  
methods I typically use, such as str(object), methods(function),  
and printing out the function code. But I am a rather low-level R- 
user, and as soon as you strart throwing around questions about  
NAMESPACE, my eyes glaze over and I move to the next question.


When I do install and load fitdistrplus and then execute:

methods(summary)

.. I see a new function which is not even invisible, called  
summary.fitdist. So it seems to be in my NAMESPACE   ... or at least  
what I dimly understand about such metaphysical entities. I get an  
error when I execute your suggestion:


 S3method(summary, fitdist)
Error: could not find function S3method

So I would have assumed that you had a package with that S3method  
function about which you had not informed us. Not sure this helps  
because, as I said, your question appeared more complex that I  
considered myself competent to answer.


--
David



Début du message réexpédié :


De : Christophe Dutang duta...@gmail.com
Date : 19 septembre 2009 11:26:51 HAEC
À : r-help@r-project.org
Objet : generic methods - in particular the summary function

Hi all,

I'm currently working on the fitdistrplus package (that basically
fit distributions). There is something I do not understand about the
generic function summary.

In the current version on CRAN, there is no NAMESPACE saying

S3method(summary, fitdist)

.
However if we use summary on an object send by fitdist function it
works fine...

According to R-lang, we have

The most common use of generic functions is to provide print and
summary methods for
statistical ob jects, generally the output of some model fitting
process. To do this, each model
attaches a class attribute to its output and then provides a special
method that takes that output
and provides a nice readable version of it. The user then needs only
remember that print or
summary will provide nice output for the results of any analysis.


I would like to be sure, that if the summary.fitdist is not exported
in the NAMESPACE, then we must use declare it with S3method.

Thanks in advance

Christophe

--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr



--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr







[[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
Heritage Laboratories
West Hartford, CT



--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr

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