[R] Splitting lines in R script

2015-08-02 Thread Steven Yen
I have a line containing summation of four components.

# This works OK:
  p-pbivnorm(bb,dd,tau)+pbivnorm(aa,cc,tau)-
-pbivnorm(aa,dd,tau)-pbivnorm(bb,cc,tau)

# This produces unpredicted results without warning:
  p-pbivnorm(bb,dd,tau)+pbivnorm(aa,cc,tau)
-pbivnorm(aa,dd,tau)-pbivnorm(bb,cc,tau)

Is there a general rule of thumb for line breaks? Thanks you.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Splitting lines in R script

2015-08-02 Thread Peter Langfelder
R does not need a semicolon or other character to terminate a command;
if a line can be interpreted as a complete command, it will (first
line in your second example).

Also note that the first example may not produce what you want (if
your second example is any indication) - the result of
pbivnorm(aa,dd,tau) is added to the sum of the first two terms,
because the two minuses give a plus:

 1- -1
[1] 2

Peter

On Sun, Aug 2, 2015 at 9:05 PM, Steven Yen sye...@gmail.com wrote:
 I have a line containing summation of four components.

 # This works OK:
   p-pbivnorm(bb,dd,tau)+pbivnorm(aa,cc,tau)-
 -pbivnorm(aa,dd,tau)-pbivnorm(bb,cc,tau)

 # This produces unpredicted results without warning:
   p-pbivnorm(bb,dd,tau)+pbivnorm(aa,cc,tau)
 -pbivnorm(aa,dd,tau)-pbivnorm(bb,cc,tau)

 Is there a general rule of thumb for line breaks? Thanks you.

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] vectorized sub, gsub, grep, etc.

2015-08-02 Thread John Thaden
Adam,
The original posting gave a function sub2 whose aim differs both from your 
functions' aim and from the intent of mgsub() in the qdap package:
 Here is code to apply a different 
 pattern and replacement for every target.#Example
X - c(ab, cd, ef)
patt - c(b, cd, a)
repl - c(B, CD, A)
The first pattern ('b') and the first replacement ('B') therefore apply only to 
the first target ('ab'), the second to the second, etc. The function achieves 
its aim, giving the correct answer 'aB', 'CD', 'ef'.

mgsub() satisfies a different need, testing all targets for matches with any 
pattern in the vector of patterns and, if a match is found, replacing the 
matched target with the replacement value corresponding to the matched pattern. 
It, too, achieves its aim, giving a different (but also correct) answer 'AB', 
'CD', 'ef'.
Regards,-John
#Example
X - c(ab, cd, ef)
patt - c(b, cd, a)
repl - c(B, CD, A)

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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-es] ayuda con análisis de supervivencia

2015-08-02 Thread Javier Rubén Marcuzzi
Estimado José Miguel Arbones

Leí su solicitud respecto a un análisis de (Survival) donde quiere medir el 
efecto de dos genotipos en la aparición de un síndrome metabólico. Usted 
también pregunta sobre si estadísticamente sería apropiado ese enfoque.

Leí algo de sobrevida en genética, pero su problema desde mi punto de vista es 
de genética cuantitativa, ¿en que cuantificación tiene que ver el genotipo 
respecto a la medición del síndrome metabólico? Usted habla de genotipo, este 
puede ser homocigota, heterocigota, pero en la gametogénesis solo se heredan 
genes, no genotipos, por lo cuál ¿hay un efecto entre los genes iguales?. En 
otras palabras, efecto aditivo del gen, epistasis, dominancia, etc.

No es justo lenguaje R pero hay un libro en español de Falconer, introducción a 
la genética cuantitativa, luego hay algunos (muchos) paquetes par estos temas 
en R, pero sobrevida sin mezclar algo de terminología de genética cuantitativa, 
a mi me resulta extraño. Por otro lado como usted tiene mediciónes a lo largo 
del tiempo, no hay nada que diga que los efectos del gen son los mismos todo el 
tiempo, si emplea modelos de regresiones aleatorios puede observar que el 
efecto cuantitativo del gen varía, sospecho que el síndrome metabólico puede 
ser observado por ejemplo en el peso, pero este no depende de un gen, hay un 
efecto de muchos genes menores, aunque el que usted quiere analizar puede ser 
un gen mayor (no lo se).

Por lo que usted comenta yo iría sobre el paquete MCMCglmm, posiblemente en los 
ejemplos hay algo que intermedia entre lo que usted plantea, R, y lo que yo 
pienso.

Javier Rubén Marcuzzi
Técnico en Industria Lácteas
Veterinario



De: JM ARBONES
Enviado: domingo, 2 de agosto de 2015 2:19 p. m.
Para: r-help-es@r-project.org
Asunto: [R-es] ayuda con análisis de supervivencia


Hola a todos,
-Estoy estudiando el efecto de dos genotipos (~tratamientos) en la aparición de 
síndrome metabólico (MetS) con datos longitudinales recogidos a tiempo 
0,7,10,15,20 y 25 años.

-He hecho un dataframe con las siguientes variables
MetS: Síndrome Metabólico (Si=1,No=0)
bmi: Indice de masa corporal (IMC) cuando se produce la conversión a MetS+ . 
Para los que permancen MetS-, esta variable indica el bmi cuando hay censura 
(por abandono del estudio o al finalizar el estudio en el año 25).
bmi0: IMC al inicio del estudio (categórica, levels=normal/overweight/obese)
apoE4: Genotipo de interés (E4, no-E4)

-Mi hipótesis es que la interacción genotipo~MetS depende del IMC al principio 
del estudio. Concretamente, individuos 'overweight' al inicio del estudio y con 
el genotipo E4 hacen la conversión a MetS+ a valores de IMC mas bajos que los 
que tienen el genotipo no-E4. Este fenómeno no ocurriría en los 'normal' y 
'obese'.

-He creado unos objetos Surv, pero en lugar de utilizar el tiempo hasta evento 
(MetS+) estoy utilizando el bmi hasta el evento. Las gráficas que resultan al 
hacer el análisis de supervivencia parecerían confirmar mi hipótesis, pero no 
se si lo que estoy haciendo es una aberración estadística. Tampoco se si los 
coeficientes de la regresión de Cox tienen sentido al no utilizar la variable 
tiempo.

?Alguien me podría 1)decir si lo que estoy haciendo tiene sentido y 2) como 
interpretar los resultados (regresión de Cox y gráficas)?
Si a alguien se anima a contestar, adjunto un link con los datos (.Rdata) y el 
script que he utilizado en el análisis.


https://www.dropbox.com/s/d96itird8ms42yx/dataframe.Rdata?dl=0 
https://www.dropbox.com/s/d96itird8ms42yx/dataframe.Rdata?dl=0

sapply(levels(df0$bmi0),function (x){ #SURVIVAL CURVE
  dfx=filter(df0,bmi0==x)
  
  surv2=Surv(dfx$bmi,dfx$MetS)
  km2=survfit(surv2~dfx$apoe4)##start.time=20,type='kaplan')
  plot(km2,lty=2:1,xlim=c(20,41),xlab='BMI at onset',main=x,mark.time = F)
  legend('bottomleft',c('E4','no-E4'),lty=2:1)
  cox=list(coxph(surv2~relevel(dfx$apoe4,ref='no-E4')))
})

sapply(levels(df0$bmi0),function (x){ #CUMULATIVE HAZARDs
  dfx=filter(df0,bmi0==x)
  
  surv2=Surv(dfx$bmi,dfx$MetS)
  km2=survfit(surv2~dfx$apoe4)
  plot(km2,lty=2:1,xlim=c(20,41),xlab='BMI at onset',main=x,mark.time = 
F,fun='cumhaz')
  legend('topleft',c('E4','no-E4'),lty=2:1)
  
})

Muchas gracias y un saludo

Jose Miguel

---

Jose Miguel Arbones-Mainar, PhD
Unidad de Investigación Traslacional 
Instituto Aragones de Ciencias de la Salud 
Hospital Universitario Miguel Servet 
Pº Isabel la Católica, 1-3 
50009 Zaragoza (Spain) 
Tel: +34 976 769 565
Fax: +34 976 769 566 
www.adipofat.com http://www.adipofat.com/




---
Jose Miguel Arbones-Mainar
www.adipofat.com http://www.adipofat.com/







[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es



[[alternative 

Re: [R] Error when compiling R-2.5.1 / *** [d-p-q-r-tests.Rout] Fehler 1

2015-08-02 Thread Joerg Kirschner
Dear Martin,
thanks for the advice, I'll check out Bioconductor.

Meanwhile I reinstalled Ubuntu, this time as 64-bit and the error is gone :
)

Rgds, Joerg

On Sat, Aug 1, 2015 at 8:16 PM, Martin Morgan mtmor...@fredhutch.org
wrote:

 On 07/31/2015 10:48 PM, Joerg Kirschner wrote:

 Hi everyone,
 I am new to Linux and R - but I managed to build R-2.5.1 from source to
 use
 it in Genepattern. Genepattern does only support R-2.5.1 which I could not
 find anywhere for installation via apt-get or in the Ubuntu
 Software-Centre
 (I am using Ubuntu 14.04 (Trusty Tahr) 32-bit)


 Are you sure you want to do this? R 2.5.1 is from 2007, which is a very
 long time ago. It seems like GenePattern is not restricted to R-2.5.1,



 http://www.broadinstitute.org/cancer/software/genepattern/administrators-guide#using-different-versions-of-r

 and if their default distribution uses it, then I'm not sure I'd recommend
 using GenePattern for new analysis! (Maybe you're trying to re-do a
 previous analysis?)

 Since GenePattern modules that use R typically wrap individual CRAN or
 Bioconductor (http://bioconductor.org) packages, maybe you can take out
 the middleman ?

 Martin Morgan


 But after doing

 make check


 I get

 comparing 'method-dispatch.Rout' to './method-dispatch.Rout.save' ... OK
 running code in 'd-p-q-r-tests.R' ...make[3]: *** [d-p-q-r-tests.Rout]
 Fehler 1
 make[3]: Verzeichnis »/home/karin/Downloads/R-2.5.1/tests« wird verlassen
 make[2]: *** [test-Specific] Fehler 2
 make[2]: Verzeichnis »/home/karin/Downloads/R-2.5.1/tests« wird verlassen
 make[1]: *** [test-all-basics] Fehler 1
 make[1]: Verzeichnis »/home/karin/Downloads/R-2.5.1/tests« wird verlassen
 make: *** [check] Fehler 2


 but I can make install and use R for simple plots etc. afterwards - still
 I
 am worried something is wrong, can you give some advice.

 A closer look at the error gives

 ## PR#7099 : pf() with large df1 or df2:
 nu - 2^seq(25,34, 0.5)
 y - 1e9*(pf(1,1,nu) - 0.68268949)
 stopifnot(All.eq(pf(1,1,Inf), 0.68268949213708596),

 +   diff(y)  0, # i.e. pf(1,1, *) is monotone increasing
 +   All.eq(y [1], -5.07420372386491),
 +   All.eq(y[19],  2.12300110824515))
 Error: All.eq(y[1], -5.07420372386491) is not TRUE
 Execution halted


 As I understand so far some errors are critical some are not - can you
 please give some advice on the error above? Can I still use R installed
 with that error? What do I need to solve the error?

 Thanks, Joerg

 [[alternative HTML version deleted]]

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



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


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] NATURAL Smoothing B-splines

2015-08-02 Thread Marc Lamblin
Hi all,

I'm an engineering student from Politecnico di Milano.
I want to perform Smoothing using Smoothing B-splines on syntethic
data. The splines must be NATURAL (at the edges the second and third
order derivates are zero).
How can I impose this constraint?
I have searched in R documentation. For Smoothing I use the fda
package. From the description of the function smooth.basis() it seems
that it is not possible to use natural B-splines. I have found only
the function ns() from splines package but in this way you can obtain
only the basis and I have seen that this function is used in models
expressed in symbolic notation.

Thanks in advance!!

mggl

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] NATURAL Smoothing B-splines

2015-08-02 Thread Spencer Graves

 library(sos)
 ns. - findFn('natural spline')
found 191 matches;  retrieving 10 pages
2 3 4 5 6 7 8 9 10
Downloaded 113 links in 70 packages.
 ns2 - findFn('natural splines')
found 145 matches;  retrieving 8 pages
2 3 4 5 6 7 8
Downloaded 70 links in 42 packages.
 ns2. - ns.|ns2
 ns2.

# This displayed a table of 137 different help pages sorted to place the 
package with the most matches first.


 findFn2xls(ns2.) # writes a file with a name like nls2..xls to the 
working directory [getwd()]

# with a sheet giving a summary by package.


  Hope this helps.
  Spencer


On 8/2/2015 10:10 AM, Marc Lamblin wrote:

Hi all,

I'm an engineering student from Politecnico di Milano.
I want to perform Smoothing using Smoothing B-splines on syntethic
data. The splines must be NATURAL (at the edges the second and third
order derivates are zero).
How can I impose this constraint?
I have searched in R documentation. For Smoothing I use the fda
package. From the description of the function smooth.basis() it seems
that it is not possible to use natural B-splines. I have found only
the function ns() from splines package but in this way you can obtain
only the basis and I have seen that this function is used in models
expressed in symbolic notation.

Thanks in advance!!

mggl

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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-es] ayuda con análisis de supervivencia

2015-08-02 Thread JM ARBONES
Hola a todos,
-Estoy estudiando el efecto de dos genotipos (~tratamientos) en la aparición de 
síndrome metabólico (MetS) con datos longitudinales recogidos a tiempo 
0,7,10,15,20 y 25 años.

-He hecho un dataframe con las siguientes variables
MetS: Síndrome Metabólico (Si=1,No=0)
bmi: Indice de masa corporal (IMC) cuando se produce la conversión a MetS+ . 
Para los que permancen MetS-, esta variable indica el bmi cuando hay censura 
(por abandono del estudio o al finalizar el estudio en el año 25).
bmi0: IMC al inicio del estudio (categórica, levels=normal/overweight/obese)
apoE4: Genotipo de interés (E4, no-E4)

-Mi hipótesis es que la interacción genotipo~MetS depende del IMC al principio 
del estudio. Concretamente, individuos 'overweight' al inicio del estudio y con 
el genotipo E4 hacen la conversión a MetS+ a valores de IMC mas bajos que los 
que tienen el genotipo no-E4. Este fenómeno no ocurriría en los 'normal' y 
'obese'.

-He creado unos objetos Surv, pero en lugar de utilizar el tiempo hasta evento 
(MetS+) estoy utilizando el bmi hasta el evento. Las gráficas que resultan al 
hacer el análisis de supervivencia parecerían confirmar mi hipótesis, pero no 
se si lo que estoy haciendo es una aberración estadística. Tampoco se si los 
coeficientes de la regresión de Cox tienen sentido al no utilizar la variable 
tiempo.

?Alguien me podría 1)decir si lo que estoy haciendo tiene sentido y 2) como 
interpretar los resultados (regresión de Cox y gráficas)?
Si a alguien se anima a contestar, adjunto un link con los datos (.Rdata) y el 
script que he utilizado en el análisis.


https://www.dropbox.com/s/d96itird8ms42yx/dataframe.Rdata?dl=0 
https://www.dropbox.com/s/d96itird8ms42yx/dataframe.Rdata?dl=0

sapply(levels(df0$bmi0),function (x){ #SURVIVAL CURVE
  dfx=filter(df0,bmi0==x)
  
  surv2=Surv(dfx$bmi,dfx$MetS)
  km2=survfit(surv2~dfx$apoe4)##start.time=20,type='kaplan')
  plot(km2,lty=2:1,xlim=c(20,41),xlab='BMI at onset',main=x,mark.time = F)
  legend('bottomleft',c('E4','no-E4'),lty=2:1)
  cox=list(coxph(surv2~relevel(dfx$apoe4,ref='no-E4')))
})

sapply(levels(df0$bmi0),function (x){ #CUMULATIVE HAZARDs
  dfx=filter(df0,bmi0==x)
  
  surv2=Surv(dfx$bmi,dfx$MetS)
  km2=survfit(surv2~dfx$apoe4)
  plot(km2,lty=2:1,xlim=c(20,41),xlab='BMI at onset',main=x,mark.time = 
F,fun='cumhaz')
  legend('topleft',c('E4','no-E4'),lty=2:1)
  
})

Muchas gracias y un saludo

Jose Miguel

---

Jose Miguel Arbones-Mainar, PhD
Unidad de Investigación Traslacional 
Instituto Aragones de Ciencias de la Salud 
Hospital Universitario Miguel Servet 
Pº Isabel la Católica, 1-3 
50009 Zaragoza (Spain) 
Tel: +34 976 769 565
Fax: +34 976 769 566 
www.adipofat.com http://www.adipofat.com/




---
Jose Miguel Arbones-Mainar
www.adipofat.com http://www.adipofat.com/







[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] PythonInR. Python script in R with parameters required. Download satellite images from NASA

2015-08-02 Thread Florian Schwendinger

I believe the Problem is that you trying to give command line arguments
pyExecfile(myPythonScript.py) and pyExecfile only expects to get a 
filename.



In Pyhton27 pyExecfile only runs the Python command execfile on the 
given filename. So the Problem is that in


pyExecfile(C:/Landsat/download_espa_order.py -e magifranqu...@gmail.com
-o magifranqu...@gmail.com-07222015-120911 -d C:/Landsat/ESPA)

your not only providing a file name but also command line arguments.


It is maybe easier for you to use the command line. Something like the 
following should work


python - C:/Python27/python.exe
pyScript - C:/Landsat/download_espa_order.py
email - yourem...@gmail.com
order - yourem...@gmail.com-order-number
targetDirectory - C:/Landsat/ESPA
pyArgs - sprintf(--email %s --order %s --target_directory %s,
  email, order, targetDirectory)
pyArgs
cmd - sprintf(%s %s %s, python, pyScript, pyArgs)
cmd
system(cmd ,wait=FALSE)

or

system(C:/Python27/python.exe C:/Landsat/download_espa_order.py --email 
magifranqu...@gmail.com --order magifranqu...@gmail.com-07222015-120911 
--target_directory C:/Landsat/ESPA, wait=FALSE)



If you want to use PythonInR you could something like the following.
pyConnect(pythonExePath=python)
setwd(C:/Landsat/)
pyExec(import download_espa_order)
pySet(email, email)
pySet(order, order)
pyGet([scene for scene in SceneFeed(email).get_items(order)])


Florian


On 07/29/2015 06:29 PM, Magi Franquesa wrote:

Hello,

I'm trying to execute a python script within R (3.2.1 x 64) with the
PythonInR package. I would like to download an order of satellite images
from Nasa using a python script (
http://landsat.usgs.gov/documents/espa_bulk_downloader_v1.0.0.zip) but I
have no success. I first run the pyExecfile command with the *feedparser.py*
script and then the *download_espa_order.py* giving the required parameters
(my mail acount and the order number), here is the code:

setwd(C:/Python27)
install.packages(PythonInR)
library(PythonInR)
pyConnect(pythonExePath=C:/Python27/python.exe)
pyIsConnected()
# autodetectPython(C:/Python27/python.exe)

pyExecfile(C:/Landsat/feedparser.py)
pyExecfile(C:/Landsat/download_espa_order.py -e magifranqu...@gmail.com
-o magifranqu...@gmail.com-07222015-120911 -d C:/Landsat/ESPA)

and I get this error:

Error: unexpected string constant in
pyExecfile(C:/Landsat/download_espa_order.py -e
magifranqu...@gmail.com

The code C:/Landsat/download_espa_order.py -e
magifranqu...@gmail.com -o magifranqu...@gmail.com-07222015-120911
-d C:/Landsat/ESPA runs ok when I use it within
system console.

I appreciate if someone could help me to solve this problem.

Thank you

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.