Re: [R] nlminb() - how do I constrain the parameter vector properly?

2013-10-21 Thread Steven LeBlanc

On Oct 20, 2013, at 9:54 PM, Mark Leeds  wrote:

> Bill: I didn't look at the code but I think the OP means that during the 
> nlminb algorithm,
> the variance covariance parameters hit values such that the covariance matrix 
> estimate becomes negative definite.

Yes, that is what I meant.

> 
> Again, I didn't look at the details but one way to deal with this is to have 
> the likelihood
> function return -Inf whenever the covariance matrix becomes not positive 
> definite. so, the
> likelihood should check for  positive definiteness first before it actually 
> calculates anything.
> If PD is not true, the -Inf value should push nlminb towards values that 
> obtain a positive definite matrix. But there could be something more subtle 
> going on that I'm not understanding. I don't know even what algorithm nlminb 
> is using ( probably quasi-newton ) but this is one thing the OP could try.

I tried this at your suggestion. nlminb() seems to hang at -Inf, but Inf works 
splendidly. Thanks much!

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

2013-10-21 Thread Marino David
Greatly enrich my mind.

Thank you!

David

2013/10/16 Spencer Graves 

>  On 10/15/2013 5:37 PM, Marino David wrote:
>
>  Hi Spencer:
>
> Thanks for your interpretation again and again.  Your statement does
> enable me to have a good understanding of  Gaussian quadrature.
>
> This sos package you recommended is greatly powerful. From now on, I will
> use the sos package to find something helpful before I do some research.
>
> Yes, I want to compute the expection of functions whos variables follow
> common distriubtions (e.g. F, t, Beta, Gamma, etc.). Via searching
> referrences, I know that Gaussian quadrature  based on orthogonal
> polynomials is fast method for integration.
>
>
>
>   Often, the most expensive part of any data analysis is the time of
> the person doing it.  For that reason, it's often wise to first try the
> quickest thing available.  Just for fun, I performed the following tests on
> the F distribution:
>
>
> f. <- Fd(1,1)
> sinF <- sin(f.)
> E(sinF)
> # 0.2093619
>
>
>   This didn't work for round(sinF).  For that, we can try the
> following:
>
>
> rf. <- r(sinF)(1)
> mean(round(rf.))
> # 0.197
>
>
>   If I were only doing this once, I wouldn't mess with quadrature.  If
> the options like "integrate" or the above take too much compute time, then
> I'll consider other options, like numerical integration with quadrature.
> However, orthogonal polynomials for a continuous distribution won't work
> properly with a discontinuous transformation like round ;-)
>
>
>   Hope this helps.
>   Spencer
>
>
>   David
>
>
> 2013/10/14 Spencer Graves 
>
>>  David:
>>
>>
>>   What you have is close, but I perceive some problems:
>>
>>
>> integral{from -Inf to Inf of f(x)t(x)dx} = integral{from 0 to
>> Inf of (f(-x)+f(x))t(x)dx}, because Student's t distribution is symmetric.
>>
>>
>>   Now do the change of variables x = sqrt(z), so dx =
>> 0.5*dz/sqrt(z).  Then t(x)dx = 0.5*t(sqrt(z))dz/sqrt(z).  Play with this
>> last expression a bit, and you should get it into the form of g(z)dz, where
>> g(z) = the density for the F distribution.
>>
>>
>>   Next transform the F distribution to a beta distribution on [0, 1],
>> NOT a beta distribution on [-1, 1].  There are Jacobi polynomials on [0, 1]
>> you can use.  Or further transform the interval [0, 1] to [-1, 1].
>>
>>
>>   Did you look at the literature search results I sent you using
>> findFn{sos}?  When I need to do something new in statistics, the first
>> thing I do is a literature search like I described, ending with using the
>> installPackages and writeFindFn2xls functions, as described in the sos
>> vignette.  That rarely takes more than a minute or two.  The
>> writeFindFn2xls function should create an Excel file in your working
>> directory, which you can find with getwd().  Open that.  The first sheet is
>> a summary of the different packages.  This gives you a list of different
>> packages.  You can then use that to prioritize your further study.
>>
>>
>>   Two more comments:
>>
>>
>> 1.  It is conceptually quite simple to write an algorithm to
>> compute polynomials that are orthonormal relative to any distribution.  The
>> Wikipedia article on "Orthogonal polynomials" gives a set of linear
>> equations that must be solved to create them.
>>
>>
>> 2.  Why do you want orthogonal polynomials?  To obtain a very
>> fast algorithm for computing the expected values of a certain class of
>> functions?  If no, have you considered doing without orthogonal polynomials
>> and just computing the expected value of whatever function you want using
>> the distr package to compute the distribution of f(X) and E{distrEx} to
>> compute the expected value?
>>
>>
>>   Best Wishes,
>>   Spencer
>>
>>
>> p.s.  Could you please post a summary of this exchange to R-help, so
>> someone else with a similar question a year from now can find it?  Thanks.
>>
>>
>>
>> On 10/13/2013 10:12 PM, Marino David wrote:
>>
>> Hi Spencer:
>>
>> I still have trouble in understanding your response to email
>> about Gaussian quadrature. I tried to describe it in detail. See attachment.
>>
>> Thank you!
>>
>> David
>>
>>
>>
>> --
>> Spencer Graves, PE, PhD
>> President and Chief Technology Officer
>> Structure Inspection and Monitoring, Inc.
>> 751 Emerson Ct.
>> San José, CA 95126
>> ph:  408-655-4567
>> web:  www.structuremonitoring.com
>>
>>
>
>
> --
> Spencer Graves, PE, PhD
> President and Chief Technology Officer
> Structure Inspection and Monitoring, Inc.
> 751 Emerson Ct.
> San José, CA 95126
> ph:  408-655-4567
> web:  www.structuremonitoring.com
>
>

[[alternative HTML version deleted]]

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


Re: [R] Errore : requires numeric/complex matrix/vector arguments

2013-10-21 Thread PIKAL Petr
Hi

>From your first post if any of variables is not numeric this command

mY<-cbind(G, T, Y, news)

makes mY also nonumeric.

so look at structure of 

"D" data.frame which results from reading your csv file by

str(D)

Regards
Petr


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Berend Hasselman
> Sent: Sunday, October 20, 2013 4:31 PM
> To: valentina colombo
> Cc: r-help@r-project.org help
> Subject: Re: [R] Errore : requires numeric/complex matrix/vector
> arguments
> 
> 
> On 20-10-2013, at 16:16, valentina colombo 
> wrote:
> 
> > Dear Mr. Hasselman,
> > I have attached my code to solve (hopefully) my problem in
> > Error-require numeric/complex matrix/vector Any suggestions?
> > Thanks
> >
> Please answer to the list and NOT only privately. I'm forwarding this
> message to R-help.
> 
> You are not showing how you constructed mX and others.
> In the attachment you show how you read X.
> 
> I do not get your error when I generate your matrices with these
> commands:
> 
> set.seed(1)
> 
> N <- 126
> mX <- matrix(runif(N*4),ncol=4)
> mY <- matrix(runif(N*4),ncol=4)
> mZ <- matrix(runif(N*4),ncol=4)
> 
> If you want to include data in a text-only mail use dput.
> 
> Berend
> 
> >
> >
> > > Subject: Re: [R] Errore : requires numeric/complex matrix/vector
> > > arguments
> > > From: b...@xs4all.nl
> > > Date: Sun, 20 Oct 2013 13:29:37 +0200
> > > CC: r-help@r-project.org
> > > To: valentina...@hotmail.it
> > >
> > >
> > > On 20-10-2013, at 13:08, valentina colombo
>  wrote:
> > >
> > > > Dear R users,I'm a new user of R. I'm trying to do a LM test an
> there is this type of error: Error in t(mX) %*% mX : requires
> numeric/complex matrix/vector arguments.
> > > > To be clear I write down the code in which mY ( 126,1 ) mX
> (126,1) mZ(126,1) are matrix.
> > > >
> > > > LMTEST <- function(mY, mX, mZ)#mY, mX, mZ must be
> > > > matrices!#returns the LM test statistic and the degree of
> > > > freedom{iT = dim(mY)[1]ip = dim(mY)[2]iDF = dim(mZ)[2]*ipmE = mY
> -
> > > > mX%*%solve(t(mX)%*%mX)%*%t(mX)%*%mY
> > > > the error starts from the above step (t(mX)%*%mX)%*%t(mX)%*%mY
> > > > RSS0 = t(mE)%*%mEmXX = cbind(mX, mZ)mK = mE -
> > > > mXX%*%solve(t(mXX)%*%mXX)%*%t(mXX)%*%mERSS1 = t(mK)%*%mKdTR =
> sum(diag(solve(RSS0)%*%RSS1))LM = iT*(ip-dTR)pval = 1-
> pchisq(LM,df=iDF)return( c(pval, LM, iDF) )} Any suggestion? Where is
> the problem? I am getting craxy!
> > >
> > > Your code is a complete mess and thus unreadable because you posted
> in HTML.
> > > Cleaning up and doing this
> > >
> > > LMTEST <- function(mY, mX, mZ)#mY, mX, mZ must be matrices!
> > > #returns the LM test statistic and the degree of freedom {iT =
> > > dim(mY)[1] ip = dim(mY)[2] iDF = dim(mZ)[2]*ip mE = mY -
> > > mX%*%solve(t(mX)%*%mX)%*%t(mX)%*%mY
> > > # the error starts from the above step (t(mX)%*%mX)%*%t(mX)%*%mY
> > > RSS0 = t(mE)%*%mE mXX = cbind(mX, mZ) mK = mE -
> > > mXX%*%solve(t(mXX)%*%mXX)%*%t(mXX)%*%mE
> > > RSS1 = t(mK)%*%mK
> > > dTR = sum(diag(solve(RSS0)%*%RSS1))
> > > LM = iT*(ip-dTR)
> > > pval = 1-pchisq(LM,df=iDF)
> > > return( c(pval, LM, iDF) )
> > > }
> > >
> > > set.seed(1)
> > >
> > > N <- 20
> > > mX <- matrix(runif(N),ncol=1)
> > > mY <- matrix(runif(N),ncol=1)
> > > mZ <- matrix(runif(N),ncol=1)
> > >
> > > LMTEST(mY,mX,mZ)
> > >
> > > the answer I got was:
> > >
> > > [1] 0.004965514 7.891955826 1.0
> > >
> > >
> > > So it must be your data.
> > > Are you sure they are numeric? Have you checked with str(mX) etc?
> > >
> > > Berend
> > >
> > > > Valentina
> > > > [[alternative HTML version deleted]]
> > >
> > >
> > > Please don't post in html but in plain text.
> > >
> > >
> > > >
> > > > __
> > > > R-help@r-project.org mailing list
> > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > PLEASE do read the posting guide
> > > > http://www.R-project.org/posting-guide.html
> > > > and provide commented, minimal, self-contained, reproducible
> code.
> > >
> > 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Conflict between Accelerate BLAS and package 'stats'

2013-10-21 Thread Prof Brian Ripley

On 21/10/2013 04:18, David Degras wrote:

Hi All,

After successfully setting up the Accelerate BLAS library via


'UNsucessfully' ...

This is a question for R-sig-MAC: see the posting guide, and you need to 
ask how to achieve whatever you are trying to do, rather than tell us 
how you broke your R.  (My guess is that the advice you need is in the 
'R Installation and Administration Manual'.)




/cd /Library/Frameworks/R.framework/Resources/lib
ln -sf
/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib
libRblas.dylib
/

I restarted R (version 3.0.1) and got the following error message:

/Error in dyn.load(file, DLLpath = DLLpath, ...) :
   unable to load shared object
'/Library/Frameworks/R.framework/Versions/3.0/Resources/library/stats/libs/stats.so':

dlopen(/Library/Frameworks/R.framework/Versions/3.0/Resources/library/stats/libs/stats.so,
6): Symbol not found: _lsame_
   Referenced from:
/Library/Frameworks/R.framework/Versions/3.0/Resources/lib/libRlapack.dylib
   Expected in:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
  in
/Library/Frameworks/R.framework/Versions/3.0/Resources/lib/libRlapack.dylib
During startup - Warning message:
package 'stats' in options("defaultPackages") was not found /

Can anybody help?

Below is the system info for my iMac:

/sysname   "Darwin"
release "10.8.0"
version
"Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011;
root:xnu-1504.15.3~1/RELEASE_I386"
machine"i386"
/

Thanks,
David


David Degras
Department of Mathematical Sciences
DePaul University




--
View this message in context: 
http://r.789695.n4.nabble.com/Conflict-between-Accelerate-BLAS-and-package-stats-tp4678674.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.




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

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


[R] Reproducing density(..., kernel='rectangular', width=1) using convolve? (for educational purposes)

2013-10-21 Thread Tal Galili
Hello dear R-help members,

I am currently teaching students on kernel density estimators, and I was
hoping to show them an animation of the convolution which is taking place
in the "density" function. I wrote a (somewhat clunky) piece of code to
reproduce the density function, but I seem to get rather different results
(which means I am missing something).

If any of you are in the mood to help and see what is wrong (or if you have
your own piece of code which already does this), it would be lovely for
future students who are studying this method.

Here is the code I got thus far:


 The function to reproduce
set.seed(13413)
some_data <- c(round(rnorm(100)))
plot(density(some_data, kernel='rectangular', width=1, n = 10**5), lwd = 3)

 The attempt
convolve_new <- function(data_range, kernel_range, data_fun, kernel_fun,
normalize = TRUE) {
   # data_range, kernel_range - MUST have the same length

   # if we have the range of a kernel function and of the data function
   # we would like to have one move over the other without any problems.
   y_data_fun <- data_fun(data_range)
   y_kernel_fun <- kernel_fun(kernel_range)
   n_kernel <- length(y_kernel_fun)
   n_data <- length(y_kernel_fun)
   conv_vec <- convolve(y_data_fun, rev(y_kernel_fun), type = "o")

   items_to_remove <- floor(n_kernel/2)
   conv_vec <- head(conv_vec,-items_to_remove)
   conv_vec <- tail(conv_vec,-items_to_remove)

   dx <- ifelse(normalize, mean(diff(data_range)), 1)# this is dx
   conv_vec  * dx
}


w_R_01 <- function(u) {
   ifelse(abs(u)<=.5 & u >=0,1,0)
}


# fun1 <- dnorm # kernel
fun1 <- w_R # kernel
# fun2 <- w_R_01 # data
fun2 <-  # data
   function(x) {
  sapply(x, function(y) sum(some_data %in% y))
   }
# fun2(1)


# the_data_range <- seq(-2,2, by = .01)
the_data_range <- sort(c(seq(min(some_data),max(some_data), by = .01),
some_data))
the_kernel_range <- the_data_range
convo_the_range <- convolve_new(the_data_range, the_kernel_range, fun2,
fun1)
the_animation_range <- seq(-2,2, by = .2)
# plot(convo_the_range/sum(convo_the_range)~the_range, type = "l")

for(i in the_animation_range) {
#curve(fun2,
#  from = min(the_data_range), to = max(the_data_range), ylim =
c(0,3),
#  n=10**3)
   plot(fun2(the_data_range) ~ the_data_range, type= "h")
   abline(v = i, lty = 2, col = "purple", lwd = 2)
   temp_fun1 <- function(x) {fun1(x-i)}
   curve(temp_fun1,
 from = min(the_animation_range), to = max(the_animation_range),
add = TRUE,
 n=10**3, lwd = 3, col = 2)
#temp_convolution_range <- function(x) {convolution_range(x, fun1 =
temp_fun1, fun2 = fun2)}
##curve(convolution_range, from = -3, to =3, add = TRUE)
   ss<- the_data_range<=i
   lines(convo_the_range[ss]~the_data_range[ss], type = "l", col = 3, lwd =
3)
   rug(some_data)
}



Thanks,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[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] nlminb() - how do I constrain the parameter vector properly?

2013-10-21 Thread Mark Leeds
my mistake. since nlminb is minimizing, it should be +Inf  ( so that the
likelihood
is large ) as you pointed out. Note  that this approach is a heuristic and
may  not work all the time.















On Mon, Oct 21, 2013 at 3:01 AM, Steven LeBlanc  wrote:

>
> On Oct 20, 2013, at 9:54 PM, Mark Leeds  wrote:
>
> > Bill: I didn't look at the code but I think the OP means that during the
> nlminb algorithm,
> > the variance covariance parameters hit values such that the covariance
> matrix estimate becomes negative definite.
>
> Yes, that is what I meant.
>
> >
> > Again, I didn't look at the details but one way to deal with this is to
> have the likelihood
> > function return -Inf whenever the covariance matrix becomes not positive
> definite. so, the
> > likelihood should check for  positive definiteness first before it
> actually calculates anything.
> > If PD is not true, the -Inf value should push nlminb towards values that
> obtain a positive definite matrix. But there could be something more subtle
> going on that I'm not understanding. I don't know even what algorithm
> nlminb is using ( probably quasi-newton ) but this is one thing the OP
> could try.
>
> I tried this at your suggestion. nlminb() seems to hang at -Inf, but Inf
> works splendidly. Thanks much!
>
>

[[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] blod dot size and name in plot

2013-10-21 Thread S Ellison


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of eliza botto
> Sent: 19 October 2013 22:27
> To: r-help@r-project.org
> Subject: [R] blod dot size and name in plot
> 
> Dear useRs,I have the following data "z" of two variables "x"(z[,1])
> and "y"(z[,2]).
> ...
> I made a dot plot between them. what i want to do is to bold the size
> of dots,compared to that of others, for the following ranges
> ---80 6 Then, i also want to draw square around those dots falling in these
> ranges and finally naming the areas with alphabets A, B and C.
> Is there a way of doing it?

Yes, depending what you mean by 'bold'.
If 'bold' means 'bigger' you can use cex to change sizes. 
If it means 'coloured' or a filled symbol (eg pch=19) you can use pch.
if it means 'the same size with thicker lines', you can't have 'bold' symbols, 
though you could plot circles with lwd=2 or go looking for a symbol font on 
your machine that has thicker lines.

The trick is to use a cex, col or pch as long as the data. For example

bold.A <- bold.B <- bold.C <- rep_len(FALSE,length.out=length(x)) # A bit 
crude, but it'll work
bold.A[ 80https://stat.ethz.ch/mailman/listinfo/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] nlminb() - how do I constrain the parameter vector properly?

2013-10-21 Thread Prof J C Nash (U30A)
This is one area where more internal communication between the objective 
function (inadmissible inputs) and optimizer (e.g., Quasi-Newton) is 
needed. This is NOT done at the moment in R, nor in most software. An 
area for R&D. In Nash and Walker-Smith (1987) we did some of this in 
BASIC back in mid-80s. Still trying to redo that for R, but it won't be 
done quickly due to the much bigger infrastructure of R.


The "trick" with using a large value or Inf (which sometimes causes
other errors) usually slows the optimization, whereas communicating that 
the objective is inadmissible in a line search can often be simply a 
shortening of the step size.


JN

On 13-10-21 06:00 AM, r-help-requ...@r-project.org wrote:

Message: 34
Date: Mon, 21 Oct 2013 05:56:45 -0400
From: Mark Leeds
To: Steven LeBlanc
Cc:"r-help@R-project.org"  
Subject: Re: [R] nlminb() - how do I constrain the parameter vector
properly?
Message-ID:

Content-Type: text/plain

my mistake. since nlminb is minimizing, it should be +Inf  ( so that the
likelihood
is large ) as you pointed out. Note  that this approach is a heuristic and
may  not work all the time.


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

2013-10-21 Thread Mohammad Goodarzi
Dear all,

I have to load more than 1000 matrices from desktop which all of them have
the same size.
If I do it manually, it would be very hard, can you please guide me how to
load them and merge them together ?

for example I want to put them one after another
X1 X2 X3 etc

Many thanks,
Mohammad

[[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] Problem to understand calculation of loglikelihood in the ramps package

2013-10-21 Thread zhe zhao
Dear R,

We are trying to understand the calculation of loglikelihood in the ramps
package. Our calculations do not agree with the package's. Can anyone
explain why not?

Here's an example using a small data set.

# create small dataset
library(ramps)

data(NURE)  ## NURE is included in ramps package
attach(NURE)
data <- NURE[lat>41.9 & lon > -72.5 & !is.na(lat),]
dim(data)  # 20 data points

# ramps analysis
set.seed(22)

NURE.ctrl1 <- ramps.control(
  iter = 10,
  beta = param(0, "flat"),
  sigma2.e = param(1, "invgamma", shape = 2.0, scale = 0.1, tuning = 0.75),
  phi = param(10, "uniform", min = 0, max = 35, tuning = 0.50),
  sigma2.z = param(1, "invgamma", shape = 2.0, scale = 0.1)
)

NURE.fit2 <- georamps(log(ppm) ~ 1,
  correlation = corRExp(form = ~ easting + northing),

  data = data,
  control = NURE.ctrl1
)
rampsll <- NURE.fit2$loglik[1:4] # ramps loglikelihood for iterations 1:4


# our calculation
# We should be able to use the parameter values from a single MCMC iteration
# to calculate the loglikelihood using dmvnorm

library(mvtnorm)
cor.exp <- function(x, range = 1, p = 1) # copied from corStruct.R in the
ramps package

{
   if (range <= 0 || p <= 0)
  stop("Exponential correlation parameter must be > 0")

   if (p == 1) exp(x / (-1 * range))
   else exp(-1 * (x / range)^p)
}

# Compute the covariance matrix

sig.fn <- function(itno,data){
  dist <- as.matrix ( dist ( data[,c("easting","northing")] ) )
  npts <- nrow(data)
  sig1 <- diag(npts)
  for ( i in 1:(npts-1) )
for ( j in (i+1):npts )
  sig1[j,i] <- sig1[i,j] <- cor.exp ( dist[i,j], range =
NURE.fit2$params[itno,"phi"] )

  Sigma <- sig1 * NURE.fit2$params[itno, "sigma2.z"] +
diag(npts) * NURE.fit2$params[itno, "sigma2.e"]
  return(Sigma)
}

# Calculate the loglikelihood for a single MCMC iteration
loglik.fn <- function(itno,data){

  loglik <- dmvnorm ( x = log(data[,"ppm"]),
mean = rep ( NURE.fit2$params[itno,"(Intercept)"], nrow(data) ),
sigma = sig.fn(itno,data),
log = TRUE
  )
  return(loglik)
}

# Collect the loglikelihood from iterations 1:4
myll <- c ( loglik.fn(1,data), loglik.fn(2,data), loglik.fn(3,data),
loglik.fn(4,data) )


But myll does not agree with rampsll.
Can anyone tell us why not?

Thanks very much for your help.
Zhe

[[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] Removing duplicates dates matched on another column

2013-10-21 Thread arun
Hi,
May be this helps:

dat1 <- structure(
res <- dat1[!(duplicated(dat1$date) & dat1$admit==0),]

A.K.


I want to remove duplicate dates if the value of admit is 0. How could I 
realize this in R?  Reproducible sample data is here: 

structure(list(date = structure(c(13879, 13879, 13880, 13880, 
13881, 13881, 13882, 13882, 13883, 13883, 13884, 13885, 13886, 
13886, 13887, 13887, 13888, 13888, 13889, 13889, 13890, 13891, 
13891, 13892, 13893, 13893, 13894, 13894, 13895, 13895, 13896, 
13896, 13897, 13897, 13898, 13898, 13899, 13899, 13900, 13900, 
13901, 13901, 13902, 13902, 13903, 13903, 13904, 13904, 13905, 
13905, 13906, 13906, 13907, 13907, 13908, 13908, 13909, 13909 
), class = "Date"), admit = c(1, 0, 1, 0, 2, 0, 1, 0, 3, 0, 0, 
0, 4, 0, 2, 0, 1, 0, 3, 0, 0, 2, 0, 0, 2, 0, 1, 0, 5, 0, 2, 0, 
2, 0, 1, 0, 4, 0, 3, 0, 1, 0, 4, 0, 6, 0, 8, 0, 3, 0, 3, 0, 3, 
0, 2, 0, 4, 0)), .Names = c("date", "admit"), row.names = 10152:10209, class = 
"data.frame")

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

2013-10-21 Thread Bert Gunter
Have you read "An Introduction to R" (ships with R) or any R web
tutorials to learn how R works? If not, don't you think you should
before posting here? Your question appears to be rather basic.

Cheers,
Bert

On Mon, Oct 21, 2013 at 3:18 AM, Mohammad Goodarzi
 wrote:
> Dear all,
>
> I have to load more than 1000 matrices from desktop which all of them have
> the same size.
> If I do it manually, it would be very hard, can you please guide me how to
> load them and merge them together ?
>
> for example I want to put them one after another
> X1 X2 X3 etc
>
> Many thanks,
> Mohammad
>
> [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

(650) 467-7374

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 to understand calculation of loglikelihood in the ramps package

2013-10-21 Thread Bert Gunter
You may get an answer here, but this appears to be something that you
should address to the package maintainer or package author.

Cheers,
Bert

On Mon, Oct 21, 2013 at 7:04 AM, zhe zhao  wrote:
> Dear R,
>
> We are trying to understand the calculation of loglikelihood in the ramps
> package. Our calculations do not agree with the package's. Can anyone
> explain why not?
>
> Here's an example using a small data set.
>
> # create small dataset
> library(ramps)
>
> data(NURE)  ## NURE is included in ramps package
> attach(NURE)
> data <- NURE[lat>41.9 & lon > -72.5 & !is.na(lat),]
> dim(data)  # 20 data points
>
> # ramps analysis
> set.seed(22)
>
> NURE.ctrl1 <- ramps.control(
>   iter = 10,
>   beta = param(0, "flat"),
>   sigma2.e = param(1, "invgamma", shape = 2.0, scale = 0.1, tuning = 0.75),
>   phi = param(10, "uniform", min = 0, max = 35, tuning = 0.50),
>   sigma2.z = param(1, "invgamma", shape = 2.0, scale = 0.1)
> )
>
> NURE.fit2 <- georamps(log(ppm) ~ 1,
>   correlation = corRExp(form = ~ easting + northing),
>
>   data = data,
>   control = NURE.ctrl1
> )
> rampsll <- NURE.fit2$loglik[1:4] # ramps loglikelihood for iterations 1:4
>
>
> # our calculation
> # We should be able to use the parameter values from a single MCMC iteration
> # to calculate the loglikelihood using dmvnorm
>
> library(mvtnorm)
> cor.exp <- function(x, range = 1, p = 1) # copied from corStruct.R in the
> ramps package
>
> {
>if (range <= 0 || p <= 0)
>   stop("Exponential correlation parameter must be > 0")
>
>if (p == 1) exp(x / (-1 * range))
>else exp(-1 * (x / range)^p)
> }
>
> # Compute the covariance matrix
>
> sig.fn <- function(itno,data){
>   dist <- as.matrix ( dist ( data[,c("easting","northing")] ) )
>   npts <- nrow(data)
>   sig1 <- diag(npts)
>   for ( i in 1:(npts-1) )
> for ( j in (i+1):npts )
>   sig1[j,i] <- sig1[i,j] <- cor.exp ( dist[i,j], range =
> NURE.fit2$params[itno,"phi"] )
>
>   Sigma <- sig1 * NURE.fit2$params[itno, "sigma2.z"] +
> diag(npts) * NURE.fit2$params[itno, "sigma2.e"]
>   return(Sigma)
> }
>
> # Calculate the loglikelihood for a single MCMC iteration
> loglik.fn <- function(itno,data){
>
>   loglik <- dmvnorm ( x = log(data[,"ppm"]),
> mean = rep ( NURE.fit2$params[itno,"(Intercept)"], nrow(data) ),
> sigma = sig.fn(itno,data),
> log = TRUE
>   )
>   return(loglik)
> }
>
> # Collect the loglikelihood from iterations 1:4
> myll <- c ( loglik.fn(1,data), loglik.fn(2,data), loglik.fn(3,data),
> loglik.fn(4,data) )
>
>
> But myll does not agree with rampsll.
> Can anyone tell us why not?
>
> Thanks very much for your help.
> Zhe
>
> [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

(650) 467-7374

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

2013-10-21 Thread Alaios
Hi all,
I am having 4 vectors like

Data: num [1:4, 1:32] -82.8 -81.8 -75.5 -107.6 -87.6 ...  

and I want to calculate the correlation between those.

Is there a graphical way in R to plot the correlations or not?

I would like to thank you in advance for your help

Regards
Alex
[[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] nlminb() - how do I constrain the parameter vector properly?

2013-10-21 Thread William Dunlap
Try defining the function
theta345toSigma <- function(theta) {
   cholSigma <- cbind(c(theta[3], 0), c(theta[4], theta[5]))
   crossprod(cholSigma) # t(cholSigma) %*% cholSigma)
}
This creates a positive definite matrix for any theta (and
any positive definite matrix has such a representation, generally
more than one).  It is like using the square root of a quantity
in the optimizer when you know the quantity must be non-negative.

Then change your
sigma <- c(theta[3],theta[5],theta[5],theta[4])
dim(sigma) <- c(2, 2)
to
sigma <- theta345toSigma(theta)

If one of your variances is near 0 the optimizer may run into
trouble at saddlepoints.  Others may be able to help better
with that issue.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: Steven LeBlanc [mailto:ores...@gmail.com]
> Sent: Sunday, October 20, 2013 9:35 PM
> To: William Dunlap
> Subject: Re: [R] nlminb() - how do I constrain the parameter vector properly?
> 
> 
> On Oct 20, 2013, at 6:41 PM, William Dunlap  wrote:
> 
> > Do you mean that your objective function (given to nlminb) parameterized
> > a positive definite matrix, P, as the elements in its upper (or lower) 
> > triangle?
> > If so, you could reparameterize it by the non-zero (upper triangular) 
> > elements
> > of the Choleski decomposition, C, of P.  Compute P as crossprod(C), compute
> > the initial estimate of C as chol(P).
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> 
> Hi Bill,
> 
> I've clipped out the superfluous code to leave the objective function and 
> call to nlminb()
> below.
> 
> I'm using the first two parameters to construct the vector of means 'u' for a 
> bivariate
> normal, and the final three parameters to construct the corresponding 
> covariance matrix
> 'sigma'. Both are required by dmvnorm(). In summary, nlminb() required a 
> vector of
> parameters, so I supplied the number of parameters I needed nlminb() to 
> optimize and
> simply built the required formats within the function.
> 
> It didn't occur to me until I saw the error that nlminb() would have no way 
> of knowing the
> proper boundaries of the parameter space unless there is some way to 
> communicate the
> constraints. nlminb() implements simple box constraints, but I don't see a 
> way to
> communicate "parameters 3, 4, and 5 must satisfy 3*4 - 5^2 > 0.
> 
> Regarding your suggestion, I don't think I understand. Might you elaborate?
> 
> Thanks & Best Regards,
> Steven
> 
> > exact<-function(theta,complete,deleted){
> >>
> >>u<-c(theta[1],theta[2])
> >>sigma<-c(theta[3],theta[5],theta[5],theta[4])
> >>dim(sigma)<-c(2,2)
> >>-sum(log(dmvnorm(x=complete,mean=u,sigma=sigma)))-
> >>sum(log(dnorm(one.only,u[1],sigma[1,1])))-
> >>sum(log(dnorm(two.only,u[2],sigma[2,2])))
> >> }
> >>
> nlminb(start=c(0,0,1,1,0),objective=exact,complete=complete,deleted=deleted,control=l
> >> ist(trace=1))

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] nlminb() - how do I constrain the parameter vector properly?

2013-10-21 Thread Mark Leeds
thanks bill. that's a neat trick that I haven't seen before. now I see what
you're saying
much more clearly. steven: bill's method should be faster than mine because
it won't
have rejection iterations like my idea will.





On Mon, Oct 21, 2013 at 10:52 AM, William Dunlap  wrote:

> Try defining the function
> theta345toSigma <- function(theta) {
>cholSigma <- cbind(c(theta[3], 0), c(theta[4], theta[5]))
>crossprod(cholSigma) # t(cholSigma) %*% cholSigma)
> }
> This creates a positive definite matrix for any theta (and
> any positive definite matrix has such a representation, generally
> more than one).  It is like using the square root of a quantity
> in the optimizer when you know the quantity must be non-negative.
>
> Then change your
> sigma <- c(theta[3],theta[5],theta[5],theta[4])
> dim(sigma) <- c(2, 2)
> to
> sigma <- theta345toSigma(theta)
>
> If one of your variances is near 0 the optimizer may run into
> trouble at saddlepoints.  Others may be able to help better
> with that issue.
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
> > -Original Message-
> > From: Steven LeBlanc [mailto:ores...@gmail.com]
> > Sent: Sunday, October 20, 2013 9:35 PM
> > To: William Dunlap
> > Subject: Re: [R] nlminb() - how do I constrain the parameter vector
> properly?
> >
> >
> > On Oct 20, 2013, at 6:41 PM, William Dunlap  wrote:
> >
> > > Do you mean that your objective function (given to nlminb)
> parameterized
> > > a positive definite matrix, P, as the elements in its upper (or lower)
> triangle?
> > > If so, you could reparameterize it by the non-zero (upper triangular)
> elements
> > > of the Choleski decomposition, C, of P.  Compute P as crossprod(C),
> compute
> > > the initial estimate of C as chol(P).
> > >
> > > Bill Dunlap
> > > Spotfire, TIBCO Software
> > > wdunlap tibco.com
> >
> > Hi Bill,
> >
> > I've clipped out the superfluous code to leave the objective function
> and call to nlminb()
> > below.
> >
> > I'm using the first two parameters to construct the vector of means 'u'
> for a bivariate
> > normal, and the final three parameters to construct the corresponding
> covariance matrix
> > 'sigma'. Both are required by dmvnorm(). In summary, nlminb() required a
> vector of
> > parameters, so I supplied the number of parameters I needed nlminb() to
> optimize and
> > simply built the required formats within the function.
> >
> > It didn't occur to me until I saw the error that nlminb() would have no
> way of knowing the
> > proper boundaries of the parameter space unless there is some way to
> communicate the
> > constraints. nlminb() implements simple box constraints, but I don't see
> a way to
> > communicate "parameters 3, 4, and 5 must satisfy 3*4 - 5^2 > 0.
> >
> > Regarding your suggestion, I don't think I understand. Might you
> elaborate?
> >
> > Thanks & Best Regards,
> > Steven
> >
> > > exact<-function(theta,complete,deleted){
> > >>
> > >>u<-c(theta[1],theta[2])
> > >>sigma<-c(theta[3],theta[5],theta[5],theta[4])
> > >>dim(sigma)<-c(2,2)
> > >>-sum(log(dmvnorm(x=complete,mean=u,sigma=sigma)))-
> > >>sum(log(dnorm(one.only,u[1],sigma[1,1])))-
> > >>sum(log(dnorm(two.only,u[2],sigma[2,2])))
> > >> }
> > >>
> >
> nlminb(start=c(0,0,1,1,0),objective=exact,complete=complete,deleted=deleted,control=l
> > >> ist(trace=1))
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] merging matrices

2013-10-21 Thread jim holtman
?list.files
?read.table
?rbind

Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Mon, Oct 21, 2013 at 6:18 AM, Mohammad Goodarzi
 wrote:
> Dear all,
>
> I have to load more than 1000 matrices from desktop which all of them have
> the same size.
> If I do it manually, it would be very hard, can you please guide me how to
> load them and merge them together ?
>
> for example I want to put them one after another
> X1 X2 X3 etc
>
> Many thanks,
> Mohammad
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Am I working with regularly spaced time series?

2013-10-21 Thread Weiwu Zhang
My data is sampled once per minute. There are invalid samples, leaving
a lot of holes in the samples, successful sample is around 80% of all
minutes in a day. and during the last 4 months sampling, one month's
data was stored on a harddisk that failed, leaving a month's gap in
between.

So am I working with regularly spaced time series or not? Should I
padd all missing data with NAs, and start with ts(), and followed by
forecast package (which seems to have all the functions I need in the
begining) or should I start with a library with irregular time series
in mind?

Also, ts() manual didn't say how to create time-series with one minute
as daltat. Its seems to assume time-series is about dates. So the data
I have with me, is it really time series at all?

Newbie question indeed. Thanks.

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


Re: [R] list and <<-

2013-10-21 Thread Greg Snow
See fortune(174).

It is best to avoid using '<<-', if you tell us what you are trying to
accomplish then we may be able to provide a better means to accomplish
it.

On Sat, Oct 19, 2013 at 10:28 PM, Taiyun Wei  wrote:
> Dear All,
>
>> opt = list()
>> opt$aa <<- TRUE
> Error in opt$aa <<- TRUE : object 'opt' not found
>
> Why?
>
> --
> Regards,
> Taiyun
> --
> Taiyun Wei 
> Homepage: http://blog.cos.name/taiyun/
> Phone: +86-15201142716
> Renmin University of China
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

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


Re: [R] nlminb() - how do I constrain the parameter vector properly?

2013-10-21 Thread William Dunlap
[I added r-help to the cc again.  Please keep the replies on the list as
there are others who can contribute to or learn from them.]

> I also learned you have to be very careful with the starting value, as the 
> simple identity
> matrix becomes singular under the transformation.

That is why I suggested using the non-zero entries in chol(sigmaStart), where
sigmaStart is your initial estimate of the variance matrix, as the initial
values of theta[3:5].

I should have said that crossProd(x) gives you a positive semidefinite matrix,
not positive definite.  When I said that variances near 0 would cause problems
I meant that a singular covariance matrix would cause problems.


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: Steven LeBlanc [mailto:ores...@gmail.com]
> Sent: Monday, October 21, 2013 9:21 AM
> To: William Dunlap
> Subject: Re: [R] nlminb() - how do I constrain the parameter vector properly?
> 
> 
> On Oct 21, 2013, at 7:52 AM, William Dunlap  wrote:
> 
> > Try defining the function
> >theta345toSigma <- function(theta) {
> >   cholSigma <- cbind(c(theta[3], 0), c(theta[4], theta[5]))
> >   crossprod(cholSigma) # t(cholSigma) %*% cholSigma)
> >}
> > This creates a positive definite matrix for any theta (and
> > any positive definite matrix has such a representation, generally
> > more than one).  It is like using the square root of a quantity
> > in the optimizer when you know the quantity must be non-negative.
> >
> > Then change your
> >sigma <- c(theta[3],theta[5],theta[5],theta[4])
> >dim(sigma) <- c(2, 2)
> > to
> >sigma <- theta345toSigma(theta)
> >
> > If one of your variances is near 0 the optimizer may run into
> > trouble at saddlepoints.  Others may be able to help better
> > with that issue.
> >
> > Bill Dunlap
> > Spotfire, TIBCO Software
> > wdunlap tibco.com
> 
> Hi Bill,
> 
> I tried your suggestion and the optimizer produces a result, but it seems 
> substantially far
> from the anticipated result and from the result obtained when I use Inf as a 
> return value
> for an invalid covariance matrix. Perhaps it would work if I made other 
> adjustments to
> account for the 'bias' (using this term very loosely) induced by changing an 
> invalid
> parameter vector into something valid but incorrect?
> 
> I also learned you have to be very careful with the starting value, as the 
> simple identity
> matrix becomes singular under the transformation.
> 
> > theta<-c(0,0,1,1,0)
> > cholSigma<-cbind(c(theta[3], 0), c(theta[4], theta[5]))
> > sigma<-crossprod(cholSigma)
> > sigma
>  [,1] [,2]
> [1,]11
> [2,]11
> 
> In any case, the Inf trick works for now. I was asking about 'adjustments' 
> strictly out of
> curiosity. Code and results are below.
> 
> Best Regards,
> Steven
> 
> > exact<-function(theta,complete,deleted){
> + one.only<-deleted[!(is.na(deleted[,1])),1]
> + two.only<-deleted[!(is.na(deleted[,2])),2]
> + u<-c(theta[1],theta[2])
> + sigma<-c(theta[3],theta[5],theta[5],theta[4])
> + dim(sigma)<-c(2,2)
> + if(!(is.positive.semi.definite(sigma))){return(Inf)}
> + -sum(log(dmvnorm(x=complete,mean=u,sigma=sigma)))-
> + sum(log(dnorm(one.only,u[1],sigma[1,1])))-
> + sum(log(dnorm(two.only,u[2],sigma[2,2])))
> + }
> > exact2<-function(theta,complete,deleted){
> + one.only<-deleted[!(is.na(deleted[,1])),1]
> + two.only<-deleted[!(is.na(deleted[,2])),2]
> + u<-c(theta[1],theta[2])
> + cholSigma<-cbind(c(theta[3], 0), c(theta[4], theta[5]))
> + sigma<-crossprod(cholSigma)
> + -sum(log(dmvnorm(x=complete,mean=u,sigma=sigma)))-
> + sum(log(dnorm(one.only,u[1],sigma[1,1])))-
> + sum(log(dnorm(two.only,u[2],sigma[2,2])))
> + }
> > nlminb(start=theta.hat.em,objective=exact,complete=complete,deleted=deleted)$par
> [1] 1.2289422 5.4995271 0.9395155 4.8069068 1.8009213
> > nlminb(start=theta.hat.em,objective=exact2,complete=complete,deleted=deleted)$par
> [1] 1.2289421 5.4995265 0.9692861 1.8579876 1.1639544

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

2013-10-21 Thread Kevin Wright
You could try the corrgram or corrplot packages.

kw



On Mon, Oct 21, 2013 at 9:45 AM, Alaios  wrote:

> Hi all,
> I am having 4 vectors like
>
> Data: num [1:4, 1:32] -82.8 -81.8 -75.5 -107.6 -87.6 ...
>
> and I want to calculate the correlation between those.
>
> Is there a graphical way in R to plot the correlations or not?
>
> I would like to thank you in advance for your help
>
> Regards
> Alex
> [[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.
>
>


-- 
Kevin Wright

[[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] Problem with coordinates when trying to draw lines into a raster (image) file

2013-10-21 Thread Rick Turner

   Hi All,

   I am struggling with something, and could use some help

   I have a scenario where I need to draw lines onto a base image using R –
   briefly, the image has what amounts to an outline ‘map’ of locations, and
   the lines will correspond to ‘routes’ between two locations.

   The locations are known in terms of image pixel coordinates – let’s call
   them (px1, py1) and (px2, py2), but when I try and plot a line into the
   image using these coordinates, the visual positions are incorrect – the
   start and end points of the line are offset from the desired position, and
   the amount of offset changes as I resize the window. I've tried such things
   as normalising them into the [0,1] range used by the viewport but this does
   not correct the problem.

   So,  I  figured  that I must have made some mistake with my scaling of
   coordinates from image to viewport, but I cannot find where or what. I’ve
   fiddled around a bit (well, a lot!) but cannot get the desired result. So,
   it is time to ask for help, hence this message….

   Any  suggestions  gratefully  received…   I’ve done a fair amount of R
   programming, but have not used these extended graphics capabilities much at
   all, so I really am getting frustrated

   Regards and thanks in advance,
   Rick

   
   --

   The code segment in question is:

   # load packages

   library(jpeg)

   library(grid)


   # read the image file

   baseimg <- readJPEG("loc_map.jpg", native=FALSE)

   xsize <- ncol(baseimg)   # Get image size – this one is 
1344
   px wide

   ysize <- nrow(baseimg) # and 1008 px high


   # create a viewport

   xrange <- c(0, xsize)# set up the viewport range to
   match the image size

   yrange <- c(0, ysize)

   vp  <-  viewport(x=0.5,  y=0.5,  width=0.9, height=0.9, xscale=xrange,
   yscale=yrange)

   pushViewport(vp)

   grid.rect(gp=gpar(lty="dashed"))# draw a dashed line around it.


   # display the base image

   grid.raster(baseimg)


   # First location – image pixel coordinates (748, 177). Normalise these to
   [0,1] to

   # match the viewpoint coordinate scheme. Note that we need to invert the

   # y coordinate as R coords run from bottom up, but image ones are top down

   px1 <- (748/xsize)# 748/1344 ~=
   0.556, so in range [0,1]

   py1 <- (1.0 - (177/ysize))   # 1-(177/1008) ~=
   0.824, so also in range [0,1]


   # position of the St Johns Hill enterance (image coords

   # [769, 892]) normalised to the viewport

 x2 <- (769/xsize)

 y2 <- (1.0 - (892/ysize))


 # draw a line from pixel (px1,py1) to pixel (px2,py2) in blue

 xx <- c(px1, px2)

 yy <- c(py1, py2)

 grid.lines(xx, yy, gp=gpar(col="blue"))
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Predicting hurdle model results on spatial scale

2013-10-21 Thread Lauria, Valentina
Dear List,

I apologise in advance for all my questions. 

I am interested to predict the habitat selection of fish species using the 
hurdle model. I know that I can perform this in R with the function 
predict.hurdle() on newdata, however how this work  is not entirely clear.

Usually with a two-step approach a binary and a poisson models are created to 
deal with zero-inflated and over-dispersed data, then the binary model is 
multiplied by the poisson model in order weight the predictions.  Is this 
already included in the predict.hurdle function? 

Also I am using the function dredge (from the MuMin package) to select my best 
model based on AIC, still in this case the best model selected seems to be a 
combination between the truncated poisson and the binary model (hurdle model). 
Is there any way that I could dredge the two model components separately? I did 
some research and in the NEWS section I found that a package pscf was created 
for this but when I did more digging around I did not have much luck.

I would be grateful if someone could help me. 
Thank you very much once again,
Valentina




-Original Message-
From: Achim Zeileis [mailto:achim.zeil...@uibk.ac.at] 
Sent: 18 October 2013 18:57
To: Lauria, Valentina
Cc: r-help@r-project.org
Subject: Re: [R] hurdle model error why does need integer values for the 
dependent variable?

On Fri, 18 Oct 2013, Lauria, Valentina wrote:

> Dear list,
>
> I am using the hurdle model for modelling the habitat of rare fish 
> species. However I do get an error message when I try to model my data:
>
>> test_new1<-hurdle(GALUMEL~ depth + sal + slope + vrm + lat:long + 
>> offset(log(haul_numb)), dist = "negbin", data = datafit_elasmo)
>
> Error in hurdle(GALUMEL ~ depth + sal + slope + vrm + lat:long + 
> offset(log(haul_numb)),  :
>  invalid dependent variable, non-integer values
>
> When I do fit the same model with round(my dependent variable) the 
> model works. Sorry for the stupid question but could anyone explain me 
> why? My data are zero inflated (zeros occurring for 78%) and positively 
> skewed.

hurdle() fits a count data distribution (poisson, negbin, geometric) by maximum 
likelihood. Hence, its response needs to be a count variable (i.e., integer). 
See vignette("countreg", package = "pscl") for the underlying likelihoods 
employed.

> Thank you very much in advance.
> Kind Regards,
> Valentina
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] Aggregate values in one dataframe into a list of vectors of different sieze

2013-10-21 Thread sartene
Hi everyone,

I have a data frame that is quite huge (dozens of millions of lines).

It looks like this :

Name      Value
Name1    156
Name2    458963
Name3    758
...
Name143 89325
Name1     4678
Name42   766
Name144 777
...
Name2     46767
...

Each name and and value has no predefined length and may be repeated any number 
of times.

My goal is to have a list (aggregating the numbers relative to each name, so to 
obtain a data frame which looks like this:
Name     Values
Name1   156, 4678,...
Name2   458963, 46767...
...

Creating the unique names in the first column is easy via the unique function, 
but I did not find any way to regroup in matching vectors the different values 
aggregated for each name, of to directly create a data frame like I want.

The ultimate goal is to use the values in the vectors to do some statistics 
(means, etc.), but that is another matter for later!

Thanks for your help.


Sartene Bel
___
Les prévisions météo pour aujourd'hui, demain et jusqu'à 8 jours ! Voila.fr 
http://meteo.voila.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] tr: Aggregate values in one dataframe into a list of vectors of different sieze

2013-10-21 Thread sartene

I just found out what I was looking for, aggregate did the trick:
AggregatedList <- aggregate(data = Sample, Value ~ Name, list)

Hope this will help someone else!


Sartene Bel

> Message du 21/10/13 à 16h29
> De : sart...@voila.fr
> A : r-help@r-project.org
> Copie à : 
> Objet : Aggregate values in one dataframe into a list of vectors of different 
> sieze
> 
> Hi everyone,
> 
> I have a data frame that is quite huge (dozens of millions of lines).
> 
> It looks like this :
> 
> Name  Value
> Name1    156
> Name2    458963
> Name3    758
> ...
> Name143 89325
> Name1 4678
> Name42   766
> Name144 777
> ...
> Name2 46767
> ...
> 
> Each name and and value has no predefined length and may be repeated any 
> number of times.
> 
> My goal is to have a list (aggregating the numbers relative to each name, so 
> to obtain a data frame which looks like this:
> Name Values
> Name1   156, 4678,...
> Name2   458963, 46767...
> ...
> 
> Creating the unique names in the first column is easy via the unique 
> function, but I did not find any way to regroup in matching vectors the 
> different values 
aggregated for each name, of to directly create a data frame like I want.
> 
> The ultimate goal is to use the values in the vectors to do some statistics 
> (means, etc.), but that is another matter for later!
> 
> Thanks for your help.
> 
> 
> Sartene Bel
> ___
> Les prévisions météo pour aujourd'hui, demain et jusqu'à 8 jours ! Voila.fr 
> http://meteo.voila.fr/
___
Les prévisions météo pour aujourd'hui, demain et jusqu'à 8 jours ! Voila.fr 
http://meteo.voila.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.


[R] Statistical software interoperability meeting

2013-10-21 Thread Daniel Farewell
The British and Irish Region of the International Biometric Society
would like to bring your attention to a half-day meeting on Statistical
Software Interoperability on Thursday 14th November 2013 at the
headquarters of the Royal Statistical Society, Errol Street, London, UK. 

Please see 

http://bir.biometricsociety.org/events/interop

for registration, and more details.

Closing date for online registration: Friday 8th November 2013

This is an afternoon meeting featuring four presentations from leading
figures in computational statistics, giving talks on new developments
that involve interoperability between statistical software packages.
Some of the speakers will discuss interoperability with R.

This is a joint meeting of the Statistical Computing Section of the
Royal Statistical Society and the British and Irish Region of the
International Biometric Society.

Cost:
Member of Biometric/Royal Statistical Society: £20
Student/Retired Member: £10
Non-Member: £35

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

2013-10-21 Thread Mark Leeds
hi john. I knew it wasn't that simple and was thinking of asking you to
comment. so thanks for commenting. any good references are appreciated
also. In the various texts I have, this issue is seldom talked about.








On Mon, Oct 21, 2013 at 8:43 AM, Prof J C Nash (U30A) wrote:

> This is one area where more internal communication between the objective
> function (inadmissible inputs) and optimizer (e.g., Quasi-Newton) is
> needed. This is NOT done at the moment in R, nor in most software. An area
> for R&D. In Nash and Walker-Smith (1987) we did some of this in BASIC back
> in mid-80s. Still trying to redo that for R, but it won't be done quickly
> due to the much bigger infrastructure of R.
>
> The "trick" with using a large value or Inf (which sometimes causes other
> errors) usually slows the optimization, whereas communicating that the
> objective is inadmissible in a line search can often be simply a shortening
> of the step size.
>
> JN
>
> On 13-10-21 06:00 AM, r-help-requ...@r-project.org wrote:
>
>> Message: 34
>> Date: Mon, 21 Oct 2013 05:56:45 -0400
>> From: Mark Leeds
>> To: Steven LeBlanc
>> Cc:"r-help@R-project.org"  
>> Subject: Re: [R] nlminb() - how do I constrain the parameter vector
>> properly?
>> Message-ID:
>> > MMb7jfa3OkYkBTKA@mail.gmail.**com
>> >
>> Content-Type: text/plain
>>
>> my mistake. since nlminb is minimizing, it should be +Inf  ( so that the
>> likelihood
>> is large ) as you pointed out. Note  that this approach is a heuristic and
>> may  not work all the time.
>>
>

[[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] About integrating R inside a C++ software

2013-10-21 Thread Tambellini William
Hi,
  We are a company developing a software mainly in C++.
  We want to integrate R inside our software in order to use mainly the 
engine (usual stats as mean, sigma, Pearson, outlier detection, CPA, 
multivariate, ...) and probably later the chart solution.
  Of course we don't want to temporary write the data to some csv files 
and then do an ugly system() call : system("RScript.exe myscript.R") for 
many legitimate reasons.
  We are also using Qt so a Qt to/from R wrapper could be interesting.
  For the moment, we have found these solutions :
- using directly the standard R C API : R.h, Rmath.h, R_ext, 
- Rcpp : www.rcpp.org
- QtInterfaces : http://r-forge.r-project.org/projects/qtinterfaces/
- RInside http://dirk.eddelbuettel.com/code/rinside.html

  Any advices ?
Kind regards
William.
-- 
*William Tambellini*
Senior Developper
Phoenix, AZ, USA
www.galaxysemi.com
Semiconductor Intelligence

Subscribe to our blog at http://www.galaxysemi.com/blog
Join the support portal at http://support.galaxysemi.com

Confidentiality Notice: The information contained in thi...{{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] nlminb() - how do I constrain the parameter vector properly?

2013-10-21 Thread Mark Leeds
Steven: I'm not sure if it makes a difference but you might want to start
off with the "square root" of sigmaStart because that will really start you
off with sigmaStart. Essentially, what
Bill is doing is a reparameterization using the correlation and the 2
standard deviations so compute those based on the sigmaStart and use those
as the starting values. That might be a little faster.








On Mon, Oct 21, 2013 at 12:28 PM, William Dunlap  wrote:

> [I added r-help to the cc again.  Please keep the replies on the list as
> there are others who can contribute to or learn from them.]
>
> > I also learned you have to be very careful with the starting value, as
> the simple identity
> > matrix becomes singular under the transformation.
>
> That is why I suggested using the non-zero entries in chol(sigmaStart),
> where
> sigmaStart is your initial estimate of the variance matrix, as the initial
> values of theta[3:5].
>
> I should have said that crossProd(x) gives you a positive semidefinite
> matrix,
> not positive definite.  When I said that variances near 0 would cause
> problems
> I meant that a singular covariance matrix would cause problems.
>
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
> > -Original Message-
> > From: Steven LeBlanc [mailto:ores...@gmail.com]
> > Sent: Monday, October 21, 2013 9:21 AM
> > To: William Dunlap
> > Subject: Re: [R] nlminb() - how do I constrain the parameter vector
> properly?
> >
> >
> > On Oct 21, 2013, at 7:52 AM, William Dunlap  wrote:
> >
> > > Try defining the function
> > >theta345toSigma <- function(theta) {
> > >   cholSigma <- cbind(c(theta[3], 0), c(theta[4], theta[5]))
> > >   crossprod(cholSigma) # t(cholSigma) %*% cholSigma)
> > >}
> > > This creates a positive definite matrix for any theta (and
> > > any positive definite matrix has such a representation, generally
> > > more than one).  It is like using the square root of a quantity
> > > in the optimizer when you know the quantity must be non-negative.
> > >
> > > Then change your
> > >sigma <- c(theta[3],theta[5],theta[5],theta[4])
> > >dim(sigma) <- c(2, 2)
> > > to
> > >sigma <- theta345toSigma(theta)
> > >
> > > If one of your variances is near 0 the optimizer may run into
> > > trouble at saddlepoints.  Others may be able to help better
> > > with that issue.
> > >
> > > Bill Dunlap
> > > Spotfire, TIBCO Software
> > > wdunlap tibco.com
> >
> > Hi Bill,
> >
> > I tried your suggestion and the optimizer produces a result, but it
> seems substantially far
> > from the anticipated result and from the result obtained when I use Inf
> as a return value
> > for an invalid covariance matrix. Perhaps it would work if I made other
> adjustments to
> > account for the 'bias' (using this term very loosely) induced by
> changing an invalid
> > parameter vector into something valid but incorrect?
> >
> > I also learned you have to be very careful with the starting value, as
> the simple identity
> > matrix becomes singular under the transformation.
> >
> > > theta<-c(0,0,1,1,0)
> > > cholSigma<-cbind(c(theta[3], 0), c(theta[4], theta[5]))
> > > sigma<-crossprod(cholSigma)
> > > sigma
> >  [,1] [,2]
> > [1,]11
> > [2,]11
> >
> > In any case, the Inf trick works for now. I was asking about
> 'adjustments' strictly out of
> > curiosity. Code and results are below.
> >
> > Best Regards,
> > Steven
> >
> > > exact<-function(theta,complete,deleted){
> > + one.only<-deleted[!(is.na(deleted[,1])),1]
> > + two.only<-deleted[!(is.na(deleted[,2])),2]
> > + u<-c(theta[1],theta[2])
> > + sigma<-c(theta[3],theta[5],theta[5],theta[4])
> > + dim(sigma)<-c(2,2)
> > + if(!(is.positive.semi.definite(sigma))){return(Inf)}
> > + -sum(log(dmvnorm(x=complete,mean=u,sigma=sigma)))-
> > + sum(log(dnorm(one.only,u[1],sigma[1,1])))-
> > + sum(log(dnorm(two.only,u[2],sigma[2,2])))
> > + }
> > > exact2<-function(theta,complete,deleted){
> > + one.only<-deleted[!(is.na(deleted[,1])),1]
> > + two.only<-deleted[!(is.na(deleted[,2])),2]
> > + u<-c(theta[1],theta[2])
> > + cholSigma<-cbind(c(theta[3], 0), c(theta[4], theta[5]))
> > + sigma<-crossprod(cholSigma)
> > + -sum(log(dmvnorm(x=complete,mean=u,sigma=sigma)))-
> > + sum(log(dnorm(one.only,u[1],sigma[1,1])))-
> > + sum(log(dnorm(two.only,u[2],sigma[2,2])))
> > + }
> > >
> nlminb(start=theta.hat.em,objective=exact,complete=complete,deleted=deleted)$par
> > [1] 1.2289422 5.4995271 0.9395155 4.8069068 1.8009213
> > >
> nlminb(start=theta.hat.em,objective=exact2,complete=complete,deleted=deleted)$par
> > [1] 1.2289421 5.4995265 0.9692861 1.8579876 1.1639544
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproduci

Re: [R] Data Manipulation in R

2013-10-21 Thread Anamika Chaudhuri
Hi Arun:

Thanks for your help. Seperate files are being created by concatenating the
rows from the two files but I was looking to have them as columns rather
than text. This is the way it appears in Excel with row # at the beginning.
X Y1 Y2
1 1 4 0 20 17 1 20 52 15 18

Ideally I would like it to look like
X Y1 Y2
1 4 20
1 0 52
1 20 15
1 17 18
Thanks again!
Anamika

On Mon, Oct 21, 2013 at 1:11 AM, arun  wrote:

> Hi,
> May be this helps:
> Y1 <- read.table(text="V1 V2 V3 V4
> 1 4 0 20 17
> 2 4 0 15 17
> 3 2 0 13 21",sep="",header=TRUE)
>
> Y2 <- read.table(text="V1 V2 V3 V4
> 1 20 52 15 18
> 2 18 54 14 21
> 3 18 51 13 21",sep="",header=TRUE)
>  res <- lapply(seq_len(nrow(Y1)),function(i) {dat <-
> data.frame(X=i,Y1=unlist(Y1[i,]),Y2=unlist(Y2[i,])); row.names(dat) <-
> 1:nrow(dat);
> write.csv(dat,paste0("file",i,".csv"),row.names=FALSE,quote=FALSE)})
>
>
> A.K.
>
>
>
>
>
> A.K.
>
>
>
>
> On Monday, October 21, 2013 12:24 AM, Anamika Chaudhuri <
> canam...@gmail.com> wrote:
> Hi:
>
> I am looking for some help to manipulate data in R. I have two csv files.
>
> datasetY1
> V1 "V2" "V3" "V4"
> 1 4 0 20 17
> 2 4 0 15 17
> 3 2 0 13 21
>
> datasetY2
> V1 "V2" "V3" "V4"
> 1 20 52 15 18
> 2 18 54 14 21
> 3 18 51 13 21
>
> I want to be able to create separate csv files by taking the corresponding
> rows of dataset1 and dataset2, convert them into columns. So from the above
> example I would be creating 3 datasets (csvs), of which the first one would
> be
>X Y1Y2  1 4 20  1 0
> 52  1 20 15  1 17
> 18
>   Appreciate any help.
>
> Thanks
> Anamika
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

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


Re: [R] About integrating R inside a C++ software

2013-10-21 Thread Jeff Newmiller
Don't cross-post. If discussed further, this should probably be in r-devel, but 
I am not on that list.

Also, what is your question? I don't really see a question here. It might be 
along the lines of what technical solutions others like, but your research 
seems thorough enough for you to apply your own opinions. If it is legal (this 
is not a legal advice forum), keep in mind that many of the valuable algorithms 
in R are really in packages, and they may have similar but different licensing 
restrictions than R. However, as long as your software conforms to GPL2 (used 
in house only or released with source code) you are probably most of the way 
there. If not, you may need to keep the system calls in there or start 
discussions with the individual package authors to avoid stepping on licensing 
mines.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Tambellini William  wrote:
>Hi,
>  We are a company developing a software mainly in C++.
> We want to integrate R inside our software in order to use mainly the 
>engine (usual stats as mean, sigma, Pearson, outlier detection, CPA, 
>multivariate, ...) and probably later the chart solution.
> Of course we don't want to temporary write the data to some csv files 
>and then do an ugly system() call : system("RScript.exe myscript.R")
>for 
>many legitimate reasons.
>  We are also using Qt so a Qt to/from R wrapper could be interesting.
>  For the moment, we have found these solutions :
>- using directly the standard R C API : R.h, Rmath.h, R_ext, 
>- Rcpp : www.rcpp.org
>- QtInterfaces : http://r-forge.r-project.org/projects/qtinterfaces/
>- RInside http://dirk.eddelbuettel.com/code/rinside.html
>
>  Any advices ?
>Kind regards
>William.

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

2013-10-21 Thread Carl Witthoft
If you have over a thousand files on your desktop, you have bigger problems
than just how to load them into R.   
Where do these files come from, and why do you want to "merge" them into a
single entity?




--
View this message in context: 
http://r.789695.n4.nabble.com/merging-matrices-tp4678702p4678721.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] Data Manipulation in R

2013-10-21 Thread arun
Hi,

I am getting this.


 res <- lapply(seq_len(nrow(Y1)),function(i) {dat <- 
data.frame(X=i,Y1=unlist(Y1[i,]),Y2=unlist(Y2[i,])); row.names(dat) <- 
1:nrow(dat); 
write.csv(dat,paste0("Anam",i,".csv"),row.names=FALSE,quote=FALSE)})


dat1 <- read.csv("Anam1.csv",header=TRUE)

 dat1
  X Y1 Y2
1 1  4 20
2 1  0 52
3 1 20 15
4 1 17 18


Attaching one of the files generated.


A.K.




On Monday, October 21, 2013 1:55 PM, Anamika Chaudhuri  
wrote:

Hi Arun:

Thanks for your help. Seperate files are being created by concatenating the 
rows from the two files but I was looking to have them as columns rather than 
text. This is the way it appears in Excel with row # at the beginning.
X Y1 Y2
1 1 4 0 20 17 1 20 52 15 18

Ideally I would like it to look like
X Y1 Y2
1 4 20
1 0 52
1 20 15
1 17 18

Thanks again!
Anamika


On Mon, Oct 21, 2013 at 1:11 AM, arun  wrote:

Hi,
>May be this helps:
>Y1 <- read.table(text="V1 V2 V3 V4
>
>1 4 0 20 17
>2 4 0 15 17
>3 2 0 13 21",sep="",header=TRUE)
>
>Y2 <- read.table(text="V1 V2 V3 V4
>
>1 20 52 15 18
>2 18 54 14 21
>3 18 51 13 21",sep="",header=TRUE)
> res <- lapply(seq_len(nrow(Y1)),function(i) {dat <- 
>data.frame(X=i,Y1=unlist(Y1[i,]),Y2=unlist(Y2[i,])); row.names(dat) <- 
>1:nrow(dat); 
>write.csv(dat,paste0("file",i,".csv"),row.names=FALSE,quote=FALSE)})
>
>
>A.K.
>
>
>
>
>
>A.K.
>
>
>
>
>
>On Monday, October 21, 2013 12:24 AM, Anamika Chaudhuri  
>wrote:
>Hi:
>
>I am looking for some help to manipulate data in R. I have two csv files.
>
>datasetY1
>V1 "V2" "V3" "V4"
>1 4 0 20 17
>2 4 0 15 17
>3 2 0 13 21
>
>datasetY2
>V1 "V2" "V3" "V4"
>1 20 52 15 18
>2 18 54 14 21
>3 18 51 13 21
>
>I want to be able to create separate csv files by taking the corresponding
>rows of dataset1 and dataset2, convert them into columns. So from the above
>example I would be creating 3 datasets (csvs), of which the first one would
>be
>               X             Y1            Y2  1 4 20  1 0
>52  1 20 15  1 17
>18
>  Appreciate any help.
>
>Thanks
>Anamika
>
>    [[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] help creating a simple function to rename columns

2013-10-21 Thread Carl Witthoft
Steve E. wrote
> Hi R users,
> 
> I am having some trouble with a very simple function that I hope that you
> might be able to help me with (and, really, to shed some light on how
> functions work generally). I have a series of very small 2-column data
> frames of which I need to change the column names. A simple command such
> as this one below works just fine on any given data frame:
> 
> colnames(DF) <- c("newname1","newname2")
> 
> However, I have to do this for numerous files and would like to address it
> with a function for easier processing but when I put the above in a
> function like this: 
> 
> cnames <- function(DF) {colnames(DF) <- c("newname1","newname2")}
> 
> the function returns a list of the column names instead of the modified
> data frame (e.g., DF <- cnames(DF) returns the list
> c("newname1","newname2") instead of a data frame with the desired column
> names).

1) You've confused what a function *returns* with what goes on inside.  Your
function quite correctly returns the result of the last command, which in
this case is  c('newname1','newname2') .
2) Anything you do *inside* a function persists only in that environment. 
What that means is that your "DF" inside the function is not your "DF" in
your working environment, so nothing you do (with exceptions not to be gone
into here) will change the actual matrix.

An easier way: 
alldf<-list(df1,df2,df3) # for however many little dfs you have
for(j in 1:length(alldf) )  colnames(alldf[[j]])<- c("newname1","newname2")  

I suspect there are cleaner tools in the *apply function  set (or the
data.frame package).




--
View this message in context: 
http://r.789695.n4.nabble.com/help-creating-a-simple-function-to-rename-columns-tp4678719p4678726.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] Recovering object names when using the ... argument in a fn XXXX

2013-10-21 Thread peter dalgaard

On Oct 19, 2013, at 19:03 , Duncan Murdoch wrote:

> On 13-10-18 1:54 PM, Bert Gunter wrote:
>> Yes, similar, but better, as match.call() will get unwanted named
>> arguments, too.
>> 
>> However, I do not understand the
>> 
>> substitute(...())
>> 
>> idiom. Would you care to explain it? (No is an acceptable  answer!).
> 
> I suspect it's a bug, though I can't see it's one that's likely to need 
> fixing.  The general idea is that a function call like ...() is parsed into a 
> pairlist containing just the name "...", then substitute replaces it with the 
> content of that variable, which is a pairlist containing the unevaluated 
> argument list.  So by that analysis, you might expect to get the same result 
> using
> 
> pairlist(...)
> 
> However, you don't, because the latter expression evaluates all the arguments 
> to the function, while Bill's idiom leaves them unevaluated. I can't think of 
> any documented reason why that should be, but on the other hand, I can't 
> think of any reason it would cause problems.  So I'd say it's unlikely to be 
> deliberately changed, but it might change as a result of some internal change 
> to R.
> 
> Duncan Murdoch
> 

Just curious, does substitute(...()) buy you anything that you don't get from 
the straightforward

match.call(expand.dots=FALSE)$...

???
-pd


> 
>> 
>> I would have expressed it as:
>> 
>> as.list(substitute(list(...)))[-1]
>> 
>> to convert the parse tree to a list. (which is again better than using
>> match.call() ).
>> 
>> Best,
>> Bert
>> 
>> On Fri, Oct 18, 2013 at 10:27 AM, William Dunlap  wrote:
 I am using the ... argument to parmeterize a user define fn to accept
 multiple input objects. I subsquently save all these data as a list.
 Question: what is the best way to recover or extract the original object
 names that were fed to the fn?
>>> 
>>> The following function, ellipsisInfo, returns character strings 
>>> representing the
>>> actual arguments to the function.  If the function was called with tags on 
>>> the
>>> arguments, as in ellipsisInfo(tag=argument), it makes those tags the names
>>> on the returned character  vector.  It does not evaluate the ... arguments, 
>>> so
>>> you don't run into problems with evaluating arguments too soon or evaluating
>>> ones that should not be evaluated most of the time.
>>> 
>>> ellipsisInfo <- function(...) {
>>> # get the unevaluated expressions given as arguments
>>> unevaluatedArgs <- substitute(...())
>>> # convert those expressions to text (truncate to single line)
>>> unevaluatedArgsAsText <- vapply(unevaluatedArgs, 
>>> function(a)deparse(a)[1], "")
>>> unevaluatedArgsAsText
>>> }
>>> 
>>> E.g.,
>>> 
 i <- ellipsisInfo(x, log(10), e=exp(1), onProblem=stop("there was a 
 problem"))
 i
>>> 
>>> "x"
>>> 
>>>   "log(10)"
>>>   e
>>>"exp(1)"
>>>   onProblem
>>> "stop(\"there was a problem\")"
 ifelse(names(i)=="", i, names(i)) # use tag if supplied, otherwise 
 argument itself
>>> [1] "x" "log(10)"   "e"
>>> [4] "onProblem"
>>> 
>>> Bill Dunlap
>>> Spotfire, TIBCO Software
>>> wdunlap tibco.com
>>> 
>>> 
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
 On Behalf
 Of Dan Abner
 Sent: Friday, October 18, 2013 9:06 AM
 To: r-help@r-project.org
 Subject: [R] Recovering object names when using the ... argument in a fn 
 
 
 Hi all,
 
 I am using the ... argument to parmeterize a user define fn to accept
 multiple input objects. I subsquently save all these data as a list.
 Question: what is the best way to recover or extract the original object
 names that were fed to the fn?
 
 Thanks,
 
 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-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd..

[R] Error in heatmap

2013-10-21 Thread David Romero
Hi,

 

Could you please help?

 

Heatmap  doesn't work with:

 

> heatmap(as.matrix(SPIV2),na.rm = T)

Error in hclustfun(distfun(x)) : 

  NA/NaN/Inf in foreign function call (arg 11)

 

There are no 0 data rows or column

 

Thanks a lot

 

Regards

---

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.


Re: [R] Recovering object names when using the ... argument in a fn XXXX

2013-10-21 Thread William Dunlap
> Just curious, does substitute(...()) buy you anything that you don't get from 
> the
> straightforward
> 
> match.call(expand.dots=FALSE)$...

substitute() makes is easier to bury the idiom in a function so you don't have 
to
remember the weird syntax.
   > dotdotdot1 <- function(...)substitute(...())
   > dotdotdot2 <- function(...)match.call(expand.dots=FALSE)$...
   > (function(..., FUN)dotdotdot1(...))(1:10, onProblem=stop("oops"), 
FUN=objects)
   [[1]]
   1:10
   
   $onProblem
   stop("oops")

   > (function(..., FUN)dotdotdot2(...))(1:10, onProblem=stop("oops"), 
FUN=objects)
   [[1]]
   ..1
   
   $onProblem
   ..2

I suppose one could figure out appropriate values for match.call's 'definition'
and 'call' arguments to make this work.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: peter dalgaard [mailto:pda...@gmail.com]
> Sent: Monday, October 21, 2013 11:56 AM
> To: Duncan Murdoch
> Cc: Bert Gunter; William Dunlap; r-help@r-project.org
> Subject: Re: [R] Recovering object names when using the ... argument in a fn 
> 
> 
> 
> On Oct 19, 2013, at 19:03 , Duncan Murdoch wrote:
> 
> > On 13-10-18 1:54 PM, Bert Gunter wrote:
> >> Yes, similar, but better, as match.call() will get unwanted named
> >> arguments, too.
> >>
> >> However, I do not understand the
> >>
> >> substitute(...())
> >>
> >> idiom. Would you care to explain it? (No is an acceptable  answer!).
> >
> > I suspect it's a bug, though I can't see it's one that's likely to need 
> > fixing.  The general
> idea is that a function call like ...() is parsed into a pairlist containing 
> just the name "...",
> then substitute replaces it with the content of that variable, which is a 
> pairlist containing
> the unevaluated argument list.  So by that analysis, you might expect to get 
> the same
> result using
> >
> > pairlist(...)
> >
> > However, you don't, because the latter expression evaluates all the 
> > arguments to the
> function, while Bill's idiom leaves them unevaluated. I can't think of any 
> documented
> reason why that should be, but on the other hand, I can't think of any reason 
> it would
> cause problems.  So I'd say it's unlikely to be deliberately changed, but it 
> might change as
> a result of some internal change to R.
> >
> > Duncan Murdoch
> >
> 
> Just curious, does substitute(...()) buy you anything that you don't get from 
> the
> straightforward
> 
> match.call(expand.dots=FALSE)$...
> 
> ???
> -pd
> 
> 
> >
> >>
> >> I would have expressed it as:
> >>
> >> as.list(substitute(list(...)))[-1]
> >>
> >> to convert the parse tree to a list. (which is again better than using
> >> match.call() ).
> >>
> >> Best,
> >> Bert
> >>
> >> On Fri, Oct 18, 2013 at 10:27 AM, William Dunlap  wrote:
>  I am using the ... argument to parmeterize a user define fn to accept
>  multiple input objects. I subsquently save all these data as a list.
>  Question: what is the best way to recover or extract the original object
>  names that were fed to the fn?
> >>>
> >>> The following function, ellipsisInfo, returns character strings 
> >>> representing the
> >>> actual arguments to the function.  If the function was called with tags 
> >>> on the
> >>> arguments, as in ellipsisInfo(tag=argument), it makes those tags the names
> >>> on the returned character  vector.  It does not evaluate the ... 
> >>> arguments, so
> >>> you don't run into problems with evaluating arguments too soon or 
> >>> evaluating
> >>> ones that should not be evaluated most of the time.
> >>>
> >>> ellipsisInfo <- function(...) {
> >>> # get the unevaluated expressions given as arguments
> >>> unevaluatedArgs <- substitute(...())
> >>> # convert those expressions to text (truncate to single line)
> >>> unevaluatedArgsAsText <- vapply(unevaluatedArgs, 
> >>> function(a)deparse(a)[1], "")
> >>> unevaluatedArgsAsText
> >>> }
> >>>
> >>> E.g.,
> >>>
>  i <- ellipsisInfo(x, log(10), e=exp(1), onProblem=stop("there was a 
>  problem"))
>  i
> >>>
> >>> "x"
> >>>
> >>>   "log(10)"
> >>>   e
> >>>"exp(1)"
> >>>   onProblem
> >>> "stop(\"there was a problem\")"
>  ifelse(names(i)=="", i, names(i)) # use tag if supplied, otherwise 
>  argument itself
> >>> [1] "x" "log(10)"   "e"
> >>> [4] "onProblem"
> >>>
> >>> Bill Dunlap
> >>> Spotfire, TIBCO Software
> >>> wdunlap tibco.com
> >>>
> >>>
>  -Original Message-
>  From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
>  On
> Behalf
>  Of Dan Abner
>  Sent: Friday, October 18, 2013 9:06 AM
>  To: r-help@r-project.org
>  Subject: [R] Recovering object names when using the ... argument in a fn 
>  
> 
>  Hi all,
> 
>  I am using the ... argument to parmeterize a user define fn to accept
>  multiple input objec

Re: [R] help creating a simple function to rename columns

2013-10-21 Thread David Winsemius

On Oct 21, 2013, at 11:45 AM, Carl Witthoft wrote:

> Steve E. wrote
>> Hi R users,
>> 
>> I am having some trouble with a very simple function that I hope that you
>> might be able to help me with (and, really, to shed some light on how
>> functions work generally). I have a series of very small 2-column data
>> frames of which I need to change the column names. A simple command such
>> as this one below works just fine on any given data frame:
>> 
>> colnames(DF) <- c("newname1","newname2")
>> 
>> However, I have to do this for numerous files and would like to address it
>> with a function for easier processing but when I put the above in a
>> function like this: 
>> 
>> cnames <- function(DF) {colnames(DF) <- c("newname1","newname2")}
>> 
>> the function returns a list of the column names instead of the modified
>> data frame (e.g., DF <- cnames(DF) returns the list
>> c("newname1","newname2") instead of a data frame with the desired column
>> names).
> 
> 1) You've confused what a function *returns* with what goes on inside.  Your
> function quite correctly returns the result of the last command, which in
> this case is  c('newname1','newname2') .
> 2) Anything you do *inside* a function persists only in that environment. 
> What that means is that your "DF" inside the function is not your "DF" in
> your working environment, so nothing you do (with exceptions not to be gone
> into here) will change the actual matrix.
> 
> An easier way: 
> alldf<-list(df1,df2,df3) # for however many little dfs you have
> for(j in 1:length(alldf) )  colnames(alldf[[j]])<- c("newname1","newname2")  
> 
> I suspect there are cleaner tools in the *apply function  set (or the
> data.frame package).

Carl;

In such an instance , you might try using either `names<-` or `colnames<-` with 
`lapply`.

alldf <- lapply(alldf, `names<-`, c("newname1","newname2")  )

-- 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] speeding up "sum of squared differences" calculation

2013-10-21 Thread Bos, Roger
All,

I am using a sum of squared differences in the objective function of an 
optimization problem I am doing and I have managed to speed it up using the 
outer function versus the nested for loops, but my suspicion is that the 
calculation could be done even quicker.  Please see the code below for a simple 
example.  If anyone can point out a faster way I would appreciate it greatly.

Thanks,

Roger

X <- runif(1000)

now <- proc.time()
ans <- 0
for (i in 1:length(X)) {
  for (j in 1:length(X)) {
ans <- ans + (X[i]-X[j])*(X[i]-X[j])
  }
}
ans
speed <- proc.time() - now; cat(" That took ", round(speed[3],1), " secs.\n", 
sep="")

now <- proc.time()
gg <- outer(X, X, FUN="-")
sum(gg*gg)
speed <- proc.time() - now; cat(" That took ", round(speed[3],1), " secs.\n", 
sep="")

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

2013-10-21 Thread Ken Knoblauch
Bos, Roger  rothschild.com> writes:
> I am using a sum of squared differences in the 
objective function of an optimization problem I am 
doing and I
> have managed to speed it up using the
 outer function versus the nested for loops, but my 
suspicion is that
> the calculation could be done even quicker.  
Please see the code below for a simple example.  If 
anyone can

> point out a faster way I would appreciate it greatly.
> 
> Thanks,
> 
> Roger
> 
> X <- runif(1000)
> 
> now <- proc.time()
> ans <- 0
> for (i in 1:length(X)) {
>   for (j in 1:length(X)) {
> ans <- ans + (X[i]-X[j])*(X[i]-X[j])
>   }
> }
> ans
> speed <- proc.time() - now; cat(" That took ", 
round(speed[3],1), " secs.\n", sep="")
> 
> now <- proc.time()
> gg <- outer(X, X, FUN="-")
> sum(gg*gg)
> speed <- proc.time() - now; cat(" That took ", 
round(speed[3],1), " secs.\n", sep="")
> 
> 

system.time(
for (i in 1:length(X)) {
  for (j in 1:length(X)) {
ans <- ans + (X[i]-X[j])*(X[i]-X[j])
  }
})
   user  system elapsed 
  2.241   0.009   2.293 

system.time(2 * sum(c(dist(X))^2))

   user  system elapsed 
  0.038   0.002   0.040 

and then there is Rcpp if you want to add
some extra grease.

-- 
Kenneth Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html

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

2013-10-21 Thread Ken Knoblauch
Ken Knoblauch  inserm.fr> writes:

> 
> Bos, Roger  rothschild.com> writes:
> > I am using a sum of squared differences in the 
> objective function of an optimization problem I am 
> doing and I
> > have managed to speed it up using the
>  outer function versus the nested for loops, but my 
> suspicion is that
> > the calculation could be done even quicker.  
> Please see the code below for a simple example.  If 
> anyone can
> 
> > point out a faster way I would appreciate it greatly.
> > 
> > Thanks,
> > 
> > Roger
> > 
> > X <- runif(1000)
> > 
> > now <- proc.time()
> > ans <- 0
> > for (i in 1:length(X)) {
> >   for (j in 1:length(X)) {
> > ans <- ans + (X[i]-X[j])*(X[i]-X[j])
> >   }
> > }
> > ans
> > speed <- proc.time() - now; cat(" That took ", 
> round(speed[3],1), " secs.\n", sep="")
> > 
> > now <- proc.time()
> > gg <- outer(X, X, FUN="-")
> > sum(gg*gg)
> > speed <- proc.time() - now; cat(" That took ", 
> round(speed[3],1), " secs.\n", sep="")
> > 
> > 
> 
> system.time(
> for (i in 1:length(X)) {
>   for (j in 1:length(X)) {
> ans <- ans + (X[i]-X[j])*(X[i]-X[j])
>   }
> })
>user  system elapsed 
>   2.241   0.009   2.293 
> 
> system.time(2 * sum(c(dist(X))^2))
> 
>user  system elapsed 
>   0.038   0.002   0.040 
> 
> and then there is Rcpp if you want to add
> some extra grease.
> 

and just to follow-up on my own suggestion

library(Rcpp)

cppFunction('
double ss(NumericVector X){
int n = X.size();
double total = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
 total += (X[i] - X[j]) * (X[i] - X[j]);
return total;
}'
)

system.time(ss(X))
   user  system elapsed 
  0.002   0.000   0.002 

-- 
Kenneth Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html

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

2013-10-21 Thread Berk, Richard
I am trying to update R  from 3.0.1 to 3.0.2. The installer quits saying I need 
a Mac OS of
at least 10.6. I have 10.8.5. I have tried several times over a period of 2 
weeks hoping the
problem would be fixed. Suggestions?


Richard A. Berk
be...@wharton.upenn.edu




[[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] Calculating Blups Using R (lem4 packages)

2013-10-21 Thread Geraldo Carvalho Jr
Hi, 

 

I have some field data from a randomized complete block design trial in two
locations and I would like to calculate BLUPs and BLUEs from this data. I´ve
run some analysis using the lem4 package but I am not too sure about the
results I got. 

 

When I calculate the BLUPs considering environments separate the output
lists genotypes and intercept values. Are these intercept values BLUPs? 

 

Many thanks! I am new in R but I really want learn how to use it for this
purpose. 

 

I aprreciate your time!

 

--

Geraldo Afonso de Carvalho Junior

PhD student, Plant Breeding

Soil and Crop Sciences Dept

Texas A&M University

979-220-9923

 

 


[[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] May I send a zip attachment to a post?

2013-10-21 Thread Hurr
May I send a .zip file attached to a post?




--
View this message in context: 
http://r.789695.n4.nabble.com/May-I-send-a-zip-attachment-to-a-post-tp4678742.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] May I send a zip attachment to a post?

2013-10-21 Thread David Winsemius

On Oct 21, 2013, at 2:15 PM, Hurr wrote:

> May I send a .zip file attached to a post?

No.

-- 
David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Calculating Blups Using R (lem4 packages)

2013-10-21 Thread Bert Gunter
I suggest you post to the R-sig-Mixed-models list rather than here. It
is specifically devoted to mixed models and you are more likely to get
an (reliable!) answer there.

Cheers,
Bert

On Mon, Oct 21, 2013 at 1:11 PM, Geraldo Carvalho Jr
 wrote:
> Hi,
>
>
>
> I have some field data from a randomized complete block design trial in two
> locations and I would like to calculate BLUPs and BLUEs from this data. I´ve
> run some analysis using the lem4 package but I am not too sure about the
> results I got.
>
>
>
> When I calculate the BLUPs considering environments separate the output
> lists genotypes and intercept values. Are these intercept values BLUPs?
>
>
>
> Many thanks! I am new in R but I really want learn how to use it for this
> purpose.
>
>
>
> I aprreciate your time!
>
>
>
> --
>
> Geraldo Afonso de Carvalho Junior
>
> PhD student, Plant Breeding
>
> Soil and Crop Sciences Dept
>
> Texas A&M University
>
> 979-220-9923
>
>
>
>
>
>
> [[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.
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

(650) 467-7374

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] post hoc test to a significant Kruskal-Wallis test package asbio function pairw.kw()

2013-10-21 Thread luigi marongiu
Dear all,
I am trying to apply a post hoc test to a significant Kruskal-Wallis test.
I eventually found the function ‘pairw.kw()’ of the package “asbio”. 
This
function has the following syntax:
pairw.kw(y, x, conf)
Arguments
y The response variable. A vector of quantitative responses.
x An explanatory variable. A vector of factor levels.
conf The level of desired confidence, 1 - P(type I error).

The example reported indicated 2 vectors of length 12 arranged in a data
frame:
rye.data <- data.frame(rye = c(50, 49.8, 52.3, 44.5, 62.3, 74.8, 72.5, 80.2,
47.6, 39.5, 47.7,50.7), nutrient = factor(c(rep(1, 4), rep(2, 4), rep(3,
4
with(rye.data, pairw.kw(y = rye, x = nutrient, conf = .95))

I tried to arrange the data in this way, as well as using my own dataframe
obtained from the read.table() function and directly with two vectors, but
I always obtained an error. Essentially the two vectors are not of the same
length; this is incorrect since there are both 64 elements.

Is there somebody who could tell me how to use this function?

Many thanks,
Luigi

EXAMPLE GIVEN
Here I am using the vector example.

### define vectors
x<-c(0,0,0,0,0,0,0,0,0,0,0,
0,1,1,1,1,1,1,1,1,1,1,1,
1,2,2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,4,4,4,4,
4,4,4,4,4)

y<-c(0.002515324,0.005128344,0.008474943,0.009992525,
0.01460982,0.020567249,0.069597233,0.192428254,
0.636910481,0.673830995,4.354055891,4.847755691,
0.403135211,0.539626363,0.892722111,0.993636963,
1.289747804,3.766986726,5.623002684,8.52186547,
17.24684431,19.84624792,25.9529251,35.64632645,
0.437492775,0.594863773,0.64377689,0.88033664,
3.199906591,5.745723357,6.339129057,6.583851172,
11.27921212,13.01230334,14.61151433,26.68041064,
52.42360789,71.88062442,91.34132781,115.1038548,
0.059333604,0.068746428,0.1473799,0.220983138,
0.959677864,1.21197612,2.860983172,4.402992963,
5.122748306,8.711530662,25.6245157,44.0798333,
45.24736747,66.4490478,86.60427738,0.10348061,
0.390758249,0.634667258,1.122594755,2.726868877,
4.15194739,5.361175006,8.825635885,45.75640999)

### confirm length:
length(x)# 64
length(y)# 64

### KRUSKAL-WALLIS to test inter-group differences
kruskal.test(y, x) # p-value = 0.0008701

### Multiple pairwise comparison procedure to accompany a Kruskal-Wallis
test
pairw.kw(y, x, conf = .95)

# Error in outer(levels(x), levels(x), function(x1, x2) { :
# dims [product 0] do not match the length of object [1]

[[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] Installation of 3.0.2

2013-10-21 Thread Jeff Newmiller
Perhaps ask on r-sig-mac?
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

"Berk, Richard"  wrote:
>I am trying to update R  from 3.0.1 to 3.0.2. The installer quits
>saying I need a Mac OS of
>at least 10.6. I have 10.8.5. I have tried several times over a period
>of 2 weeks hoping the
>problem would be fixed. Suggestions?
>
>
>Richard A. Berk
>be...@wharton.upenn.edu
>
>
>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


[R] How do I use simple calls to java methods?

2013-10-21 Thread Hurr
I need to learn how to set up two methods (java functions) so I can call them
from R.
Currently I just copy and paste R code into the R console. 
A little piece of the R code inside a loop is:
  linTm <- linTimOfCalStg(dta[i,timCol],tlev) 
  calCk <- calStgOfLinTim(linTm,tlev) 
  if(calCk!=dta[i,timCol]) { 
print(c(i,dta[i,timCol],linTm,calCk),digits=20) 
stop("incorrect time conversion") 
  } 
The two functions called have these first lines:
linTimOfCalStg <- function(calStg,tlev) and 
calStgOfLinTim <- function(linTm, tlev) 
which in java substitutes are: 
public final static double linTimOfCalqsStg(String calStg,int tlev)  and  
public final static String calqsStgOfLinTim(double linTm,int tlev) 
both in a java class called "CalqsLin.class" compiled from "CalqsLin.java".
The R code works.
The purpose of all this is to eliminate duplicate subroutines and 
their duplicate checking ln both languages.
There will be several other subroutines that I will also use in both
languages.
I can start by putting everything into a single directory in Windows seven
to learn.
How do I make this substitution?




--
View this message in context: 
http://r.789695.n4.nabble.com/How-do-I-use-simple-calls-to-java-methods-tp4678753.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] cor matrix in multivariate regression

2013-10-21 Thread Suyan Tian
Sorry to bother, I want to construct a correlation matrix in multivariate 
regression  (several dependent variables and they are correlated in some ways) 
like the followings, 

1   0.8   0  0 … 0 0 
0.8 1 0  0  …0 0 
00 1  0.8 …  0 0 
0   0  0.8 1  … 0 0 
. .   . . ….

. ..   .  

0  0  1  0.8 
0  0   0.8 1 

Does anyone know how to do it? 

Thanks,

Suyan Tian 
Associate Professor 
The Jilin University 



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

2013-10-21 Thread Vokey, John
useRs,
  I frequently require the following transform of a matrix that I call a 
leftTranspose:

  -- transposes x such that the last items of each row become
  -- the first items in each column.  E.g.,
  --  a b c d
  --  e f g h
  -- becomes:
  -- d h
  -- c g
  -- b f
  -- a e

because it is a leftward rotation.  I have written my own function, but I was 
wondering whether I was reinventing the wheel here.  Does such a transpose 
already exist in R (or matlab/octave/FreeMat, for that matter)?


--
Please avoid sending me Word or PowerPoint attachments.
See 

-Dr. John R. Vokey

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

2013-10-21 Thread Jorge I Velez
Dear Dr. Vokey,

Here is one approach, although may not be the more efficient:

x <- matrix(1:8, ncol = 4)
x
# [,1] [,2] [,3] [,4]
#[1,]1357
#[2,]2468

t(x[, ncol(x):1])
# [,1] [,2]
#[1,]78
#[2,]56
#[3,]34
#[4,]12

leftTranspose <- function(x)  t(x[, ncol(x):1])
leftTranspose(x)

HTH.
Jorge.-


On Tue, Oct 22, 2013 at 12:52 PM, Vokey, John <> wrote:

> useRs,
>   I frequently require the following transform of a matrix that I call a
> leftTranspose:
>
>   -- transposes x such that the last items of each row become
>   -- the first items in each column.  E.g.,
>   --  a b c d
>   --  e f g h
>   -- becomes:
>   -- d h
>   -- c g
>   -- b f
>   -- a e
>
> because it is a leftward rotation.  I have written my own function, but I
> was wondering whether I was reinventing the wheel here.  Does such a
> transpose already exist in R (or matlab/octave/FreeMat, for that matter)?
>
>
> --
> Please avoid sending me Word or PowerPoint attachments.
> See 
>
> -Dr. John R. Vokey
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] post hoc test to a significant Kruskal-Wallis test package asbio function pairw.kw()

2013-10-21 Thread arun
Hi,
Try:
pairw.kw(y,factor(x),conf=.95)


A.K.




On Monday, October 21, 2013 7:10 PM, luigi marongiu  
wrote:
Dear all,
I am trying to apply a post hoc test to a significant Kruskal-Wallis test.
I eventually found the function ‘pairw.kw()’ of the package “asbio”. This
function has the following syntax:
pairw.kw(y, x, conf)
Arguments
y     The response variable. A vector of quantitative responses.
x     An explanatory variable. A vector of factor levels.
conf     The level of desired confidence, 1 - P(type I error).

The example reported indicated 2 vectors of length 12 arranged in a data
frame:
rye.data <- data.frame(rye = c(50, 49.8, 52.3, 44.5, 62.3, 74.8, 72.5, 80.2,
47.6, 39.5, 47.7,50.7), nutrient = factor(c(rep(1, 4), rep(2, 4), rep(3,
4
with(rye.data, pairw.kw(y = rye, x = nutrient, conf = .95))

I tried to arrange the data in this way, as well as using my own dataframe
obtained from the read.table() function and directly with two vectors, but
I always obtained an error. Essentially the two vectors are not of the same
length; this is incorrect since there are both 64 elements.

Is there somebody who could tell me how to use this function?

Many thanks,
Luigi

EXAMPLE GIVEN
Here I am using the vector example.

### define vectors
x<-c(    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
0,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
1,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
2,    2,    2,    2,    2,    3,    3,    3,    3,    3,    3,    3,
3,    3,    3,    3,    3,    3,    3,    3,    4,    4,    4,    4,
4,    4,    4,    4,    4)

y<-c(    0.002515324,    0.005128344,    0.008474943,    0.009992525,
0.01460982,    0.020567249,    0.069597233,    0.192428254,
0.636910481,    0.673830995,    4.354055891,    4.847755691,
0.403135211,    0.539626363,    0.892722111,    0.993636963,
1.289747804,    3.766986726,    5.623002684,    8.52186547,
17.24684431,    19.84624792,    25.9529251,    35.64632645,
0.437492775,    0.594863773,    0.64377689,    0.88033664,
3.199906591,    5.745723357,    6.339129057,    6.583851172,
11.27921212,    13.01230334,    14.61151433,    26.68041064,
52.42360789,    71.88062442,    91.34132781,    115.1038548,
0.059333604,    0.068746428,    0.1473799,    0.220983138,
0.959677864,    1.21197612,    2.860983172,    4.402992963,
5.122748306,    8.711530662,    25.6245157,    44.0798333,
45.24736747,    66.4490478,    86.60427738,    0.10348061,
0.390758249,    0.634667258,    1.122594755,    2.726868877,
4.15194739,    5.361175006,    8.825635885,    45.75640999)

### confirm length:
    length(x)    # 64
    length(y)    # 64

### KRUSKAL-WALLIS to test inter-group differences
    kruskal.test(y, x)     # p-value = 0.0008701

### Multiple pairwise comparison procedure to accompany a Kruskal-Wallis
test
    pairw.kw(y, x, conf = .95)

# Error in outer(levels(x), levels(x), function(x1, x2) { :
# dims [product 0] do not match the length of object [1]

    [[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] post hoc test to a significant Kruskal-Wallis test package asbio function pairw.kw()

2013-10-21 Thread Andrew Koeser

Luigi,

agricolae has a nice function for this with the post hoc test as part of 
the output.


AKK

On 10/21/2013 11:12 PM, arun wrote:

Hi,
Try:
pairw.kw(y,factor(x),conf=.95)


A.K.




On Monday, October 21, 2013 7:10 PM, luigi marongiu  
wrote:
Dear all,
I am trying to apply a post hoc test to a significant Kruskal-Wallis test.
I eventually found the function ‘pairw.kw()’ of the package “asbio”. This
function has the following syntax:
pairw.kw(y, x, conf)
Arguments
y The response variable. A vector of quantitative responses.
x An explanatory variable. A vector of factor levels.
conf The level of desired confidence, 1 - P(type I error).

The example reported indicated 2 vectors of length 12 arranged in a data
frame:
rye.data <- data.frame(rye = c(50, 49.8, 52.3, 44.5, 62.3, 74.8, 72.5, 80.2,
47.6, 39.5, 47.7,50.7), nutrient = factor(c(rep(1, 4), rep(2, 4), rep(3,
4
with(rye.data, pairw.kw(y = rye, x = nutrient, conf = .95))

I tried to arrange the data in this way, as well as using my own dataframe
obtained from the read.table() function and directly with two vectors, but
I always obtained an error. Essentially the two vectors are not of the same
length; this is incorrect since there are both 64 elements.

Is there somebody who could tell me how to use this function?

Many thanks,
Luigi

EXAMPLE GIVEN
Here I am using the vector example.

### define vectors
x<-c(0,0,0,0,0,0,0,0,0,0,0,
0,1,1,1,1,1,1,1,1,1,1,1,
1,2,2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,4,4,4,4,
4,4,4,4,4)

y<-c(0.002515324,0.005128344,0.008474943,0.009992525,
0.01460982,0.020567249,0.069597233,0.192428254,
0.636910481,0.673830995,4.354055891,4.847755691,
0.403135211,0.539626363,0.892722111,0.993636963,
1.289747804,3.766986726,5.623002684,8.52186547,
17.24684431,19.84624792,25.9529251,35.64632645,
0.437492775,0.594863773,0.64377689,0.88033664,
3.199906591,5.745723357,6.339129057,6.583851172,
11.27921212,13.01230334,14.61151433,26.68041064,
52.42360789,71.88062442,91.34132781,115.1038548,
0.059333604,0.068746428,0.1473799,0.220983138,
0.959677864,1.21197612,2.860983172,4.402992963,
5.122748306,8.711530662,25.6245157,44.0798333,
45.24736747,66.4490478,86.60427738,0.10348061,
0.390758249,0.634667258,1.122594755,2.726868877,
4.15194739,5.361175006,8.825635885,45.75640999)

### confirm length:
 length(x)# 64
 length(y)# 64

### KRUSKAL-WALLIS to test inter-group differences
 kruskal.test(y, x) # p-value = 0.0008701

### Multiple pairwise comparison procedure to accompany a Kruskal-Wallis
test
 pairw.kw(y, x, conf = .95)

# Error in outer(levels(x), levels(x), function(x1, x2) { :
# dims [product 0] do not match the length of object [1]

 [[alternative HTML version deleted]]

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


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


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

2013-10-21 Thread Jim Lemon

On 10/22/2013 01:45 AM, Alaios wrote:

Hi all,
I am having 4 vectors like

Data: num [1:4, 1:32] -82.8 -81.8 -75.5 -107.6 -87.6 ...

and I want to calculate the correlation between those.

Is there a graphical way in R to plot the correlations or not?

I would like to thank you in advance for your help


Hi Alex,
Have a look at color2D.matplot in plotrix, particularly the show.values 
argument and the first example.


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] R - How to "physically" Increase Speed

2013-10-21 Thread Alexandre Khelifa
Hi,

My name is Alexandre Khelifa and I have been using R at my work for about 2
years. I have been working on a project when we do Monte Carlo Simulation
and it involves a lot of calculations.

I am currently using R x64.3.0.1 and used to work on a 4GB machine.
However, the calculation time was very long (about 2 weeks), and the IT
team and I decided to add more memory and to make it a 8GB virtual machine.
 I also added the following line in my code:
*
*

   - *options(java.parameters = "-Xmx8192m") *


I re-did the same calculations (4GB vs. 8GB) but did not see a significant
increase in the calculation time, so I was wondering if I did anything
wrong and/or what would be the best solution to increase this time.

Thanks a lot for your help and more generally for building such an amazing
(and free) tool.
Let me know if you have any questions.

Regards,

Alexandre Khelifa

[[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] Quick advice on loading packages

2013-10-21 Thread Data Analytics Corp.

Hi,

I need some quick advice/help on loading packages.  I want to write a 
simple function to load a number of packages I intend to use at a 
conference presentation.  I'm thinking of something like:


fn.install <- function(){install.packages(c("ggplot2", 
"scales"),  repos = "c:\\temp")}


There will be many more than just the two I listed.  All the zip files 
are in a Windows directory c:\temp.  Will this work?


Thanks,

Walt



Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536

(V) 609-936-8999
(F) 609-936-3733
w...@dataanalyticscorp.com
www.dataanalyticscorp.com

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


Re: [R] R - How to "physically" Increase Speed

2013-10-21 Thread Henrik Bengtsson
On Mon, Oct 21, 2013 at 4:12 PM, Alexandre Khelifa
 wrote:
> Hi,
>
> My name is Alexandre Khelifa and I have been using R at my work for about 2
> years. I have been working on a project when we do Monte Carlo Simulation
> and it involves a lot of calculations.
>
> I am currently using R x64.3.0.1 and used to work on a 4GB machine.
> However, the calculation time was very long (about 2 weeks), and the IT
> team and I decided to add more memory and to make it a 8GB virtual machine.
>  I also added the following line in my code:
> *
> *
>
>- *options(java.parameters = "-Xmx8192m") *
>
>
> I re-did the same calculations (4GB vs. 8GB) but did not see a significant
> increase in the calculation time, so I was wondering if I did anything
> wrong and/or what would be the best solution to increase this time.

If you and your team travel Earth-to-Space round trip at 87% the speed
of light, your computations would *physically* become roughly twice as
fast (you must leave computer behind).  Alternatively, look at
help(package="parallel").  But what really makes a difference is to
find and replace bottle necks in your code by profiling it, cf.
help("Rprof").  I'd go with the latter if you haven't already done so.

/Henrik

>
> Thanks a lot for your help and more generally for building such an amazing
> (and free) tool.
> Let me know if you have any questions.
>
> Regards,
>
> Alexandre Khelifa
>
> [[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] merging matrices

2013-10-21 Thread PIKAL Petr
Hi

?merge

and if you are in reading help pages

?matrix
?data.frame

and of course R-intro.pdf especially chapters about data objects and their 
differences.

Regards
Petr


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of jim holtman
> Sent: Monday, October 21, 2013 5:21 PM
> To: Mohammad Goodarzi
> Cc: R mailing list
> Subject: Re: [R] merging matrices
> 
> ?list.files
> ?read.table
> ?rbind
> 
> Jim Holtman
> Data Munger Guru
> 
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
> 
> 
> On Mon, Oct 21, 2013 at 6:18 AM, Mohammad Goodarzi
>  wrote:
> > Dear all,
> >
> > I have to load more than 1000 matrices from desktop which all of them
> > have the same size.
> > If I do it manually, it would be very hard, can you please guide me
> > how to load them and merge them together ?
> >
> > for example I want to put them one after another
> > X1 X2 X3 etc
> >
> > Many thanks,
> > Mohammad
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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