Re: [R] manual R en español

2011-10-01 Thread pittjj
http://cran.r-project.org/doc/contrib/R-intro-1.1.0-espanol.1.pdf   ?

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

2011-10-01 Thread yehengxin
I used to consider using R and "Optim" to replace my commercial packages:
Gauss and Matlab.  But it turns out that "Optim" does not converge
completely.  The same data for Gauss and Matlab are converged very well.  I
see that there are too many packages based on "optim" and really doubt if
they can be trusted!  

--
View this message in context: 
http://r.789695.n4.nabble.com/Poor-performance-of-Optim-tp3862229p3862229.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] Poor performance of "Optim"

2011-10-01 Thread Rubén Roa
-Original Message-
From: r-help-boun...@r-project.org on behalf of yehengxin
Sent: Sat 10/1/2011 8:12 AM
To: r-help@r-project.org
Subject: [R] Poor performance of "Optim"
 
I used to consider using R and "Optim" to replace my commercial packages:
Gauss and Matlab.  But it turns out that "Optim" does not converge
completely.  The same data for Gauss and Matlab are converged very well.  I
see that there are too many packages based on "optim" and really doubt if
they can be trusted!  

--
Considering that your post is pure whining without any evidence or reproducible 
example, considering that you speak of 'data' being converged, me think it's 
your fault, you cann't
control optim well enough to get sensible results. There are many ways to use 
optim eh?, you can pass on the gradients, you can use a variety of methods, you 
can increase the number of iterations, et cetera, read optim's help, come back 
with a reproducible example, or quietly stick to your commercial sofware, 
leaving the whining to yourself.

HTH

Ruben 

--
Rubén H. Roa-Ureta, Ph. D.
AZTI Tecnalia, Txatxarramendi Ugartea z/g,
Sukarrieta, Bizkaia, SPAIN


--
View this message in context: 
http://r.789695.n4.nabble.com/Poor-performance-of-Optim-tp3862229p3862229.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.


[[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] Poor performance of "Optim"

2011-10-01 Thread Joshua Wiley
Is there a question or point to your message or did you simply feel
the urge to inform the entire R-help list of the things that you
consider?

Josh

On Fri, Sep 30, 2011 at 11:12 PM, yehengxin  wrote:
> I used to consider using R and "Optim" to replace my commercial packages:
> Gauss and Matlab.  But it turns out that "Optim" does not converge
> completely.  The same data for Gauss and Matlab are converged very well.  I
> see that there are too many packages based on "optim" and really doubt if
> they can be trusted!
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Poor-performance-of-Optim-tp3862229p3862229.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

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


Re: [R] Covariance-Variance Matrix and For Loops

2011-10-01 Thread sf1979
Hello again,

sapply works. 

However it does not explicitly call a simplify function, but rather seems to
handle the case within its own body of code. I should be able to figure out
basically what simplify2array does from the code though.

function (X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE) 
{
FUN <- match.fun(FUN)
answer <- lapply(X, FUN, ...)
if (USE.NAMES && is.character(X) && is.null(names(answer))) 
names(answer) <- X
if (simplify && length(answer) && length(common.len <-
unique(unlist(lapply(answer, 
length == 1L) {
if (common.len == 1L) 
unlist(answer, recursive = FALSE)
else if (common.len > 1L) {
r <- as.vector(unlist(answer, recursive = FALSE))
if (prod(d <- c(common.len, length(X))) == length(r)) 
array(r, dim = d, dimnames = if (!(is.null(n1 <-
names(answer[[1L]])) & 
  is.null(n2 <- names(answer 
  list(n1, n2))
else answer
}
else answer
}
else answer
}


--
View this message in context: 
http://r.789695.n4.nabble.com/Covariance-Variance-Matrix-and-For-Loops-tp3859441p3862347.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] Help with cast/reshape

2011-10-01 Thread Daniel Malter
df2<-melt(df1)
df3<-cast(df2,Index~Name)
df3

HTH,
Daniel


Dana Sevak wrote:
> 
> I realize that this is terribly basic, but I just don't seem to see it at
> this moment, so I would very much appreciate your help.
> 
> 
> How shall I transform this dataframe:
> 
>> df1
>   Name Index Value
> 1    a 1   0.1
> 2    a 2   0.2
> 3    a 3   0.3
> 4    a 4   0.4
> 5    b 1   2.1
> 6    b 2   2.2
> 7    b 3   2.3
> 8    b 4   2.4
> 
> 
> into this dataframe:
> 
>> df2
>     Index  a       b
> 1  1     0.1     2.1
> 2  2     0.2     2.2
> 3  3     0.3     2.3
> 4  4     0.4     2.4
> 
> 
> df1 = data.frame(c("a", "a", "a", "a", "b", "b", "b", "b"),
> c(1,2,3,4,1,2,3,4), c(0.1, 0.2, 0.3, 0.4, 2.1, 2.2, 2.3, 2.4))
> colnames(df1) = c("Name", "Index", "Value")
> 
> df2 = data.frame(c(1,2,3,4), c(0.1, 0.2, 0.3, 0.4), c(2.1, 2.2, 2.3, 2.4))
> colnames(df2) = c("Index", "a", "b")
> 
> 
> Thank you very much.
> 
> Dana
> 
> 
> __
> R-help@ mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-cast-reshape-tp3862176p3862404.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Problem with logarithmic nonlinear model using nls() from the `stats' package

2011-10-01 Thread Casper Ti. Vector
Example:

> f <- function(x) { 1 + 2 * log(1 + 3 * x) + rnorm(1, sd = 0.5) }
> y <- f(x <- c(1 : 10)); y
 [1] 4.503841 5.623073 6.336423 6.861151 7.276430 7.620131 7.913338 8.169004
 [9] 8.395662 8.599227
> nls(x ~ a + b * log(1 + c * x), start = list(a = 1, b = 2, c = 3), trace = 
> TRUE)
37.22954 :  1 2 3 
Error in numericDeriv(form[[3L]], names(ind), env) : 
  Missing value or an infinity produced when evaluating the model
In addition: Warning message:
In log(1 + c * x) : NaNs produced

What's wrong here? Am I handling this problem in the wrong way?
Any suggestions are welcome, thanks :)

-- 
Using GPG/PGP? Please get my current public key (ID: 0xAEF6A134,
valid from 2010 to 2013) from a key server.



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


Re: [R] Poor performance of "Optim"

2011-10-01 Thread Marc Girondot

Le 01/10/11 08:12, yehengxin a écrit :

I used to consider using R and "Optim" to replace my commercial packages:
Gauss and Matlab.  But it turns out that "Optim" does not converge
completely.

What it means "completely" ?

The same data for Gauss and Matlab are converged very well.  I
see that there are too many packages based on "optim" and really doubt if
they can be trusted!


I don't understand the "too many". If a package needs an optimization, 
it is normal that it uses optim !


I use the same model in r, Excel solver (the new version is rather good) 
or Profit (a mac software, very powerful) and r is rather one of the 
best solution. But they are many different choices that can influence 
the optimization. You must give an example of the problem.
I find some convergence problem when the criteria to be minimized is the 
result of a stochastic model (ie if the same set of parameters produce 
different objective value depending on the run). In this case the fit 
stops prematurely and the method SANN should be preferred.
In conclusion, give us more information but take into account that 
non-linear optimization is a complex world !

Marc


--
__
Marc Girondot, Pr

Laboratoire Ecologie, Systématique et Evolution
Equipe de Conservation des Populations et des Communautés
CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079
Bâtiment 362
91405 Orsay Cedex, France

Tel:  33 1 (0)1.69.15.72.30   Fax: 33 1 (0)1.69.15.73.53
e-mail: marc.giron...@u-psud.fr
Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
Skype: girondot

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Returning vector of values shared across 3 vectors?

2011-10-01 Thread jim holtman
try this:

> vec1 <- 
> c(4,5,6,7,8,9,10,11,12,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81)
> vec2 <- c 
> (1,2,3,4,5,6,7,8,9,10,11,12,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66)
> vec3 <- c (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,52)
>  intersect(vec1,intersect(vec2, vec3))
 [1]  4  5  6  7  8  9 10 11 12 52
>


On Sat, Oct 1, 2011 at 2:00 AM, Chris Conner  wrote:
> Help-Rs,
>
> I've got three vectors representing participants:
>
> vec1 <- 
> c(4,5,6,7,8,9,10,11,12,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81)
> vec2 <- c 
> (1,2,3,4,5,6,7,8,9,10,11,12,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66)
> vec3 <- c (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,52)
>
> I'd like to return a vector that contains only the values that are shared 
> across ALL THREE vectors. So the statement would return a vector that looked 
> like this:
> 4,5,6,7,8,9,10,11,12,52
>
> For some reason I initially thought that a cbind and a unique() would handle 
> it, but then common sense sunk in.  I think the sleep deprivation is starting 
> to take it's toll.  I've got to believe that there is a simple solution to 
> this dilema.
>
> Thanks in adance for any help!
> C
>        [[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.
>
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

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


Re: [R] Poor performance of "Optim"

2011-10-01 Thread Spencer Graves



  Have you considered the "optimx" package?  I haven't tried it, 
but it was produced by a team of leading researchers in nonlinear 
optimization, including those who wrote most of "optim" 
(http://user2010.org/tutorials/Nash.html) years ago.



  There is a team actively working on this.  If you could provide 
specific examples where Gauss and Matlab outperformed the alternatives 
you've tried in R, especially if Gauss and Matlab outperformed optimx, I 
believe they would be interested.



  As previously noted, nonlinear optimization is a difficult 
problem.  An overview of alternatives available in R, including optim 
and optimx, is available with the CRAN Task View on optimization 
(http://cran.fhcrc.org/web/views/Optimization.html).



  Hope this helps.
  Spencer


On 10/1/2011 3:04 AM, Marc Girondot wrote:

Le 01/10/11 08:12, yehengxin a écrit :

I used to consider using R and "Optim" to replace my commercial
packages:
Gauss and Matlab.  But it turns out that "Optim" does not converge
completely.

What it means "completely" ?

The same data for Gauss and Matlab are converged very well.  I
see that there are too many packages based on "optim" and really
doubt if
they can be trusted!



I don't understand the "too many". If a package needs an optimization,
it is normal that it uses optim !

I use the same model in r, Excel solver (the new version is rather
good) or Profit (a mac software, very powerful) and r is rather one of
the best solution. But they are many different choices that can
influence the optimization. You must give an example of the problem.
I find some convergence problem when the criteria to be minimized is
the result of a stochastic model (ie if the same set of parameters
produce different objective value depending on the run). In this case
the fit stops prematurely and the method SANN should be preferred.
In conclusion, give us more information but take into account that
non-linear optimization is a complex world !
Marc



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

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


Re: [R] Adding axis to an ellipse: "ellipse" package

2011-10-01 Thread Antoine
Dear Rolf,

I tryed to follow your advices but the results I am getting seems still
strange to me. See below an example of a matrix:

datamat <- matrix(c(2.2, 0.4, 0.4, 2.8), 2, 2)
plot(ellipse(datamat),type='l')
eigenval <- eigen(datamat)$values
eigenvect <- eigen(datamat)$vectors
eigenscl  <- eigenvect * sqrt(eigenval) * (qchisq(0.95,2))# One solution to
get rescale

v1 <- (eigenvect[,1])*(sqrt(eigenval[1]))*(qchisq(0.95,2))#or directly
rescale the vectors needed
v2 <- (eigenvect[,2])*(sqrt(eigenval[2]))*(qchisq(0.95,2))
#Or
v1 <- eigenscl[1,]
v2 <- eigenscl[2,]
segments(-v1[1],-v1[2],v1[1],v1[2])
segments(-v2[1],-v2[2],v2[1],v2[2])

The vectors don't seem to be scaled properly and I don't see what I am doing
wrong. Any ideas?

Thanks!
Antoine

--
View this message in context: 
http://r.789695.n4.nabble.com/Adding-axis-to-an-ellipse-ellipse-package-tp3847954p3862491.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] Can I tell about someone's academic cheating

2011-10-01 Thread YuHong
Hello,
Can I tell about someone¡¦s academic cheating behavior in the mailing list?  
For I knew this person through this R mailing list.  Thanks!
Regards,
Hong Yu
 
[[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] class definition

2011-10-01 Thread Omphalodes Verna
Hi everybody!

I have a matrix of class "myClass", for example:

myMat <- matrix(rnorm(30), nrow = 6)
attr(myMat, "class") <- "myClass"
class(myMat)

When I extract part of ''myMat'', the corresponding class ''myClass'' 
unfortunately disappear: 

myMat.p <- myMat[,1:2]
class(myMat.p)

Please for any advice / suggestions, how define class, that during an operation 
does not disappear.

Thanks, OV

[[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] Can I tell about someone's academic cheating

2011-10-01 Thread Rubén Roa
-Original Message-
From: r-help-boun...@r-project.org on behalf of YuHong
Sent: Sun 10/2/2011 3:27 AM
To: r-help@r-project.org
Subject: [R] Can I tell about someone's academic cheating
 
Hello,
Can I tell about someone¡¦s academic cheating behavior in the mailing list?  
For I knew this person through this R mailing list.  Thanks!
Regards,
Hong Yu

--

You have to provide a reproducible example ...

Rubén H. Roa-Ureta, Ph. D.
AZTI Tecnalia, Txatxarramendi Ugartea z/g,
Sukarrieta, Bizkaia, SPAIN




[[alternative HTML version deleted]]

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


Re: [R] Problem with logarithmic nonlinear model using nls() from the `stats' package

2011-10-01 Thread Gabor Grothendieck
On Sat, Oct 1, 2011 at 5:28 AM, Casper Ti. Vector
 wrote:
> Example:
>
>> f <- function(x) { 1 + 2 * log(1 + 3 * x) + rnorm(1, sd = 0.5) }
>> y <- f(x <- c(1 : 10)); y
>  [1] 4.503841 5.623073 6.336423 6.861151 7.276430 7.620131 7.913338 8.169004
>  [9] 8.395662 8.599227
>> nls(x ~ a + b * log(1 + c * x), start = list(a = 1, b = 2, c = 3), trace = 
>> TRUE)
> 37.22954 :  1 2 3
> Error in numericDeriv(form[[3L]], names(ind), env) :
>  Missing value or an infinity produced when evaluating the model
> In addition: Warning message:
> In log(1 + c * x) : NaNs produced
>
> What's wrong here? Am I handling this problem in the wrong way?
> Any suggestions are welcome, thanks :)
>

Its linear given c so calculate the residual sum of squares using lm
(or lm.fit which is faster) given c and optimize over c:

set.seed(123) # for reproducibility

# test data
x <- 1:10
y <- 1 + 2 * log(1 + 3 * x) + rnorm(1, sd = 0.5)

# calculate residual sum of squares for best fit given c
fitc <- function(c) lm.fit(cbind(1, log(1 + c * x)), y)
rssvals <- function(c) sum(resid(fitc(c))^2)

out <- optimize(rssvals, c(0.01, 10))

which gives:

> setNames(c(coef(fitc(out$minimum)), out$minimum), letters[1:3])
a b c
0.7197666 2.007 2.899

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

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


Re: [R] Problem with logarithmic nonlinear model using nls() from the `stats' package

2011-10-01 Thread Gabor Grothendieck
On Sat, Oct 1, 2011 at 9:27 AM, Gabor Grothendieck
 wrote:
> On Sat, Oct 1, 2011 at 5:28 AM, Casper Ti. Vector
>  wrote:
>> Example:
>>
>>> f <- function(x) { 1 + 2 * log(1 + 3 * x) + rnorm(1, sd = 0.5) }
>>> y <- f(x <- c(1 : 10)); y
>>  [1] 4.503841 5.623073 6.336423 6.861151 7.276430 7.620131 7.913338 8.169004
>>  [9] 8.395662 8.599227
>>> nls(x ~ a + b * log(1 + c * x), start = list(a = 1, b = 2, c = 3), trace = 
>>> TRUE)
>> 37.22954 :  1 2 3
>> Error in numericDeriv(form[[3L]], names(ind), env) :
>>  Missing value or an infinity produced when evaluating the model
>> In addition: Warning message:
>> In log(1 + c * x) : NaNs produced
>>
>> What's wrong here? Am I handling this problem in the wrong way?
>> Any suggestions are welcome, thanks :)
>>
>
> Its linear given c so calculate the residual sum of squares using lm
> (or lm.fit which is faster) given c and optimize over c:
>
> set.seed(123) # for reproducibility
>
> # test data
> x <- 1:10
> y <- 1 + 2 * log(1 + 3 * x) + rnorm(1, sd = 0.5)
>
> # calculate residual sum of squares for best fit given c
> fitc <- function(c) lm.fit(cbind(1, log(1 + c * x)), y)
> rssvals <- function(c) sum(resid(fitc(c))^2)
>
> out <- optimize(rssvals, c(0.01, 10))
>
> which gives:
>
>> setNames(c(coef(fitc(out$minimum)), out$minimum), letters[1:3])
>        a         b         c
> 0.7197666 2.007 2.899

Also you probably intended to write 10 instead of 1 as the arg to rnorm.


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

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


Re: [R] Odd gridding pattern when plotting

2011-10-01 Thread Uwe Ligges
I think you found a bug introduced in R-2.13.x that has been fixed in 
R-2.13.2 which has been released yesterday.


Best,
Uwe Ligges


On 30.09.2011 21:36, Balko, Justin wrote:

Thanks, that kind of helps.  However, some of my previous code uses functions 
like heatmap.2 which has multiple images (legend/color key) as well as the 
actual heatmap.  Employing useRaster=TRUE here only applies to the heatmap and 
not the legend.  Not a huge deal.  Is there anyway to set an option in R to 
always use rastering when drawing in the interface?
Thanks again,
Justin

-Original Message-
From: David L Carlson [mailto:dcarl...@tamu.edu]
Sent: Friday, September 30, 2011 1:54 PM
To: Balko, Justin; r-help@r-project.org
Subject: RE: [R] Odd gridding pattern when plotting


From ?image


" Images for large z on a regular grid are more efficient with useRaster enabled and 
can prevent rare anti-aliasing artifacts, but may not be supported by all graphics 
devices."

Adding useRaster=TRUE to the two image() calls gets rid of the white grid lines.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Balko, Justin
Sent: Friday, September 30, 2011 10:43 AM
To: r-help@r-project.org
Subject: [R] Odd gridding pattern when plotting


Hi, I'm no longer on the subscribing list, but was hoping to get my question 
posted.  Please inform if this is ok, although I am guessing you wont post with 
the image below.  If so, let me know and I will resend without the image.
Thanks


Hi,
I just upgraded my system and my version of R all at once.  Upon running old 
code for heatmaps etc, I suddenly notice that there is an odd grid pattern 
appearing in all of my plots.  An example is below:

#example from ?image

require(grDevices) # for colours
x<- y<- seq(-4*pi, 4*pi, len=27)
r<- sqrt(outer(x^2, y^2, "+"))
image(z = z<- cos(r^2)*exp(-r/6), col=gray((0:32)/32)) image(z, axes = FALSE, main = 
"Math can be beautiful ...",
   xlab = expression(cos(r^2) * e^{-r/6})) contour(z, add = TRUE, 
drawlabels = FALSE)



Any ideas what is causing this?  I can't seem to figure it out.  I'm not sure 
the bmp image can/will be posted, so maybe you can just take my word for it.  
It is a gridding pattern in white, that appears over the plot area only.  
Vertical lines are every 4 units, evenly spaced.  Horizontal lines appear at 
every unit, then stop for a while (6-7 units, then appear every unit for 4-5 
units).  Simple plots like plot(x,y) do not seem to produce it, or at least I 
can't see it.  Any ideas are helpful.
Thanks!


Justin M. Balko, Pharm.D., Ph.D.
Research Fellow, Arteaga Lab
Department of Medicine
Division of Hematology/Oncology
Vanderbilt University
777 Preston Research Building
Nashville TN, 37232-6307
Ph: 615-936-1495

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problem with logarithmic nonlinear model using nls() from the `stats' package

2011-10-01 Thread Casper Ti. Vector
Ah, now I see...
Thanks very much :)

On Sat, Oct 01, 2011 at 09:27:34AM -0400, Gabor Grothendieck wrote:
> On Sat, Oct 1, 2011 at 5:28 AM, Casper Ti. Vector
>  wrote:
> Its linear given c so calculate the residual sum of squares using lm
> (or lm.fit which is faster) given c and optimize over c:
> 
> set.seed(123) # for reproducibility
> x <- 1:10
> y <- 1 + 2 * log(1 + 3 * x) + rnorm(1, sd = 0.5)
> fitc <- function(c) lm.fit(cbind(1, log(1 + c * x)), y)
> rssvals <- function(c) sum(resid(fitc(c))^2)
> out <- optimize(rssvals, c(0.01, 10))
> 
> which gives:
> 0.7197666 2.007 2.899

-- 
Using GPG/PGP? Please get my current public key (ID: 0xAEF6A134,
valid from 2010 to 2013) from a key server.



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


Re: [R] class definition

2011-10-01 Thread Uwe Ligges



On 01.10.2011 13:21, Omphalodes Verna wrote:

Hi everybody!

I have a matrix of class "myClass", for example:

myMat<- matrix(rnorm(30), nrow = 6)
attr(myMat, "class")<- "myClass"
class(myMat)

When I extract part of ''myMat'', the corresponding class ''myClass'' 
unfortunately disappear:

myMat.p<- myMat[,1:2]
class(myMat.p)

Please for any advice / suggestions, how define class, that during an operation 
does not disappear.


You will need a "[" method for your class.

Uwe Ligges





Thanks, OV

[[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] Covariance-Variance Matrix and For Loops

2011-10-01 Thread R. Michael Weylandt
Surprising: must be  newer update than I realizedanyways, here's
the code if you want to add it manually:

simplify2array <-
function (x, higher = TRUE)
{
if (length(common.len <- unique(unlist(lapply(x, length >
1L)
return(x)
if (common.len == 1L)
unlist(x, recursive = FALSE)
else if (common.len > 1L) {
n <- length(x)
r <- as.vector(unlist(x, recursive = FALSE))
if (higher && length(c.dim <- unique(lapply(x, dim))) ==
1 && is.numeric(c.dim <- c.dim[[1L]]) && prod(d <- c(c.dim,
n)) == length(r)) {
iN1 <- is.null(n1 <- dimnames(x[[1L]]))
n2 <- names(x)
dnam <- if (!(iN1 && is.null(n2)))
c(if (iN1) rep.int(list(n1), length(c.dim)) else n1,
  list(n2))
array(r, dim = d, dimnames = dnam)
}
else if (prod(d <- c(common.len, n)) == length(r))
array(r, dim = d, dimnames = if (!(is.null(n1 <- names(x[[1L]])) &
is.null(n2 <- names(x
list(n1, n2))
else x
}
else x
}


On Sat, Oct 1, 2011 at 4:22 AM, sf1979  wrote:
> Hello again,
>
> sapply works.
>
> However it does not explicitly call a simplify function, but rather seems to
> handle the case within its own body of code. I should be able to figure out
> basically what simplify2array does from the code though.
>
> function (X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)
> {
>    FUN <- match.fun(FUN)
>    answer <- lapply(X, FUN, ...)
>    if (USE.NAMES && is.character(X) && is.null(names(answer)))
>        names(answer) <- X
>    if (simplify && length(answer) && length(common.len <-
> unique(unlist(lapply(answer,
>        length == 1L) {
>        if (common.len == 1L)
>            unlist(answer, recursive = FALSE)
>        else if (common.len > 1L) {
>            r <- as.vector(unlist(answer, recursive = FALSE))
>            if (prod(d <- c(common.len, length(X))) == length(r))
>                array(r, dim = d, dimnames = if (!(is.null(n1 <-
> names(answer[[1L]])) &
>                  is.null(n2 <- names(answer
>                  list(n1, n2))
>            else answer
>        }
>        else answer
>    }
>    else answer
> }
> 
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Covariance-Variance-Matrix-and-For-Loops-tp3859441p3862347.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Nearest neighbour in a matrix

2011-10-01 Thread Spartina
Hi, sorry for the late reply. I just wanted to thank both of you for your
answers. They were helpful and also thank you for mentioning the website
that has the tutorials which is a most helpful resource.

Cheers,

Léa

--
View this message in context: 
http://r.789695.n4.nabble.com/Nearest-neighbour-in-a-matrix-tp3845747p3862973.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] Is the output of survfit.coxph survival or baseline survival?

2011-10-01 Thread David Winsemius


On Sep 30, 2011, at 9:31 PM, koshihaku wrote:


Dear all,
I am confused with the output of survfit.coxph.
Someone said that the survival given by summary(survfit.coxph) is the
baseline survival S_0, but some said that is the survival  
S=S_0^exp{beta*x}.


Which one is correct?


It may depend on who _some_ and _someone_ mean by S_0 and who they  
are. I have in the past posted erroneous answers, but the name on  
which to search the archives is 'Terry Therneau'. My current  
understanding is that the survival S_0 is the estimated survival for a  
hypothetical subject whose continuous and discrete covariates are all  
at their means. (But I have been wrong before.) Here is some of what  
Therneau has said about it:


http://finzi.psych.upenn.edu/Rhelp10/2010-October/257941.html
http://finzi.psych.upenn.edu/Rhelp10/2009-March/190341.html
http://finzi.psych.upenn.edu/Rhelp10/2009-February/189768.html



By the way, if I use "newdata=" in the survfit, does that mean the  
survival

is estimated by the value of covariates in the new data frame?


In one sense yes, but in another sense, no. If you have a cox fit and  
you  supply newdata, the beta estimates and the baseline survival come  
from in the original data. If you just give it a formula, then there  
is no newdata argument, only a data argument.


Try this:
 fit <- coxph( Surv(futime, fustat)~rx, data=ovarian)
 plot( survfit(fit, newdata=data.frame(rx=1) ) )
 plot( survfit( Surv(futime, fustat)~rx, data=ovarian) )

Then flipping back and forth between those curves might clarify, at  
least to the extent that I understand this question.


And here's a pathological extrapolation:

 plot(survfit(fit, newdata=data.frame(rx=1:3)))

# There is no rx=3 in the original data but it wasn't defined as a  
factor when given to coxph.
# Just checked to see if you could extrapolate past the end of a range  
of factors and very sensibly you cannot.

> fit <- coxph( Surv(futime, fustat)~factor(rx), data=ovarian)
> plot(survfit(fit, newdata=data.frame(rx=1:3)))
Error in model.frame.default(data = data.frame(rx = 1:3), formula =  
~factor(rx),  :

  factor 'factor(rx)' has new level(s) 3


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


[R] error using ddply to generate means

2011-10-01 Thread Aidan Corcoran
Dear list,

I encounter an error when I try to use ddply to generate means as follows:

fun3<-structure(list(sector = structure(list(gics_sector_name = c("Financials",
"Financials", "Materials", "Materials")), .Names = "gics_sector_name",
row.names = structure(c("UBSN VX Equity",
"LLOY LN Equity", "AI FP Equity", "AKE FP Equity"), .Dim = 4L), class
= "data.frame"),
   bebitpcchg = c(-0.567449058550428, 0.99600643852127, NA,
   -42.7587478692081), ticker = c("UBSN VX Equity", "LLOY LN Equity",
   "AI FP Equity", "AKE FP Equity")), .Names = c("sector", "bebitpcchg",
"ticker"), row.names = c(12L, 24L, 36L, 48L), class = "data.frame")

fun3

  gics_sector_name  bebitpcchg ticker
12   Financials  -0.5674491 UBSN VX Equity
24   Financials   0.9960064 LLOY LN Equity
36Materials  NA   AI FP Equity
48Materials -42.7587479  AKE FP Equity


fun4<-ddply(fun3,c("sector"),summarise,avgbebitchg=mean(bebitpcchg,na.rm=TRUE))

Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing =
decreasing)) :
 undefined columns selected

This is a small sample of my data. I’m probably overlooking some
problem in my syntax, but would be very grateful if someone could
point it out.

Thanks in advance,
Aidan.

sessionInfo()

R version 2.13.0 (2011-04-13)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_Ireland.1252  LC_CTYPE=English_Ireland.1252
LC_MONETARY=English_Ireland.1252
[4] LC_NUMERIC=C LC_TIME=English_Ireland.1252

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

other attached packages:
 [1] plm_1.2-7  sandwich_2.2-7 MASS_7.3-12
Formula_1.0-1  nlme_3.1-100
 [6] bdsmatrix_1.0  RBloomberg_0.4-149 rJava_0.8-8
gtools_2.6.2   gdata_2.8.2
[11] ggplot2_0.8.9  proto_0.3-9.2  zoo_1.7-4
reshape_0.8.4  plyr_1.6

loaded via a namespace (and not attached):
[1] lattice_0.19-23 tools_2.13.0

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


Re: [R] error using ddply to generate means

2011-10-01 Thread Dennis Murphy
Hi:

Here's the problem:

> str(fun3)
'data.frame':   4 obs. of  3 variables:
 $ sector:'data.frame': 4 obs. of  1 variable:
  ..$ gics_sector_name: chr  "Financials" "Financials" "Materials" "Materials"
 $ bebitpcchg: num  -0.567 0.996 NA -42.759
 $ ticker: chr  "UBSN VX Equity" "LLOY LN Equity" "AI FP Equity"
"AKE FP Equity"

Notice that fun3$sector is a data frame, not a variable. By leaving
fun3 intact, the summary is gotten with

ddply(fun3, .(sector$gics_sector_name), summarise,
avgbebitchg=mean(bebitpcchg,na.rm=TRUE))
  sector$gics_sector_name avgbebitchg
1  Financials   0.2142787
2   Materials -42.7587479

You might consider reframing fun3, pardon the pun.

HTH,
Dennis
On Sat, Oct 1, 2011 at 7:58 AM, Aidan Corcoran
 wrote:
> Dear list,
>
> I encounter an error when I try to use ddply to generate means as follows:
>
> fun3<-structure(list(sector = structure(list(gics_sector_name = 
> c("Financials",
> "Financials", "Materials", "Materials")), .Names = "gics_sector_name",
> row.names = structure(c("UBSN VX Equity",
> "LLOY LN Equity", "AI FP Equity", "AKE FP Equity"), .Dim = 4L), class
> = "data.frame"),
>   bebitpcchg = c(-0.567449058550428, 0.99600643852127, NA,
>   -42.7587478692081), ticker = c("UBSN VX Equity", "LLOY LN Equity",
>   "AI FP Equity", "AKE FP Equity")), .Names = c("sector", "bebitpcchg",
> "ticker"), row.names = c(12L, 24L, 36L, 48L), class = "data.frame")
>
> fun3
>
>  gics_sector_name  bebitpcchg         ticker
> 12       Financials  -0.5674491 UBSN VX Equity
> 24       Financials   0.9960064 LLOY LN Equity
> 36        Materials          NA   AI FP Equity
> 48        Materials -42.7587479  AKE FP Equity
>
>
> fun4<-ddply(fun3,c("sector"),summarise,avgbebitchg=mean(bebitpcchg,na.rm=TRUE))
>
> Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing =
> decreasing)) :
>  undefined columns selected
>
> This is a small sample of my data. I’m probably overlooking some
> problem in my syntax, but would be very grateful if someone could
> point it out.
>
> Thanks in advance,
> Aidan.
>
> sessionInfo()
>
> R version 2.13.0 (2011-04-13)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=English_Ireland.1252  LC_CTYPE=English_Ireland.1252
> LC_MONETARY=English_Ireland.1252
> [4] LC_NUMERIC=C                     LC_TIME=English_Ireland.1252
>
> attached base packages:
> [1] grid      stats     graphics  grDevices utils     datasets
> methods   base
>
> other attached packages:
>  [1] plm_1.2-7          sandwich_2.2-7     MASS_7.3-12
> Formula_1.0-1      nlme_3.1-100
>  [6] bdsmatrix_1.0      RBloomberg_0.4-149 rJava_0.8-8
> gtools_2.6.2       gdata_2.8.2
> [11] ggplot2_0.8.9      proto_0.3-9.2      zoo_1.7-4
> reshape_0.8.4      plyr_1.6
>
> loaded via a namespace (and not attached):
> [1] lattice_0.19-23 tools_2.13.0
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Covariance-Variance Matrix and For Loops

2011-10-01 Thread sf1979
That's very helpful Michael, thank you. I will add it to the arsenal. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Covariance-Variance-Matrix-and-For-Loops-tp3859441p3863098.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] error while using shapiro.test()

2011-10-01 Thread spicymchaggis101
Thank you very much! your response solved my issue.

I needed to determine the probability of normality for word types per page. 

--
View this message in context: 
http://r.789695.n4.nabble.com/error-while-using-shapiro-test-tp3861535p3863205.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] Gstat - Installation Fail _ download source and compile help ...

2011-10-01 Thread Sandeep Patil
Hello

I have been trying to install gstat on university's unix based system ( i am
not familiar with many technical aspects of installation) but i am getting a
particular error which i could not find a solution to online. Here is what
the technical support guy mailed me back, i am sure someone who understands
the technicalities can explain me this procedure in a more lucid way.
*
**Technical Assistant's reply*
*
Unfortunately, the error is due to a type being used in one of the
source files which has not yet been defined in an include file.
The "u_int" type is defined in /usr/include/sys/types.h:

   typedef __u_int u_int;

And, the "__u_int" type is defined in /usr/include/bits/types.h:

   typedef unsigned int __u_int;

Note that  is included at the top of , so
only the  would need to be included.

Without including , the program won't recognize
"u_int" as a valid type.  So, this is an issue with the configuration
or perhaps source for the given program being compiled by the
package installation function of R.

My suggestion would be to search for the given error message on any
support/help/discussion boards/websites related to the R program.
Or, do a google search to see if anyone else has encountered the same
error and find their suggested solution.

Otherwise, you can manually download the source to your directory and
attempt to tweak the "configure" command, which would generate a more
correct Makefile.  Or, in the least desirable scenario, insert the
needed "#include " in the given *.c file yourself and
compile.
*
Can anyone make out anything from this , i want to tweak the configure
command but do not know how to proceed.

[[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] Create web applications to run R scripts

2011-10-01 Thread syrvn
Hello,

is there anything similar to the Rwui package to create web applications to
run R scripts?


Many thanks,
syrvn

--
View this message in context: 
http://r.789695.n4.nabble.com/Create-web-applications-to-run-R-scripts-tp3863457p3863457.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] Create web applications to run R scripts

2011-10-01 Thread Dirk Eddelbuettel
On Sat, Oct 01, 2011 at 11:34:47AM -0700, syrvn wrote:
> Hello,
> 
> is there anything similar to the Rwui package to create web applications to
> run R scripts?

There is an entire section of the R FAQ devoted to this.

Dirk

-- 
Three out of two people have difficulties with fractions.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Printing an xtable with type = html

2011-10-01 Thread Juliet Hannah
Maybe some of the comments in this post may be informative to you:

http://r.789695.n4.nabble.com/improve-formatting-of-HTML-table-td3736299.html

On Wed, Sep 28, 2011 at 6:21 AM, David Scott  wrote:
>
> I have been playing around with producing tables using xtable and the type =
> "html" argument when printing. For example, if xtbl is the output of a
> dataframe which has been run through xtable, using the command:
>
> print(xtbl, type = "html",
>      html.table.attributes = "border = '1', align = 'center'")
>
> I would be interested to see other examples of the use of xtable to produce
> html. There is a whole vignette on using xtable to produce all sorts of
> tables for incorporation into a TeX document but I have found no examples of
> producing html with any table attributes.
>
> Ideally xtable should be able to access a css file but I don't see any
> mechanism for doing that. Perhaps someone can enlighten me.
>
> David Scott
>
> --
> _
> David Scott     Department of Statistics
>                The University of Auckland, PB 92019
>                Auckland 1142,    NEW ZEALAND
> Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
> Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Understanding the workflow between sweave, R and Latex

2011-10-01 Thread Michael Friendly

On 9/30/2011 9:08 AM, syrvn wrote:

Hi Duncan,

I use Eclipse and StatET plus TexClipse and Sweave which comes with the
StatET package.
So fore me it is basically one click as well to produce the pdf from the
.Rnw file.

I installed the MacTex live 2011 version on my computer and thought it might
actually be
easy to find out how and where latex searches for packages. But I did not
find the place
where all this is coded...



First, since this is Mac-related, you would probably get better answers 
on the R-sig-mac list.


Second, most latex distributions support both a system 'texmf' tree and 
one or more local/user texmf trees, that you can configure with 
something like Preferences somewhere in MacTex.  On my linux system, I use

~/texmf/ and simply copied Sweave.sty to
~/texmf/tex/latex/misc/Sweave.sty   (if my path-memory serves)
No more worries (unless Sweave.sty is changed in a new R distro)

Finally, it does help to RTFM, where you can find other options
under ?RweaveLatex in the Details section.

The LaTeX file generated needs to contain the line \usepackage{Sweave}, 
and if this is not present in the Sweave source file (possibly in a 
comment), it is inserted by the RweaveLatex driver. If stylepath = TRUE, 
a hard-coded path to the file ‘Sweave.sty’ in the R installation is set 
in place of Sweave. The hard-coded path makes the LaTeX file less 
portable, but avoids the problem of installing the current version of 
‘Sweave.sty’ to some place in your TeX input path. However, TeX may not 
be able to process the hard-coded path if it contains spaces (as it 
often will under Windows) or TeX special characters.


The default for stylepath is now taken from the environment variable 
SWEAVE_STYLEPATH_DEFAULT, or is FALSE it that is unset or empty. If set, 
it should be exactly TRUE or FALSE: any other values are taken as FALSE.


As from R 2.12.0, the simplest way for frequent Sweave users to ensure 
that ‘Sweave.sty’ is in the TeX input path is to add 
‘R_HOME/share/texmf’ as a ‘texmf tree’ (‘root directory’ in the parlance 
of the ‘MiKTeX settings’ utility).


By default, ‘Sweave.sty’ sets the width of all included graphics to:
\setkeys{Gin}{width=0.8\textwidth}.

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

2011-10-01 Thread Jim Silverton
Hi all,
I have 2 columns in a mtrix, one of which is a column of probabilities and
the other is simply a vector of integers. I want to sum all the
probabilities with the same integer value and put it in a new column.
For example,
If my matrix is:

0.98   2
0.2 1
0.01   2
0.5 1
0.6 6


Then I should get:
0.98   20.99
0.2 10.70
0.01   20.99
0.5 10.70
0.6 60.60

Any help is greatly appreciated.



-- 
Thanks,
Jim.

[[alternative HTML version deleted]]

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


Re: [R] Poor performance of "Optim"

2011-10-01 Thread Daniel Malter
With respect, your statement that R's optim does not give you a reliable
estimator is bogus. As pointed out before, this would depend on when optim
believes it's good enough and stops optimizing. In particular if you stretch
out x, then it is plausible that the likelihood function will become flat
enough "earlier," so that the numerical optimization will stop earlier
(i.e., optim will "think" that the slope of the likelihood function is flat
enough to be considered zero and stop earlier than it will for more
condensed data). After all, maximum likelihood is a numerical method and
thus an approximation. I would venture to say that what you describe lies in
the nature of this method. You could also follow the good advice given
earlier, by increasing the number of iterations or decreasing the tolerance. 

However, check the example below: for all purposes it's really close enough
and has nothing to do with optim being "unreliable."

n<-1000
x<-rnorm(n)
y<-0.5*x+rnorm(n)
z<-ifelse(y>0,1,0)

X<-cbind(1,x)
b<-matrix(c(0,0),nrow=2)

#Probit
reg<-glm(z~x,family=binomial("probit"))

#Optim reproducing probit (with minor deviations due to difference in
method)
LL<-function(b){-sum(z*log(pnorm(X%*%b))+(1-z)*log(1-pnorm(X%*%b)))}
optim(c(0,0),LL)

#Multiply x by 2 and repeat optim
X[,2]=2*X[,2]
optim(c(0,0),LL)

HTH,
Daniel



yehengxin wrote:
> 
> What I tried is just a simple binary probit model.   Create a random data
> and use "optim" to maximize the log-likelihood function to estimate the
> coefficients.   (e.g. u = 0.1+0.2*x + e, e is standard normal.  And y = (u
> > 0),  y indicating a binary choice variable)
> 
> If I estimate coefficient of "x", I should be able to get a value close to
> 0.2 if sample is large enough.  Say I got 0.18. 
> 
> If I expand x by twice and reestimate the model, which coefficient should
> I get?  0.09, right?
> 
> But with "optim", I got something different.  When I do the same thing in
> both Gauss and Matlab, I can exactly get 0.09, evidencing that the
> coefficient estimator is reliable.  But R's "optim" does not give me a
> reliable estimator.
> 

--
View this message in context: 
http://r.789695.n4.nabble.com/Poor-performance-of-Optim-tp3862229p3864133.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] Sum of Probabilities in a matrix...

2011-10-01 Thread Dennis Murphy
Let's make it a data frame instead:

# Read the data from your post into a data frame named d:
d <- read.table(textConnection("
0.98   2
0.2 1
0.01   2
0.5 1
0.6 6"))
closeAllConnections()

# Use the ave() function and append the result to d:
d$sumprob <- with(d, ave(V1, V2, FUN = sum))

> d
V1 V2 sumprob
1 0.98  20.99
2 0.20  10.70
3 0.01  20.99
4 0.50  10.70
5 0.60  60.60

HTH,
Dennis

On Sat, Oct 1, 2011 at 6:06 PM, Jim Silverton  wrote:
> Hi all,
> I have 2 columns in a mtrix, one of which is a column of probabilities and
> the other is simply a vector of integers. I want to sum all the
> probabilities with the same integer value and put it in a new column.
> For example,
> If my matrix is:
>
> 0.98   2
> 0.2     1
> 0.01   2
> 0.5     1
> 0.6     6
>
>
> Then I should get:
> 0.98   2    0.99
> 0.2     1    0.70
> 0.01   2    0.99
> 0.5     1    0.70
> 0.6     6    0.60
>
> Any help is greatly appreciated.
>
>
>
> --
> Thanks,
> Jim.
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 Studio and Rcmdr/RcmdrPlugins

2011-10-01 Thread Erin Hodgess
Dear R People:

Hope you're having a great weekend!

Anyhow, I'm currently experimenting with R Studio on a web server,
which is the best thing since sliced bread, Coca Cola, etc.

My one question:  there is a way to show plots.  is there a way to
show Rcmdr or its Plugins, please?  I tried, but it doesn't seem to
work.

Thanks so much,
Sincerely,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@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] Adding axis to an ellipse: "ellipse" package

2011-10-01 Thread Rolf Turner


See comments in-line:

On 01/10/11 23:26, Antoine wrote:

Dear Rolf,

I tryed to follow your advices but the results I am getting seems still
strange to me. See below an example of a matrix:

datamat<- matrix(c(2.2, 0.4, 0.4, 2.8), 2, 2)
plot(ellipse(datamat),type='l')
eigenval<- eigen(datamat)$values
eigenvect<- eigen(datamat)$vectors
eigenscl<- eigenvect * sqrt(eigenval) * (qchisq(0.95,2))# One solution to
get rescale


This is wrong because you are multiplying the i-th row of ``eigenvect''
the square root of the i-th eigenvalue.  The *columns* of ``eigenvect''
are the eigenvectors.  So you need to multiply the j-th column by
the square root of the j-th eigenvalue.

v1<- (eigenvect[,1])*(sqrt(eigenval[1]))*(qchisq(0.95,2))#or directly
rescale the vectors needed
v2<- (eigenvect[,2])*(sqrt(eigenval[2]))*(qchisq(0.95,2))


The foregoing is correct except that you need to take the square
root of the chi-squared quantile.

#Or
v1<- eigenscl[1,]
v2<- eigenscl[2,]
segments(-v1[1],-v1[2],v1[1],v1[2])
segments(-v2[1],-v2[2],v2[1],v2[2])

The vectors don't seem to be scaled properly and I don't see what I am doing
wrong. Any ideas?


Here is correct code:

require(ellipse)
S <- matrix(c(2.2, 0.4, 0.4, 2.8), 2, 2)
# Note the ``asp=1'' which makes orthogonal lines
# look orthogonal:
plot(ellipse(S),type='l',asp=1)
E <- eigen(S)
Val <- E$values
Vec <- E$vectors
v1 <- sqrt(Val[1]*qchisq(0.95,2))*Vec[,1]
v2 <- sqrt(Val[2]*qchisq(0.95,2))*Vec[,2]
segments(-v1[1],-v1[2],v1[1],v1[2])
segments(-v2[1],-v2[2],v2[1],v2[2])

cheers,

Rolf Turner

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

2011-10-01 Thread Rolf Turner

On 02/10/11 14:06, Jim Silverton wrote:

Hi all,
I have 2 columns in a mtrix, one of which is a column of probabilities and
the other is simply a vector of integers. I want to sum all the
probabilities with the same integer value and put it in a new column.
For example,
If my matrix is:

0.98   2
0.2 1
0.01   2
0.5 1
0.6 6


Then I should get:
0.98   20.99
0.2 10.70
0.01   20.99
0.5 10.70
0.6 60.60

Any help is greatly appreciated.


Suppose your matrix is called "m".  Execute:

> ttt <- tapply(m[,1],m[,2],sum)
> m <- cbind(m,ttt[match(m[,2],names(ttt))])
> dimnames(m) <- NULL # To tidy up a bit.

You get:
> m
 [,1] [,2] [,3]
[1,] 0.982 0.99
[2,] 0.201 0.70
[3,] 0.012 0.99
[4,] 0.501 0.70
[5,] 0.606 0.60

Easy-peasy.

cheers,

Rolf Turner

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

2011-10-01 Thread Felipe Nunes
Any good news Arne?

*Felipe Nunes*
CAPES/Fulbright Fellow
PhD Student Political Science - UCLA
Web: felipenunes.bol.ucla.edu



On Thu, Sep 29, 2011 at 5:10 AM, Arne Henningsen <
arne.henning...@googlemail.com> wrote:

> Hi Felipe
>
> On 25 September 2011 00:16, Felipe Nunes  wrote:
> > Hi Arne,
> > my problem persists. I am still using censReg [version - 0.5-7] to run a
> > random effects model in my data (>50,000 cases), but I always get the
> > message.
> > tob7 <- censReg(transfers.cap ~ pt.pt + psdb.pt + pt.opp + pt.coa +
> psdb.coa
> > + pib.cap + transfers.cap.lag + pib.cap + ifdm + log(populat) +
> > mayor.vot.per + log(bol.fam.per+0.01) + factor(uf.name) + factor(year) -
> 1,
> > left=0, right=Inf, method="BHHH", nGHQ=8, iterlim=1, data = pdata2)
> > Error in maxNRCompute(fn = logLikAttr, fnOrig = fn, gradOrig = grad,
> > hessOrig = hess,  :
> >   NA in the initial gradient
> > If I sent you my data set, could you try to help me? I have been
> struggling
> > with that for two months now.
>
> Thanks for sending me your data set. With it, I was able to figure
> out, where the NAs in the (initial) gradients come from: when
> calculating the derivatives of the standard normal density function [d
> dnorm(x) / d x = - dnorm(x) * x], values for x that are larger than
> approximately 40 (in absolute terms) result in so small values (in
> absolute terms) that R rounds them to zero. Later, these derivatives
> are multiplied by some other values and then the logarithm is taken
> ... and multiplying any number by zero and taking the logarithms gives
> not a finite number :-(
>
> When *densities* of the standard normal distribution become too small,
> one can use dnorm(x,log=TRUE) and store the logarithm of the small
> number, which is much larger (in absolute terms) than the density and
> hence, is not rounded to zero. However, in the case of the
> *derivative* of the standard normal density function, this is more
> complicated as log( d dnorm(x) / d x ) =  log( dnorm(x) ) + log( - x )
> is not defined if x is positive. I will try to solve this problem by
> case distinction (x>0 vs. x<0). Or does anybody know a better
> solution?
>
> /Arne
>
> --
> Arne Henningsen
> http://www.arne-henningsen.name
>

[[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] getting list of data.frame names

2011-10-01 Thread Erin Hodgess
Dear R People:

This is probably a very simple question.  I know that if I want to get
a list of the classes of the objects in the workspace, I can do this:

> sapply(ls(), function(x)class(get(x)))
   aa1.dfbd
  "list" "data.frame""integer""numeric"

Now I want to get just the data frames.
> sapply(ls(), function(x)class(get(x))=="data.frame")
a a1.df b d
FALSE  TRUE FALSE FALSE

However, I would like the names of the data frames, rather than the
True/False for the objects.

I've been trying all sorts of combinations/permutations with no success.

Any suggestions would be much appreciated.

Thanks,
Sincerely,
Erin



-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@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] getting list of data.frame names

2011-10-01 Thread Joshua Wiley
Hi Erin,

Try this: names(which(sapply(.GlobalEnv, is.data.frame)))

Cheers,

Josh

On Sat, Oct 1, 2011 at 8:37 PM, Erin Hodgess  wrote:
> Dear R People:
>
> This is probably a very simple question.  I know that if I want to get
> a list of the classes of the objects in the workspace, I can do this:
>
>> sapply(ls(), function(x)class(get(x)))
>           a        a1.df            b            d
>      "list" "data.frame"    "integer"    "numeric"
>
> Now I want to get just the data frames.
>> sapply(ls(), function(x)class(get(x))=="data.frame")
>    a a1.df     b     d
> FALSE  TRUE FALSE FALSE
>
> However, I would like the names of the data frames, rather than the
> True/False for the objects.
>
> I've been trying all sorts of combinations/permutations with no success.
>
> Any suggestions would be much appreciated.
>
> Thanks,
> Sincerely,
> Erin
>
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodg...@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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

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


[R] Fitting 3 beta distributions

2011-10-01 Thread Nitin Bhardwaj
Hi,
I want to fit 3 beta distributions to my data which ranges between 0 and 1.
What are the functions that I can easily call and specify that 3 beta
distributions should be fitted?
I have already looked at normalmixEM and fitdistr but they dont seem to be
applicable (normalmixEM is only for fitting normal dist and fitdistr will
only fit 1 distribution, not 3). Is that right?

Also, my data has 26 million data points. What can I do to reduce the
computation time with the suggested function?
thanks a lot in advance,
eagerly waiting for any input.
Best
Nitin

-- 
ΝI+IИ

[[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] deSolve - Function daspk on DAE system - Error

2011-10-01 Thread Vince
I'm getting this error on the attached code and breaking my head but can't
figure it out. Any help is much appreciated. Thanks, Vince

CODE:
library(deSolve)

Res_DAE=function(t, y, dy, pars) {
  with(as.list(c(y, dy, pars)), {
 
  res1 = -dS -dES-k2*ES
  res2 = -dP + k2*ES
 
  eq1 = Eo-E -ES
  eq2 = So-S -ES -P
  return(list(c(res1, res2, eq1, eq2)))
  })
}

pars <- c(Eo=0.02, So=0.02, k2=250, E=0.01); pars
yini <- c(S=0.01, ES = 0.01, P=0.0, E=0.01); yini
times <- seq(0, 0.01, by = 0.0001); times
dyini = c(dS=0.0, dES=0.0, dP=0.0)

## Tabular output check of matrix output

DAE <- daspk(y = yini, dy = dyini, times = times, res = Res_DAE, parms =
pars, atol = 1e-10, rtol = 1e-10)

ERROR:
daspk--  warning.. At T(=R1) and stepsize H (=R2) the  nonlinear solver
f
  nonlinear solver failed to converge  repeatedly of with abs (H) =
H
  repeatedly of with abs (H) = HMIN  preconditioner had repeated
failur
0.0D+00  0.5960464477539D-14
Warning messages:
1: In daspk(y = yini, dy = dyini, times = times, res = Res_DAE, parms =
pars,  :
  repeated convergence test failures on a step - inaccurate Jacobian or
preconditioner?
2: In daspk(y = yini, dy = dyini, times = times, res = Res_DAE, parms =
pars,  :
  Returning early. Results are accurate, as far as they go

--
View this message in context: 
http://r.789695.n4.nabble.com/deSolve-Function-daspk-on-DAE-system-Error-tp3864298p3864298.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] Entering data into a multi-way array?

2011-10-01 Thread Victoria_Stuart
I am trying to replicate the script, appended below.  My data is in OOCalc
files.  The script (below) synthesizes a dataset (it serves as a
"tutorial"), but I will need to get my data from OOCalc into R for use in
that script (which uses arrays).

I've worked my way through the script, and understand how most of it works
(except the first bit - Step 1 - which is irrelevant to me, anyway).

[begin script]

### Supplementary material with the paper
### Interpretation of ANOVA models for microarray data using PCA
### J.R. de Haan et al. Bioinformatics (2006)
### Please cite this paper when you use this code in a publication.
### Written by J.R. de Haan, December 18, 2006

### Step1: a synthetic dataset of 500 genes is generated with 5 classes
### 1 unresponsive genes (300 genes)
### 2 constant genes (50 genes)
### 3 profile 1 (50 genes)
### 4 profile 2 (50 genes)
### 5 profile 3 (50 genes)

#generate synthetic dataset with similar dimensions:
# 500 genes, 3 replicates, 10 timepoints, 4 treatments
X <- array(0, c(500, 3, 10, 4))
labs.synth <- c(rep(1, 300), rep(2, 50), rep(3, 50), rep(4, 50), rep(5, 50))
gnames <- cbind(labs.synth, labs.synth)
#print(dim(gnames))
gnames[1:300,2] <- "A"
gnames[301:350,2] <- "B"
gnames[351:400,2] <- "C"
gnames[401:450,2] <- "D"
gnames[451:500,2] <- "E"

### generate 300 "noise" genes with expressions slightly larger than
### the detection limit (class 1)
X[labs.synth==1,1,,] <- rnorm(length(X[labs.synth==1,1,,]), mean=50, sd=40)
X[labs.synth==1,2,,] <- X[labs.synth==1,1,,] +
  rnorm(length(X[labs.synth==1,1,,]), mean=0, sd=10)
X[labs.synth==1,3,,] <- X[labs.synth==1,1,,] +
  rnorm(length(X[labs.synth==1,1,,]), mean=0, sd=10)

# generate 50 stable genes at two levels (class 2)
X[301:325,1,,] <- rnorm(length(X[301:325,1,,]), mean=1500, sd=40)
X[301:325,2,,] <- X[301:325,1,,] + rnorm(length(X[301:325,1,,]), mean=0,
sd=10)
X[301:325,3,,] <- X[301:325,1,,] + rnorm(length(X[301:325,1,,]), mean=0,
sd=10)

X[326:350,1,,] <- rnorm(length(X[326:350,1,,]), mean=3000, sd=40)
X[326:350,2,,] <- X[326:350,1,,] + rnorm(length(X[326:350,1,,]), mean=0,
sd=10)
X[326:350,3,,] <- X[326:350,1,,] + rnorm(length(X[326:350,1,,]), mean=0,
sd=10)

# generate50 genes with profile 1 (class 3)
increase.range <- matrix(rep(1:50, 10), ncol=10, byrow=FALSE)
profA3 <- matrix(rep(c(10, 60, 110, 150, 150, 150, 150, 150, 150, 150) ,
50),
 ncol=10, byrow=TRUE) * increase.range
X[351:400,1,,1] <- profA3 + rnorm(length(profA3), mean=0, sd=40)
profB3 <- matrix(rep(c(10, 100, 220, 280, 280, 280, 280, 280, 280, 280),
50),
 ncol=10, byrow=TRUE) * increase.range
X[351:400,1,1:10,2] <- profB3 + rnorm(length(profA3), mean=0, sd=40)
profC3 <- matrix(rep(c(10, 120, 300, 300, 280, 280, 280, 280, 280, 280),
50),
 ncol=10, byrow=TRUE) * increase.range
X[351:400,1,1:10,3] <- profC3 + rnorm(length(profA3), mean=0, sd=40)
profD3 <- matrix(rep(c(100, 75, 50, 50, 50, 50, 50, 50, 75, 100), 50),
ncol=10,
 byrow=TRUE)
X[351:400,1,1:10,4] <- profD3 + rnorm(length(profA3), mean=0, sd=40)
#again replicates
X[351:400,2,,] <- X[351:400,1,,] + rnorm(length(X[351:400,2,,]), mean=0,
sd=10)
X[351:400,3,,] <- X[351:400,1,,] + rnorm(length(X[351:400,3,,]), mean=0,
sd=10)

# generate50 genes with profile 2 (class 4)
increase.range <- matrix(rep(1:50, 10), ncol=10, byrow=FALSE)
profA4 <- matrix(rep(c(10, 60, 110, 150, 125, 100, 75, 50, 50, 50) , 50),
 ncol=10, byrow=TRUE) * increase.range
X[401:450,1,,1] <- profA4 + rnorm(length(profA4), mean=0, sd=40)
profB4 <- matrix(rep(c(10, 100, 220, 280, 200, 150, 100, 50, 50, 50), 50),
 ncol=10, byrow=TRUE) * increase.range
X[401:450,1,1:10,2] <- profB4 + rnorm(length(profA4), mean=0, sd=40)
profC4 <- matrix(rep(c(10, 150, 300, 220, 150, 100, 50, 50, 50, 50), 50),
 ncol=10, byrow=TRUE) * increase.range
X[401:450,1,1:10,3] <- profC4 + rnorm(length(profA4), mean=0, sd=40)
profD4 <- matrix(rep(c(150, 100, 50, 50, 75, 75, 75, 100, 100, 100), 50),
 ncol=10, byrow=TRUE)
X[401:450,1,1:10,4] <- profD4 + rnorm(length(profA4), mean=0, sd=40)
#again replicates
X[401:450,2,,] <- X[401:450,1,,] + rnorm(length(X[401:450,2,,]), mean=0,
sd=10)
X[401:450,3,,] <- X[401:450,1,,] + rnorm(length(X[401:450,3,,]), mean=0,
sd=10)

# generate50 genes with profile 3 (class 5)
increase.range <- matrix(rep(1:25, 20), ncol=10, byrow=FALSE)
profA4 <- matrix(rep((200 - c(10, 60, 110, 150, 125, 100, 75, 50, 50, 50)),
50),
 ncol=10, byrow=TRUE) * increase.range
X[451:500,1,,1] <- profA4 + rnorm(length(profA4), mean=0, sd=40)
profB4 <- matrix(rep((200 - c(10, 100, 180, 200, 200, 150, 100, 50, 50,
50)), 50),
 ncol=10, byrow=TRUE) * increase.range
X[451:500,1,1:10,2] <- profB4 + rnorm(length(profA4), mean=0, sd=40)
profC4 <- matrix(rep((200 - c(10, 150, 200, 180, 150, 100, 50, 50, 50, 50)),
50),
 ncol=10, byrow=TRUE) * increase.range
X[451:500,1,1:10,3]

Re: [R] Poor performance of "Optim"

2011-10-01 Thread yehengxin
Thank you for your response!
But the problem is when I estimate a model without knowing the true
coefficients, how can I know which "reltol" is good enough?  "1e-8" or
"1e-10"?  Why can commercial packages automatically determine the right
"reltol" but R cannot?

--
View this message in context: 
http://r.789695.n4.nabble.com/Poor-performance-of-Optim-tp3862229p3864243.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] Poor performance of "Optim"

2011-10-01 Thread yehengxin
What I tried is just a simple binary probit model.   Create a random data and
use "optim" to maximize the log-likelihood function to estimate the
coefficients.   (e.g. u = 0.1+0.2*x + e, e is standard normal.  And y = (u >
0),  y indicating a binary choice variable)

If I estimate coefficient of "x", I should be able to get a value close to
0.2 if sample is large enough.  Say I got 0.18. 

If I expand x by twice and reestimate the model, which coefficient should I
get?  0.09, right?

But with "optim", I got something different.  When I do the same thing in
both Gauss and Matlab, I can exactly get 0.09, evidencing that the
coefficient estimator is reliable.  But R's "optim" does not give me a
reliable estimator. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Poor-performance-of-Optim-tp3862229p3863969.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] Multivariate Laplace density

2011-10-01 Thread zerfetzen
Can anyone show how to calculate a multivariate Laplace density? Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/Multivariate-Laplace-density-tp3864072p3864072.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] Poor performance of "Optim"

2011-10-01 Thread yehengxin
Oh, I think  I got it.  Commercial packages limit the number of decimals
shown.  

--
View this message in context: 
http://r.789695.n4.nabble.com/Poor-performance-of-Optim-tp3862229p3864271.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.