Re: [R] How to install Defaults package offline

2010-04-10 Thread Prof Brian Ripley

On Fri, 9 Apr 2010, dbonneau wrote:



Hi,
I just installed R software on my machine which is not supposed to have an
internet access. I installed several package that I need, which are
quantmod, xts, TTR etc. When I typed require(quantmod), I get  Error:
package 'Defaults' could not be loaded. How do you install Defaults package
if you don't have an internet access ? Does anyone know where I can find the
file so I can install it manually ?


The same place you found the packages quantmod, xts and TTR?
Defaults is a CRAN package, see
http://cran.r-project.org/web/packages/Defaults/index.html

Now, you did not tell us your OS, R version or whether you were 
looking for source or binary packages, so you made it maximally 
difficult for us to give more precise details.


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

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


Re: [R] [stats-rosuda-devel] How to update JGR

2010-04-10 Thread Simon Urbanek
On Apr 9, 2010, at 6:10 PM, mau...@alice.it mau...@alice.it wrote:

 I recently updated R on Linus/SuSE 11.1
 I complained because no on-line help was available from JGR after R update. I 
 was told to update JGR as well.
 How can I do that ?
 I installed JGR on SuSE three times in the past with different R 
 versions.Every time it's been a nightmare.
 I am afraid to have to spend a whole day, maybe longer, to update JGR ...
 I would greatly appreciate some clear guidelines for JGR installation/update 
 on SuSE.
 Thank you in advance.

The upgrade should be trivial as long as your system is properly setup - simply 
run

update.packages(ask=FALSE, checkBuilt=TRUE)

that works for all packages. If that fails then either R or Java on your system 
are not setup properly.

Instructions for installing JGR from scratch on SuSE are at
http://jgr.markushelbig.org/JGR_on_Linux.html

If all that doesn't help all I can say if you want easier setup get a more 
user-firendy distro or system ;).

Cheers,
Simon

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

2010-04-10 Thread Jim Lemon

On 04/10/2010 01:22 AM, David Nemer wrote:

Hey Everyone,

Im fresh new in R, and Im supposed to write a code to give me a correlation
between two rankings. So I have two ranking lists, which contain file names,
e.g.:

Ranking list 1:
file1.java
file3.java
file2.java

Ranking list 2:
fiile2.java
file4.java
file1.java

I need to see how much are these two ranking lists are alike, get a
correlation between them. I dont even know where to start. Can anyone bring
me some light or tips? Thank you in advance.


Hi David,
Are you sure you don't want the concordance between the rankings? If so, 
look at the irr package for some concordance functions. The example 
shows pretty much no concordance.


Jim

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


Re: [R] interpolating between lat/long position data with time

2010-04-10 Thread Paul Hiemstra

cbarcelo wrote:

Hello,
I am currently working with satellite tracking data for an organism with
irregularly spaced location data in space and time (point data is
occasionally spaced by 1-10 days). I have 4 columns of data, Lat, Long,
Date, Time. I would like to linearly interpolate my data set so that I have
one position per day with attached time stamps. I am fairly new to R, any
pointers on code for this would be most helpful!
Thanks!
  

Hi,

Take a look at the Spatial Task view, this provides an introduction to 
all kinds spatial data processing in R. In addition, the R-sig-geo 
mailing list is a more suitable list to ask this question, you will 
probably get more response there.


cheers,
Paul

--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770

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

2010-04-10 Thread Gabor Grothendieck
Try this:

 A - c(file1.java, file3.java, file2.java)
 B - c(file2.java, file4.java, file1.java)
 cor(A, B, method = spearman)
[1] 0.5


On Fri, Apr 9, 2010 at 11:22 AM, David Nemer davidne...@gmail.com wrote:
 Hey Everyone,

 Im fresh new in R, and Im supposed to write a code to give me a correlation
 between two rankings. So I have two ranking lists, which contain file names,
 e.g.:

 Ranking list 1:
 file1.java
 file3.java
 file2.java

 Ranking list 2:
 fiile2.java
 file4.java
 file1.java

 I need to see how much are these two ranking lists are alike, get a
 correlation between them. I dont even know where to start. Can anyone bring
 me some light or tips? Thank you in advance.

 Cheers,
 --
 David Nemer

        [[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] Brier's score for bootstrap sample (coxph)

2010-04-10 Thread Frank E Harrell Jr

paaventhan jeyaganth wrote:

Dear all,

How can i get brier's score for the bootsrap sample for survival analysis.

this are the code i am using for the validation.

 

f1 - cph(Surv(time,dead ) ~ strata(x1)+strata(x2)+strata(x3), 
x=TRUE, y=TRUE, surv=TRUE, time.inc=12, data=new)


 


validate(f1,B=200,u=12,dxy=T)

 

 


Thanks

Paaveen



You did not following the posting guide.

You mixed two package; the functions you used did not match the subject 
line of your e-mail.


You are attempting to validate a model containing no covariates, which 
is not impossible but will be noisy.


You did not point to a function or package that claims to be able to 
compute a Brier score with censored data.


Frank


--
Frank E Harrell Jr   Professor and ChairmanSchool of Medicine
 Department of Biostatistics   Vanderbilt 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] minimization function

2010-04-10 Thread li li
Hi all,
I am trying to minimize the quardratic form w'Aw, with certain
constraints.
In particular,
(1) A=(a_{ij}) is n by n matrix and it is symmetric positive definite,
a_{ii}=1 for all i;
and 0a_{ij}1 for i not equal j.
(2) w'1=n;
(3) w_{i}=0

Analytically, for n=2, it is easy to come up with a result. For larger n, it
seems
difficult to obtain the result.

Does any one know whether it is possible to use R to numerically compute it?

Thank you so much in advance!


Hannah

[[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] str: how to use no list recursively?

2010-04-10 Thread Henrique Dallazuanna
Try this:

cat(gsub(:List of .*, , capture.output(str(x, no.list = TRUE))), sep = '\n')

On Fri, Apr 9, 2010 at 11:11 PM, Jeff Brown dopethatwantsc...@yahoo.com wrote:

 Hi,

 In the help file for str(), the following line appears: no.list         
 logical;
 if true, no ‘list of ...’ nor the class are printed.  However, that appears
 to be true only on the top level; setting no.list to TRUE still leaves the
 remaining levels with the `list of ...' statement intact:

 x - list(
 +       a = list(list()),
 +       b = list(list())
 + );
 str(x)
 List of 2
  $ a:List of 1
  ..$ : list()
  $ b:List of 1
  ..$ : list()
 str(x, no.list = TRUE)
  $ a:List of 1
  ..$ : list()
  $ b:List of 1
  ..$ : list()


 For readability reasons, I'd like to keep the indented $ signs and the names
 of the sub-lists but suppress printing of `List of ...'.  Is that possible?

 Thanks,
 Jeff
 --
 View this message in context: 
 http://n4.nabble.com/str-how-to-use-no-list-recursively-tp1820073p1820073.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.




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

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


Re: [R] use read.table for a partial reading

2010-04-10 Thread Robert Baer
- Original Message - 
From: Covelli Paolo pcove...@tele2.it

To: r-help@r-project.org
Sent: Thursday, April 08, 2010 9:05 AM
Subject: [R] use read.table for a partial reading



Hi everyone,

I've got a matrix data with 20 variables (V1, V2, V3, ...) and 215  rows 
(observations). I'm interested to read only the first and second 
variables using read.table function. How can I do?



You do not provide a reproducible example (see 
http://www.R-project.org/posting-guide.html), so my comments are somewhat of 
a guess.


Typically, when you read in data from a file in R, you read it into a 'data 
frame' not a matrix.
(To earn more 
http://cran.r-project.org/doc/manuals/R-intro.html#Lists-and-data-frames)


This is how you would get your data (the dataframe) in the form you desire:
dat - read.table(mydata.txt, header = TRUE)
dat2 - dat[,1:2]  # contains just the first two variables, V1 and V2





Thanks in advance.

Paolo.

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

2010-04-10 Thread Paul Smith
On Sat, Apr 10, 2010 at 4:58 PM, li li hannah@gmail.com wrote:
    I am trying to minimize the quardratic form w'Aw, with certain
 constraints.
 In particular,
    (1) A=(a_{ij}) is n by n matrix and it is symmetric positive definite,
        a_{ii}=1 for all i;
        and 0a_{ij}1 for i not equal j.
    (2) w'1=n;
    (3) w_{i}=0

 Analytically, for n=2, it is easy to come up with a result. For larger n, it
 seems
 difficult to obtain the result.

 Does any one know whether it is possible to use R to numerically compute it?

And your decision variables are? Both w[i] and a[i,j] ?

Paul

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


Re: [R] use read.table for a partial reading

2010-04-10 Thread Henrique Dallazuanna
Try this also:

your_data - read.table('your_file.txt', colClasses = c('character',
'character', rep(NULL, 18)))

On Thu, Apr 8, 2010 at 11:05 AM, Covelli Paolo pcove...@tele2.it wrote:
 Hi everyone,

 I've got a matrix data with 20 variables (V1, V2, V3, ...) and 215 rows
 (observations). I'm interested to read only the first and second variables
 using read.table function. How can I do?

 Thanks in advance.

 Paolo.

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




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

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


Re: [R] minimization function

2010-04-10 Thread Paul Smith
On Sat, Apr 10, 2010 at 5:13 PM, Paul Smith phh...@gmail.com wrote:
    I am trying to minimize the quardratic form w'Aw, with certain
 constraints.
 In particular,
    (1) A=(a_{ij}) is n by n matrix and it is symmetric positive definite,
        a_{ii}=1 for all i;
        and 0a_{ij}1 for i not equal j.
    (2) w'1=n;
    (3) w_{i}=0

 Analytically, for n=2, it is easy to come up with a result. For larger n, it
 seems
 difficult to obtain the result.

 Does any one know whether it is possible to use R to numerically compute it?

 And your decision variables are? Both w[i] and a[i,j] ?

In addition, what do you mean by larger n? n = 20 is already large
(in your sense)?

Paul

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


Re: [R] Read data in sequences

2010-04-10 Thread Peter Ehlers

On 2010-04-09 10:04, Dieter Menne wrote:



RockO wrote:


I tried to find a solution in the search list, but I cannot find it. I
would like to read a .txt file with, let say, three variables, with two of
which have repeated values in a number a columns.

The variables: Treat, x1, x2.
The values:
A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4 ...
B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1 ...
...

In the first column, the letters represent the variable Treat, and the
sequence of numbers on a same line represent pairs of values for x1 and
x2.




Looks like SAS is quite elegant here (don't kill me, I could not afford
using SAS, R has save my retirement fund).

I would first read it in as usual, and do the reformatting later.

library(reshape)
wide = read.table(wideseq.txt,sep= )
# renames columns
names(wide) =  c(varname,rep(c(x1,x2),ncol(wide)%/%2))
str(wide)
melt(wide)

Now you have the long format, which is not exactly what you want, but
typically much more useful in R than the format you require. You might use
one of the function in package reshape to get your format.


Almost. But you're a bit too clever with the names() because
melt() will just re-read the first x1, x2 values.

wide - as above ...
dm - melt(wide)
# replace dm$variable with appropriate factor
dm$variable - gl(2, 2, nrow(dm), c('x1','x2'))
# choose names for columns
names(dm) - c('Treat', 'x', 'value')

I agree that this 'long' format is usually most useful for
further analysis.

 -Peter

--
Peter Ehlers
University of Calgary

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

2010-04-10 Thread Gabor Grothendieck
Try this.  The data portion DF[-1] is transposed forming length 2
columns composed of successive elements of DF rows.  This is then
transposed back and the id's added in:

# read in
Lines - A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4
 B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1
DF - read.table(textConnection(Lines))

# form required data frame
data.frame(id = DF[gl(2,4),1], t(matrix(t(DF[-1]), 2)))



On Fri, Apr 9, 2010 at 11:25 AM, RockO rock.oui...@gmail.com wrote:

 Dear R users,

 I tried to find a solution in the search list, but I cannot find it. I would
 like to read a .txt file with, let say, three variables, with two of which
 have repeated values in a number a columns.

 An example:

 The variables: Treat, x1, x2.
 The values:
 A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4 ...
 B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1 ...
 ...

 In the first column, the letters represent the variable Treat, and the
 sequence of numbers on a same line represent pairs of values for x1 and
 x2.

 In SAS, this type of dataset is easy to read using @@ as in:
 data a;
 input Treat @ x1 x2 @@;

 But I would like to know how to read it with R, to get rid of my addiction
 to SAS.

 Thank You,

 Rock Ouimet
 DRF-MRNF, Quebec
 --
 View this message in context: 
 http://n4.nabble.com/Read-data-in-sequences-tp1819487p1819487.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] I can´t run the example shown in the inline pa ckage

2010-04-10 Thread Uwe Ligges



On 09.04.2010 17:43, satu wrote:


Dear Romain, you are right. Apologies, here is the complete result from your
script:



code- '#includeRdefines.h\nSEXP f(){\n return R_NilValue ; }'
writeLines( code, test.c )
  system( R CMD SHLIB test.c )

gcc -IC:/R/R-210~1.1/include-O3 -Wall  -std=gnu99 -c test.c -o
test.o
gcc -shared -s -o test.dll tmp.def test.o -LC:/R/R-210~1.1/bin -lR

dyn.load( test.so )


On Windows it is names test.dll.

Uwe Ligges



Error in inDL(x, as.logical(local), as.logical(now), ...) :
   unable to load shared library 'C:/Documents and Settings/L01359.BCRA/Mis
documentos/R/test.so':
   LoadLibrary failure:  No se puede encontrar el módulo especificado.
.Call( f )
Error in .Call(f) : C symbol name f not in load table




The system(,,,) bit seems to work, but then errors show up

Sergio


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

2010-04-10 Thread casperyc

Hi,

I have written a function,
( or 2 functions)
becasue there are only tiny difference,

One of them has lines
==
#c2 (price.mat) call option price
c2=c(
max(S.mat[1,3]-K,0),
max(S.mat[2,3]-K,0),
max(S.mat[3,3]-K,0)
)

(some lines)

list(
Stock Value=round(S.mat,dp),
Call Price=round(price.mat,dp),
Phi=round(phi.mat,dp),
Psi=round(psi.mat,dp)
)
===

and the other one is

==
#c2 (price.mat) put option price
c2=c(
max(K-S.mat[1,3],0), -difference
max(K-S.mat[2,3],0), -difference
max(K-S.mat[3,3],0)  -difference
)

(some lines)

list(
Stock Value=round(S.mat,dp),
Put Price=round(price.mat,dp),  -label difference
Phi=round(phi.mat,dp),
Psi=round(psi.mat,dp)
)
===

Can I combine them into one function?
just by adding a 'dummy variable' say 'type' 
which takes call/put or values 1,2

The full codes are in attachment.

Thanks!


http://n4.nabble.com/file/n1835638/mycall.r mycall.r 

http://n4.nabble.com/file/n1835638/myput.r myput.r 

casper

-- 
View this message in context: 
http://n4.nabble.com/writing-function-help-tp1835638p1835638.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] fill in values between rollapply

2010-04-10 Thread Brad Patrick Schneid

Dennis:
I had never used the rep() function and that works out great, thank you.
Brad
-- 
View this message in context: 
http://n4.nabble.com/fill-in-values-between-rollapply-tp1816885p1835513.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] simple data import of .csv

2010-04-10 Thread doconnor

Hello,

I am a complete beginner to R.  I use a mac and want to import and read a
.csv dataset stored as .csv file.

I understand I eventually enter - read.csv(size.csv, header=T)   , but I
can't get R to find my file, which is called size.csv and located
/Users/davidoconnor/Desktop/Eart-125/size.csv

Thank you very much!

David
-- 
View this message in context: 
http://n4.nabble.com/simple-data-import-of-csv-tp1835620p1835620.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] simple data import of .csv

2010-04-10 Thread William Revelle

Hello,

I am a complete beginner to R.  I use a mac and want to import and read a
.csv dataset stored as .csv file.

I understand I eventually enter - read.csv(size.csv, header=T)   , but I
can't get R to find my file, which is called size.csv and located
/Users/davidoconnor/Desktop/Eart-125/size.csv

Thank you very much!

David
--
View this message in context: 
http://n4.nabble.com/simple-data-import-of-csv-tp1835620p1835620.html

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


Two solutions:

To find the file, use file.choose()
e.g.,
my.file.name - file.choose()#and then use the normal mac tools 
to find the file

my.data - read.csv(my.file.name,header=TRUE)

or, if you want to just read it from the clipboard:

library(psych)
my.data - read.clipboard.csv()#after copying the data to the clipboard

Bill




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



--
William Revelle http://personality-project.org/revelle.html
Professor   http://personality-project.org
Department of Psychology http://www.wcas.northwestern.edu/psych/
Northwestern University http://www.northwestern.edu/
Use R for psychology   http://personality-project.org/r
It is 6 minutes to midnight http://www.thebulletin.org

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

2010-04-10 Thread li li
Hi, thanks for the reply.
   A will be a given matrix satisfying condition 1. I want to find the
vector w that minimizes the
quadratic form. w satisfies condition 2.


2010/4/10 Paul Smith phh...@gmail.com

 On Sat, Apr 10, 2010 at 5:13 PM, Paul Smith phh...@gmail.com wrote:
 I am trying to minimize the quardratic form w'Aw, with certain
  constraints.
  In particular,
 (1) A=(a_{ij}) is n by n matrix and it is symmetric positive
 definite,
 a_{ii}=1 for all i;
 and 0a_{ij}1 for i not equal j.
 (2) w'1=n;
 (3) w_{i}=0
 
  Analytically, for n=2, it is easy to come up with a result. For larger
 n, it
  seems
  difficult to obtain the result.
 
  Does any one know whether it is possible to use R to numerically compute
 it?
 
  And your decision variables are? Both w[i] and a[i,j] ?

 In addition, what do you mean by larger n? n = 20 is already large
 (in your sense)?

 Paul

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


[[alternative HTML version deleted]]

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


Re: [R] minimization function

2010-04-10 Thread Gabor Grothendieck
Check out the quadprog package.

On Sat, Apr 10, 2010 at 5:36 PM, li li hannah@gmail.com wrote:
 Hi, thanks for the reply.
   A will be a given matrix satisfying condition 1. I want to find the
 vector w that minimizes the
 quadratic form. w satisfies condition 2.


 2010/4/10 Paul Smith phh...@gmail.com

 On Sat, Apr 10, 2010 at 5:13 PM, Paul Smith phh...@gmail.com wrote:
     I am trying to minimize the quardratic form w'Aw, with certain
  constraints.
  In particular,
     (1) A=(a_{ij}) is n by n matrix and it is symmetric positive
 definite,
         a_{ii}=1 for all i;
         and 0a_{ij}1 for i not equal j.
     (2) w'1=n;
     (3) w_{i}=0
 
  Analytically, for n=2, it is easy to come up with a result. For larger
 n, it
  seems
  difficult to obtain the result.
 
  Does any one know whether it is possible to use R to numerically compute
 it?
 
  And your decision variables are? Both w[i] and a[i,j] ?

 In addition, what do you mean by larger n? n = 20 is already large
 (in your sense)?

 Paul

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


        [[alternative HTML version deleted]]

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


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

2010-04-10 Thread Martin Morgan
On 04/09/2010 08:52 AM, Peter Danenberg wrote:
 In principle, I'd like to be able to do something like this:
 
   sge.parLapply(seq(10), function(x) parLapply(seq(x), function(x) x^2))

I'm not sure that's such a good principle! It seems like it would be
hard to think about the tasks that are being executed, how many
processes there are, how load balancing works, etc. What about starting
with some complicated data structure that requires processing

  work - lapply(seq(10), function(x) as.list(seq(x)))

Then making a flat list of tasks that need to be done

  idx0 - rep(seq_along(work), sapply(work, length))
  idx1 - unlist(lapply(work, seq_along))
  tasks - mapply(c, idx0, idx1, SIMPLIFY=oFALSE)

and actually do the work in an easily parallelizable lapply

  answers - lapply(tasks, function(t, w) w[[ t ]]^2, work)

(the idea here is that work[[ c(3, 2) ]] selects the third element of
the outer list, and then the second element of that element). You could
transform the result back into the original form with

  result - work
  for (t in seq_along(tasks))
  result[[ tasks[[t]] ]] - answers[[t]]

Martin

 
 In practice, however, I have to resort to acrobatics like this:
 
   sge.options(sge.remove.files=FALSE)
   sge.options(sge.qsub.options='-cwd -V')
   sge.parLapply(seq(10),
 function(x) {
   sge.options(sge.save.global=TRUE)
   sge.options(sge.remove.files=FALSE)
   sge.parLapply(seq(x),
 function(x) x^2,
 cluster=TRUE,
 debug=FALSE,
 trace=FALSE,
 file.prefix='Rsge_data',
 global.savelist=NULL,
 packages=NULL)
 },
 function.savelist=c('sge.parLapply', 'sge.parParApply',
   'sge.options', 'sge.taskPrep'),
 global.savelist=c('sge.parParApply', 'sge.globalPrep',
   'global.savelist', 'sge.taskPrep', 'sge.checkNotNow',
   'sge.get.jobid', 'sge.get.result', 'docall',
   'enquote'),
 packages=NULL)
 
 and I still get bizarre behavior: half of the results will be NULL,
 for instance; the other half, incomplete.
 
 Would non-trivial changes to Rsge be required to make something like
 this possible?
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] fill in values between rollapply

2010-04-10 Thread Gabor Grothendieck
Here are two  solutions.  Assuming x is a zoo object both return zoo objects:

1. rollapply with na.pad and na.locf:

r - rollapply(x, 5, mean, by = 5, align = left, na.pad = TRUE)
na.locf(r)

2. or try this which does not use rollapply at all but assumes x is 1
dimensional:

   n - length(x)
   a - ave(x, gl(n, 5, n), FUN = mean)


On Fri, Apr 9, 2010 at 3:32 AM, Brad Patrick Schneid bpsch...@gmail.com wrote:

 Hi,
 Sorry ahead of time for not including data with this question.
 Using rollapply to calculate mean values for 5 day blocks, I'd use this:

 Roll5mean - rollapply(data, 5, mean, by=5, align = c(left))

 My question is, can someone tell me how to fill in the days between each of
 these means with the previously calculated mean?  If this doesn't make
 sense, I will clarify and provide data for an example.

 Thanks.
 Brad
 --
 View this message in context: 
 http://n4.nabble.com/fill-in-values-between-rollapply-tp1816885p1816885.html
 Sent from the R help mailing list archive at Nabble.com.

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


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


[R] .Call function crashes initializing matrix

2010-04-10 Thread Erik Wright
Hello,

I have a C function that I call from R using .Call.  I recently discovered a 
bug in my code, and I am not sure if it is a problem with what I am doing in C 
or if it has something to do with my use of .Call.

I have narrowed my problem down to these two C statements:
int size = 5000;
double matrix[size][size];

When I run this in R it crashes, with this message:
 *** caught segfault ***
address 0xb4141d70, cause 'memory not mapped'

It has no problem when size is smaller, like 50.  Any idea what is going on?

Thanks!,
Erik


sessionInfo()
R version 2.10.1 (2009-12-14) 
i386-apple-darwin9.8.0 

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] selecting certain columns or rows from a .csv

2010-04-10 Thread doconnor

Hello,

I'm using read.csv(filename,header=TRUE) but need to extract just certain
columns or rows from the file.

Much thanks.


-- 
View this message in context: 
http://n4.nabble.com/selecting-certain-columns-or-rows-from-a-csv-tp1835692p1835692.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] simple data import of .csv

2010-04-10 Thread doconnor

Perfect, thank you!!
-- 
View this message in context: 
http://n4.nabble.com/simple-data-import-of-csv-tp1835620p1835678.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] simple data import of .csv

2010-04-10 Thread doconnor

A related question: how do I make R return only one column or row of the .csv
file.  For example, I have about 1000 rows and three columns - can I import
only certain rows or columns, like just column 1?

Thank you!!!


-- 
View this message in context: 
http://n4.nabble.com/simple-data-import-of-csv-tp1835620p1835683.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] simple data import of .csv

2010-04-10 Thread jim holtman
For that size file, it is the easiest to read in the entire file and then
index just the portion that you want.

On Sat, Apr 10, 2010 at 5:38 PM, doconnor oconnor.davi...@gmail.com wrote:


 A related question: how do I make R return only one column or row of the
 .csv
 file.  For example, I have about 1000 rows and three columns - can I import
 only certain rows or columns, like just column 1?

 Thank you!!!


 --
 View this message in context:
 http://n4.nabble.com/simple-data-import-of-csv-tp1835620p1835683.html
  Sent from the R help mailing list archive at Nabble.com.

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




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

What is the problem that you are trying to solve?

[[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] selecting certain columns or rows from a .csv

2010-04-10 Thread jim holtman
?read.csv

colCLasses
nrows

On Sat, Apr 10, 2010 at 6:11 PM, doconnor oconnor.davi...@gmail.com wrote:


 Hello,

 I'm using read.csv(filename,header=TRUE) but need to extract just
 certain
 columns or rows from the file.

 Much thanks.


 --
 View this message in context:
 http://n4.nabble.com/selecting-certain-columns-or-rows-from-a-csv-tp1835692p1835692.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

What is the problem that you are trying to solve?

[[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] writing function (plot problem)

2010-04-10 Thread casperyc

Hi,

===
x=rnorm(20)
y=rnorm(20)
t=lm(y~x)
plot(t)
===

you will get 

click or hit enter to next page...

how do I write a function to archieve this ?

say

plot(x,y)
then pause, wait
plot(y,x)

Thanks!

casper
-- 
View this message in context: 
http://n4.nabble.com/writing-function-plot-problem-tp1835723p1835723.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] writing function (plot problem)

2010-04-10 Thread jim holtman
?devAskNewPage

On Sat, Apr 10, 2010 at 7:49 PM, casperyc caspe...@hotmail.co.uk wrote:


 Hi,

 ===
 x=rnorm(20)
 y=rnorm(20)
 t=lm(y~x)
 plot(t)
 ===

 you will get

 click or hit enter to next page...

 how do I write a function to archieve this ?

 say

 plot(x,y)
 then pause, wait
 plot(y,x)

 Thanks!

 casper
 --
 View this message in context:
 http://n4.nabble.com/writing-function-plot-problem-tp1835723p1835723.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

What is the problem that you are trying to solve?

[[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] .Call function crashes initializing matrix

2010-04-10 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Erik Wright
 Sent: Saturday, April 10, 2010 3:23 PM
 To: r help
 Subject: [R] .Call function crashes initializing matrix
 
 Hello,
 
 I have a C function that I call from R using .Call.  I 
 recently discovered a bug in my code, and I am not sure if it 
 is a problem with what I am doing in C or if it has something 
 to do with my use of .Call.
 
 I have narrowed my problem down to these two C statements:
 int size = 5000;
 double matrix[size][size];
 
 When I run this in R it crashes, with this message:
  *** caught segfault ***
 address 0xb4141d70, cause 'memory not mapped'

You may be overflowing the stack.  Allocate
the space for 'matrix' with the allocation
functions described in section 5.9 of Writing
R Extensions.  They allocate space on the 'heap',
which has much more space than the stack (where
space for 'automatic' variables is allocated).
Typical stack sizes are on the order of few
megabytes and typical heap sizes are in the gigabytes. 

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 
 It has no problem when size is smaller, like 50.  Any idea 
 what is going on?
 
 Thanks!,
 Erik
 
 
 sessionInfo()
 R version 2.10.1 (2009-12-14) 
 i386-apple-darwin9.8.0 
 
 locale:
 [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods  
 [7] base
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] plotting rpart objects, text.rpart, fancy option

2010-04-10 Thread Claudia Penaloza
I have created plots of rpart objects with the fancy option for text.rpart
(fancy creates ellipses and rectangles and labels branches with splitting
criteria). The ellipses and rectangles are supposed to interrupt the tree
lines (as seen in Therneau and Atkinson 1997, page 48, Fig. 18,
http://www.mayo.edu/hsr/techrpt/61.pdf), but they do not, even when I use
Therneau and Atkinson's code.

 plot(tree, uniform = T, branch = 0.2, compress = T, margin = 0.1)
 text(tree, all = T, use.n=T, fancy = T)

How do I interrupt the tree lines?

Thank you,
Claudia

[[alternative HTML version deleted]]

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


[R] using BLAT in r

2010-04-10 Thread Fahim Md
Does anyone know how to use BLAT(Blast-Like alignment tool) in R?
Thanks and regards.
-- 
Fahim

[[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] Expectation of E(x^1/2)

2010-04-10 Thread Haneef Anver
Hi all,


I am trying to find the expectation of x^1/2 where x~N(a,b) ( Normal with mean 
a and variance b). 
Any feedback would be highly appreciated. 

Have great day !

Haneef




  
[[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] Expectation of E(x^1/2)

2010-04-10 Thread Sunny Srivastava
Dear Haneef,
Pls see if this suits your requirement.

sim.norm = rnorm(1,mean=a,sd=sqrt(b))
mean.est = mean(sqrt(sim.norm))

Thx
S.

On Sat, Apr 10, 2010 at 9:31 PM, Haneef Anver hane...@yahoo.com wrote:

 Hi all,


 I am trying to find the expectation of x^1/2 where x~N(a,b) ( Normal with
 mean a and variance b).
 Any feedback would be highly appreciated.

 Have great day !

 Haneef





[[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] selecting certain columns or rows from a .csv

2010-04-10 Thread Fahim

dataFile = read.csv(filename.csv,header= TRUE);
#suppose u want col 1, col 9 and col 15 
col1 = 1;
col9 = 9;
col15 = 15;
modifiedDataFile1 = dataFile[,c(col1, col9, col15)];

#if u want rows from 1-100 and then 1000-5000
modifiedDataFile2 = dataFile[c(1:100, 1000:5000), ];

#If u want to select rows and col simultaneously as specified above then 
modifiedDataFile = dataFile[c(1:100, 1000:5000), c(col1, col9, col15)];

Hope this will work.

Thanks 
Fahim Mohammad 
Grad student 
CECS, Univ of Louisville 
-- 
View this message in context: 
http://n4.nabble.com/selecting-certain-columns-or-rows-from-a-csv-tp1835692p1835760.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] using BLAT in r

2010-04-10 Thread Fahim

I am trying to use blat in R. I couldn't find any package in CRAN or
bioconductor. I downloaded the windows executable from Jim Kent's (from
ucsc) webpage. I was wondering how to use/call these executables or
functions embedded in these executables. 
I am seeking for some direction or some material that addresses such
problem.
Help appreciated. 
Thanks

-Fahim Mohammad 
cecs, univ of Louisville
-- 
View this message in context: 
http://n4.nabble.com/using-BLAT-in-r-tp1835763p1835763.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] Expectation of E(x^1/2)

2010-04-10 Thread Charles C. Berry

On Sat, 10 Apr 2010, Haneef Anver wrote:


Hi all,


I am trying to find the expectation of x^1/2 where x~N(a,b) ( Normal with mean 
a and variance b).
Any feedback would be highly appreciated.


Start by constructing plots of x vs Re(sqrt(x)) and x vs Im(sqrt(x)) for 
-1  x  1. Do it by hand.


With that plot as a hint you will see how to use integrate() to find the 
answer.


See

?integrate

BTW, you can get both the real and imaginary compoenents with one call to 
integrate().


HTH,

Chuck




Have great day !

Haneef





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



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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


Re: [R] Expectation of E(x^1/2)

2010-04-10 Thread Ben Bolker
 Haneef Anver haneef9 at yahoo.com writes:

 I am trying to find the expectation of x^1/2 where x~N(a,b) 
 ( Normal with mean a and variance b). 
 Any feedback would be highly appreciated. 

  I have no idea at the moment how to start doing
this analytically, but is this at all helpful?

 mean(sqrt(complex(re=rnorm(100
[1] 0.4114712+0.4103866i

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Expectation of E(x^1/2)

2010-04-10 Thread Ravi Varadhan
Chuck showed how to do this:

fn - function(x) sqrt(x) * dnorm(x)

 integrate(fn, 0, Inf)
0.4110895 with absolute error  4.7e-05


So the (almost) exact answer is  0.4110895 + 1i * 0.4110895 

Ravi.


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

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


- Original Message -
From: Ben Bolker bol...@ufl.edu
Date: Sunday, April 11, 2010 1:00 am
Subject: Re: [R] Expectation of E(x^1/2)
To: r-h...@stat.math.ethz.ch


  Haneef Anver haneef9 at yahoo.com writes:
  
   I am trying to find the expectation of x^1/2 where x~N(a,b) 
   ( Normal with mean a and variance b). 
   Any feedback would be highly appreciated. 
  
I have no idea at the moment how to start doing
  this analytically, but is this at all helpful?
  
   mean(sqrt(complex(re=rnorm(100
  [1] 0.4114712+0.4103866i
  
  __
  R-help@r-project.org mailing list
  
  PLEASE do read the posting guide 
  and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Expectation of E(x^1/2)

2010-04-10 Thread Ben Bolker
  And Mathematica says

In[2]:= 1/Sqrt[2 Pi] Integrate[Exp[-x^2/2] Sqrt[x],{x,0,Infinity}]

3
  Gamma[-]
4
Out[2]= -
 3/4
2Sqrt[Pi]

(I suppose there's probably a change-of-variables trick to do this ...)

in R:

 gamma(3/4)/(2^(3/4)*sqrt(pi))
[1] 0.4110895


Ravi Varadhan wrote:
 Chuck showed how to do this:
 
 fn - function(x) sqrt(x) * dnorm(x)
 
 integrate(fn, 0, Inf)
 0.4110895 with absolute error  4.7e-05
 
 So the (almost) exact answer is  0.4110895 + 1i * 0.4110895 


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