Re: [R] Script/function/procedure with loop

2016-07-11 Thread Luca Meyer
Thanks Sarah,

The code works just fine.

Luca

2016-07-11 22:43 GMT+02:00 Sarah Goslee :

> Taking your question at face value, except for the factors in your
> original data frame, you can output anything you'd like to text
> onscreen using cat(). Output can also be saved to text files with
> sink() or using batch files, etc and so forth.
>
>
>
> date <-
> c("07-jul-16","07-jul-16","07-jul-16","08-jul-16","08-jul-16","08-jul-16","09-jul-16","09-jul-16")
> varA <- c("text A1","text A2","text A3","text A4","text A5","text
> A6","text A7","text A8")
> varB <- c("link B1","link B2","link B3","link B4","link B5","link
> B6","link B7","link B8")
> mydf <- data.frame(date, varA, varB, stringsAsFactors=FALSE)
>
> for(i in sort(unique(mydf$date))) {
>   thisdate <- subset(mydf, date==i)
>   cat(i, "\n\n")
>   for(j in seq_len(nrow(thisdate))) {
> cat(thisdate$varA[j], "\n")
> cat(thisdate$varB[j], "\n\n")
>  }
> }
>
> This code prints to screen:
>
> 07-jul-16
>
> text A1
> link B1
>
> text A2
> link B2
>
> text A3
> link B3
>
> 08-jul-16
>
> text A4
> link B4
>
> text A5
> link B5
>
> text A6
> link B6
>
> 09-jul-16
>
> text A7
> link B7
>
> text A8
> link B8
>
>
> On Mon, Jul 11, 2016 at 4:24 PM, Luca Meyer  wrote:
> > Can anyone point me to an R script/function/procedure which, starting
> from
> > the following sample data
> >
> > #sample data
> > #NB: nrow(df) is variable
> >
> > date =
> >
> c("07-jul-16","07-jul-16","07-jul-16","08-jul-16","08-jul-16","08-jul-16","09-jul-16","09-jul-16")
> > varA = c("text A1","text A2","text A3","text A4","text A5","text
> A6","text
> > A7","text A8")
> > varB = c("link B1","link B2","link B3","link B4","link B5","link
> B6","link
> > B7","link B8")
> > df = data.frame(date, varA, varB)
> >
> > allows me to obtain a text output such as:
> >
> >> 07-jul-16
> >
> > text A1
> > link B1
> >
> > text A2
> > link B2
> >
> > text A3
> > link B3
> >
> >> 08-jul-16
> >
> > text A4
> > link B4
> >
> > text A5
> > link B5
> >
> > text A6
> > link B6
> >
> >> 09-jul-16
> >
> > text A7
> > link B7
> >
> > text A8
> > link B8
> >
> > etc...
> >
> > Thanks,
> >
> > Luca
> >
> > [[alternative HTML version deleted]]
>
> Please post in plain text.
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>

[[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] Is there a way to coerce ggplot into using min & max values for x & y axes?

2016-07-11 Thread Ulrik Stervbo
Hi Ken,

You can use coord_cartesian() to set axis. Or if it makes sense to your
problem you can facet your plot.

Hope this helps
Ulrik

KMNanus  schrieb am Di., 12. Juli 2016 01:35:

> I’m plotting few dozen variables, doing so because I need to examine them
> one at a time.  The range of these variables varies widely.  One can range
> from -.5 to .03, another from -600 to +750.
>
> I want both axes to automatically plot from both min and max values for
> both continuous variables.
>
> I’ve tried  - stat_summary(fun.ymax=max, fun.ymin=min), but it doesn’t
> plot to the min and max values.
>
> This code neither plots to the min/max nor does it create tick marks on
> either axis - scale_y_continuous(breaks = c(min(b12.2$myvar), 0,
> max(b12.2$myvar)))
>
> Has anyone faced this situation before?  I appreciate the help.
>
> Ken
> kmna...@gmail.com
> 914-450-0816 (tel)
> 347-730-4813 (fax)
>
>
>
> __
> 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.

[[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] Is there a way to coerce ggplot into using min & max values for x & y axes?

2016-07-11 Thread KMNanus
I’m plotting few dozen variables, doing so because I need to examine them one 
at a time.  The range of these variables varies widely.  One can range from -.5 
to .03, another from -600 to +750.

I want both axes to automatically plot from both min and max values for both 
continuous variables.  

I’ve tried  - stat_summary(fun.ymax=max, fun.ymin=min), but it doesn’t plot to 
the min and max values.

This code neither plots to the min/max nor does it create tick marks on either 
axis - scale_y_continuous(breaks = c(min(b12.2$myvar), 0, max(b12.2$myvar)))

Has anyone faced this situation before?  I appreciate the help.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] Red Neuronal complicada categorías

2016-07-11 Thread Javier Marcuzzi
Estimado Carlos Ortega

Gracias, ahora comprendo porqué me la envió, no se si justo es la causa pero 
puede ser, hace dos o tres días una red no produjo resultados, la corrí otra 
vez y funcionó, es posible que por casualidad el valor para iniciar un número 
aleatorio justo no dio convergencia en algún punto del algoritmo, y falló en 
una corrida.

Es posible que la librería que usted utilizó, requiera un código mucho más 
simple y claro que el que yo pensé, la codificación podría ser interna dentro 
de la librería y no preocuparme en pasar a binario casi a mano

Nuevamente gracias.

Javier Rubén Marcuzzi

De: Carlos Ortega
[[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] use value in variable to be name of another variable

2016-07-11 Thread William Dunlap via R-help
I find that instead of using assign() and get(), it is more convenient to
make
an environment in which to store a related set of variables and
then use env[[varName]] instead of get(varName) or assign(varName)
to get and set variables.

The advantages are
* the same syntax works for setting and getting, unlike assign() and get()
* nested replacements work
* you don't accidently overwrite things in the current environment

You can use the same syntax with a list instead of an environment.

E.g.,

geneNames <- c("AT1", "AT2", "PQ1")
envAction <- new.env(parent=emptyenv())
envAction[[ geneNames[2] ]] <- paste("Action for", geneNames[[2]])
names(envAction)
envAction[[ geneNames[2] ]]
envAction[[ geneNames[2] ]] [2] <- "another action" # nested replacement
envAction[[ geneNames[2] ]]



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Jul 11, 2016 at 3:13 PM, Matthew 
wrote:

> Hi Jim,
>
>Wow ! And it does exactly what I was looking for.  Thank you very much.
>
> That assign function is pretty nice. I should become more familiar with it.
>
> Matthew
>
>
> On 7/11/2016 5:59 PM, Jim Lemon wrote:
>
>> Hi Matthew,
>> This question is a bit mysterious as we don't know what the object
>> "chr" is. However, have a look at this and see if it is close to what
>> you want to do.
>>
>> # set up a little matrix of character values
>> tTargTFS<-matrix(paste("A",rep(1:4,each=4),"B",rep(1:4,4),sep=""),ncol=4)
>> # try the assignment on the first row and column
>> assign(tTargTFS[1,1],tTargTFS[-1,1])
>> # see what it looks like - okay
>> A1B1
>> # run the assignment over the matrix
>> for(i in 1:4) assign(tTargTFS[1,i],tTargTFS[-1,i])
>> # see what the variables look like
>> A1B1
>> A2B1
>> A3B1
>> A4B1
>>
>> It does what I would expect.
>>
>> Jim
>>
>>
>> On Tue, Jul 12, 2016 at 6:01 AM, Matthew
>>  wrote:
>>
>>> I want to get a value that has been assigned to a variable, and then use
>>> that value to be the name of a variable.
>>>
>>> For example,
>>>
>>> tTargTFS[1,1]
>>> # returns:
>>>  V1
>>> "AT1G01010"
>>>
>>> Now, I want to make AT1G01010 the name of a variable:
>>> AT1G01010 <- tTargTFS[-1,1]
>>>
>>> Then, go to the next tTargTFS[1,2]. Which produces
>>> V1
>>> "AT1G01030"
>>> And then,
>>> AT1G01030 <- tTargTFS[-1,2]
>>>
>>> I want to do this up to tTargTFS[1, 2666], so I want to do this in a
>>> script
>>> and not manually.
>>> tTargTFS is a list of 2: chr [1:265, 1:2666], but I also have the data
>>> in a
>>> data frame of 265 observations of 2666 variables, if this data structure
>>> makes things easier.
>>>
>>> My initial attempts are not working. Starting with a test data structure
>>> that is a little simpler I have tried:
>>> for (i in 1:4)
>>> { ATG <- tTargTFS[1, i]
>>> assign(cat(ATG), tTargTFS[-1, i]) }
>>>
>>> Matthew
>>>
>>> __
>>> 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.
>

[[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] [R-pkgs] archivist.github 0.2.1 on CRAN - Task View: Reproducible Research

2016-07-11 Thread David Winsemius

> On Jun 26, 2016, at 3:16 PM, Marcin Kosiński  wrote:
> 
> Hi all R devs,
> 
> archivist.github has appeared on CRAN in it's updated version.
> You can check the last blog post on how has RHero saved the Backup City
> with the power or archivist and GitHub
> http://www.r-bloggers.com/r-hero-saves-backup-city-with-archivist-and-github/
> 
> There is also going to be a talk on useR2016 about it's core dependency -
> archivist
> 
> How to use the archivist package to boost reproducibility of your research
> 
> 
> 
> 
> If you would like to boost your reproducible engines then this is a talk
> for you :)

This is a link to a video of the talk:

https://channel9.msdn.com/Events/useR-international-R-User-conference/useR2016/How-to-use-the-archivist-package-to-boost-reproducibility-of-your-research

-- 

David Winsemius
Alameda, CA, USA

__
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] use value in variable to be name of another variable

2016-07-11 Thread Matthew

Hi Rolf,

Thanks for the warning. I think because my initial efforts used the 
assign function, that Jim provided his solution using it.


Any suggestions for how it could be done without assign() ?

Matthew

On 7/11/2016 6:31 PM, Rolf Turner wrote:

On 12/07/16 10:13, Matthew wrote:

Hi Jim,

   Wow ! And it does exactly what I was looking for.  Thank you very 
much.


That assign function is pretty nice. I should become more familiar 
with it.


Indeed you should, and assign() is indeed nice and useful and handy. 
But it should be used with care and circumspection.  It *alters the 
global environment* which is fraught with peril. Generally speaking 
most things that can be done with assign() (and its companion function 
get()) are better and more safely done using lists and functions and 
other "natural" R-ish constructs. Resist the temptation to turn R into 
a macro language.


cheers,

Rolf Turner



__
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] use value in variable to be name of another variable

2016-07-11 Thread Rolf Turner

On 12/07/16 10:13, Matthew wrote:

Hi Jim,

   Wow ! And it does exactly what I was looking for.  Thank you very much.

That assign function is pretty nice. I should become more familiar with it.


Indeed you should, and assign() is indeed nice and useful and handy. 
But it should be used with care and circumspection.  It *alters the 
global environment* which is fraught with peril.  Generally speaking 
most things that can be done with assign() (and its companion function 
get()) are better and more safely done using lists and functions and 
other "natural" R-ish constructs.  Resist the temptation to turn R into 
a macro language.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] use value in variable to be name of another variable

2016-07-11 Thread David Winsemius

> On Jul 11, 2016, at 1:01 PM, Matthew  wrote:
> 
> I want to get a value that has been assigned to a variable, and then use that 
> value to be the name of a variable.
> 
> For example,
> 
> tTargTFS[1,1]
> # returns:
>V1
> "AT1G01010"
> 
> Now, I want to make AT1G01010 the name of a variable:
> AT1G01010 <- tTargTFS[-1,1]
> 
> Then, go to the next tTargTFS[1,2]. Which produces
>   V1
> "AT1G01030"
> And then,
> AT1G01030 <- tTargTFS[-1,2]
> 
> I want to do this up to tTargTFS[1, 2666], so I want to do this in a script 
> and not manually.
> tTargTFS is a list of 2: chr [1:265, 1:2666], but I also have the data in a 
> data frame of 265 observations of 2666 variables, if this data structure 
> makes things easier.
> 
> My initial attempts are not working. Starting with a test data structure that 
> is a little simpler I have tried:
> for (i in 1:4)
> { ATG <- tTargTFS[1, i]
> assign(cat(ATG), tTargTFS[-1, i]) }

Your efforts will come to naught (or more prezactly...  NULL) when you use 
`cat` as a value. You are essentially doing the R equivalent of answering the 
question about the sound of one hand clapping.

-- 

David Winsemius
Alameda, CA, USA

__
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] Red Neuronal complicada categorías

2016-07-11 Thread Carlos Ortega
Hola Javier,

Las redes como otros muchos algoritmos utilizan valores aleatorios para
inicializar variables, pesos, etc.

Incluir un valor fijo de la semilla que genera estos números aleatorios es
una forma de poder garantizar que los resultados se van a poder repetir. De
esta forma, el resultado que yo obtengo será el mismo que tú obtienes.

El valor que he utilizado es completamente inventado.

Además de que permita reproducir resultados, también puedes variar su valor
y sin realizar ninguna modificación ni en los datos de entrada, ni en otros
parámetros tu algoritmo obtendrá diferentes valores de precisión cuando
aplicas tu modelo a un mismo conjunto de pruebas. Las variaciones son
pequeñas, pero en algunos casos lo suficientemente importantes como mejorar
tu predicción en un 1-3%...

Saludos,
Carlos Ortega
www.qualityexcellence.es


El 11 de julio de 2016, 16:39, Javier Marcuzzi <
javier.ruben.marcu...@gmail.com> escribió:

> Estimado Carlos Ortega
>
>
>
> Muchas gracias por su ayuda.
>
>
>
> Tendré que estudiar RNNS, vi muy rápido el manual y parece interesante.
>
>
>
> Le consulto, usted genera un valor al azar a partir de 432, código
> set.seed(432)
>
>
>
> ¿432?, ¿lo calcula?, ¿es por experiencia?, si bien los datos son
> inventados y el resultado por más que matemáticamente de cualquier cosa me
> sirve para resolver mi pregunta, me gustaría conocer el motivo del uso de
> este comando, puesto que corrí el mismo código sin set.seed(432) y también
> funciona (la computadora no indica que falte un parámetro o problema
> alguno).
>
>
>
> Javier Rubén Marcuzzi
>
>
>
> *De: *Carlos Ortega 
> *Enviado: *sábado, 9 de julio de 2016 18:44
> *Para: *Javier Marcuzzi 
> *CC: *r-help-es@r-project.org
> *Asunto: *Re: [R-es] Red Neuronal complicada categorías
>
>
>
> Hola,
>
>
>
> Esta es una forma de hacerlo...
>
>
>
> Mira que lo primero que he modificado es el fichero "x.csv" para sustituir
> los espacios en los nombres por "_". Y también he quitado los acentos y las
> eñes...
>
>
>
> He utilizado el paquete RNNS y la función "mlp()" para ajustar la red.
>
>
>
> #---
>
> > x <- read.csv("x.csv", header=FALSE, sep=";")
>
> > x
>
>   V1  V2V3  V4 V5   V6
>
> 1 puerta ventana techo comedor pileta  casa_grande
>
> 2 puerta ventana techo comedor  casa_comun
>
> 3 puerta ventana techocasa_pequena
>
> 4ventana techo pileta  casa_grande
>
> 5  pileta  casa_grande
>
> 6 puerta techo comedor  casa_comun
>
> 7techocasa_pequena
>
> 8 porton ventana techo  cocina pileta  casa_grande
>
> >
>
> #---
>
>
>
>
>
> V1Binario <- model.matrix(~ factor(x$V1) - 1)
>
> V2Binario <- model.matrix(~ factor(x$V2) - 1)
>
> V3Binario <- model.matrix(~ factor(x$V3) - 1)
>
> V4Binario <- model.matrix(~ factor(x$V4) - 1)
>
> V5Binario <- model.matrix(~ factor(x$V5) - 1)
>
> V6Binario <- model.matrix(~ factor(x$V6) - 1)
>
>
>
> x_new <- cbind(V1Binario,V2Binario)
>
> x_new <- cbind(x_new,V3Binario)
>
> x_new <- cbind(x_new,V4Binario)
>
> x_new <- cbind(x_new,V5Binario)
>
>
>
> nam_ori <- colnames(x_new)
>
> col_nam <- paste("V", 1:ncol(x_new), sep = "")
>
> colnames(x_new) <- col_nam
>
>
>
> library(RSNNS)
>
>
>
> xValues <- x_new
>
> xTargets <- x[, 6]
>
> xTargetsDecoded <- decodeClassLabels(xTargets)
>
> x_nn <- splitForTrainingAndTest(xValues, xTargetsDecoded, ratio=0.15)
>
>
>
> set.seed(432)
>
> model <- mlp(x_nn$inputsTrain, x_nn$targetsTrain,
>
>  size=3, learnFuncParams=c(0.1), maxit=10,
>
>  inputsTest=x_nn$inputsTest, targetsTest=x_nn$targetsTest)
>
>
>
> summary(model)
>
>
>
> #---
>
>
>
>
>
> Saludos,
>
> Carlos Ortega
>
> www.qualityexcellence.es
>
>
>
>
>
> El 9 de julio de 2016, 21:58, Javier Marcuzzi <
> javier.ruben.marcu...@gmail.com> escribió:
>
> Estimados
>
>
>
> Adjunto un archivo de texto separado por comas, muy simple como ejemplo,
> luego el siguiente código explicaría el problema. Si ejecutan el código se
> entenderá, creo.
>
>
>
> x <- read.csv("~/R/neuronal/x.csv", header=FALSE, sep=";")
>
> V1Binario <- model.matrix(~ factor(x$V1) - 1)
>
> # -1 no coloca como interceto, deja x$V1 sin nada, son los que no tienen
> nada (nada, puerta, porton)
>
> V1Binario
>
> V2Binario <- model.matrix(~ factor(x$V2) - 1)
>
> V3Binario <- model.matrix(~ factor(x$V3) - 1)
>
> V4Binario <- model.matrix(~ factor(x$V4) - 1)
>
> V5Binario <- model.matrix(~ factor(x$V5) - 1)
>
> V6Binario <- model.matrix(~ factor(x$V6) - 1)
>
>
>
> x <- cbind(x,V1Binario)
>
> x <- cbind(x,V2Binario)
>
> x <- cbind(x,V3Binario)
>
> x <- cbind(x,V4Binario)
>
> x <- cbind(x,V5Binario)
>
> x <- cbind(x,V6Binario)
>
>
>
> nn <-
> neuralnet(V6Binario~V1Binario+V2Binario+V3Binario+V4Binario+V5Binario, x,
> hidden=2, 

Re: [R] use value in variable to be name of another variable

2016-07-11 Thread Matthew

Hi Jim,

   Wow ! And it does exactly what I was looking for.  Thank you very much.

That assign function is pretty nice. I should become more familiar with it.

Matthew


On 7/11/2016 5:59 PM, Jim Lemon wrote:

Hi Matthew,
This question is a bit mysterious as we don't know what the object
"chr" is. However, have a look at this and see if it is close to what
you want to do.

# set up a little matrix of character values
tTargTFS<-matrix(paste("A",rep(1:4,each=4),"B",rep(1:4,4),sep=""),ncol=4)
# try the assignment on the first row and column
assign(tTargTFS[1,1],tTargTFS[-1,1])
# see what it looks like - okay
A1B1
# run the assignment over the matrix
for(i in 1:4) assign(tTargTFS[1,i],tTargTFS[-1,i])
# see what the variables look like
A1B1
A2B1
A3B1
A4B1

It does what I would expect.

Jim


On Tue, Jul 12, 2016 at 6:01 AM, Matthew
 wrote:

I want to get a value that has been assigned to a variable, and then use
that value to be the name of a variable.

For example,

tTargTFS[1,1]
# returns:
 V1
"AT1G01010"

Now, I want to make AT1G01010 the name of a variable:
AT1G01010 <- tTargTFS[-1,1]

Then, go to the next tTargTFS[1,2]. Which produces
V1
"AT1G01030"
And then,
AT1G01030 <- tTargTFS[-1,2]

I want to do this up to tTargTFS[1, 2666], so I want to do this in a script
and not manually.
tTargTFS is a list of 2: chr [1:265, 1:2666], but I also have the data in a
data frame of 265 observations of 2666 variables, if this data structure
makes things easier.

My initial attempts are not working. Starting with a test data structure
that is a little simpler I have tried:
for (i in 1:4)
{ ATG <- tTargTFS[1, i]
assign(cat(ATG), tTargTFS[-1, i]) }

Matthew

__
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] use value in variable to be name of another variable

2016-07-11 Thread Jim Lemon
Hi Matthew,
This question is a bit mysterious as we don't know what the object
"chr" is. However, have a look at this and see if it is close to what
you want to do.

# set up a little matrix of character values
tTargTFS<-matrix(paste("A",rep(1:4,each=4),"B",rep(1:4,4),sep=""),ncol=4)
# try the assignment on the first row and column
assign(tTargTFS[1,1],tTargTFS[-1,1])
# see what it looks like - okay
A1B1
# run the assignment over the matrix
for(i in 1:4) assign(tTargTFS[1,i],tTargTFS[-1,i])
# see what the variables look like
A1B1
A2B1
A3B1
A4B1

It does what I would expect.

Jim


On Tue, Jul 12, 2016 at 6:01 AM, Matthew
 wrote:
> I want to get a value that has been assigned to a variable, and then use
> that value to be the name of a variable.
>
> For example,
>
> tTargTFS[1,1]
> # returns:
> V1
> "AT1G01010"
>
> Now, I want to make AT1G01010 the name of a variable:
> AT1G01010 <- tTargTFS[-1,1]
>
> Then, go to the next tTargTFS[1,2]. Which produces
>V1
> "AT1G01030"
> And then,
> AT1G01030 <- tTargTFS[-1,2]
>
> I want to do this up to tTargTFS[1, 2666], so I want to do this in a script
> and not manually.
> tTargTFS is a list of 2: chr [1:265, 1:2666], but I also have the data in a
> data frame of 265 observations of 2666 variables, if this data structure
> makes things easier.
>
> My initial attempts are not working. Starting with a test data structure
> that is a little simpler I have tried:
> for (i in 1:4)
> { ATG <- tTargTFS[1, i]
> assign(cat(ATG), tTargTFS[-1, i]) }
>
> Matthew
>
> __
> 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] about smwrgraphs package

2016-07-11 Thread Sarah Goslee
You really need to follow the posting guide and ask an actual
question, ideally a reproducible one.

Failing that, contacting the package maintainer may be the appropriate action.

You're very unlikely to get much interest on the R-help list in such a
vague question, but many of us are able to help with specific
questions even if we've never used a particular package.

Sarah

On Mon, Jul 11, 2016 at 4:47 PM, lily li  wrote:
> I still haven't heard back from anyone. Please let me know as I think it is
> better to discuss here.
>
> On Sun, Jul 10, 2016 at 1:25 PM, lily li  wrote:
>
>> Has anyone used smwrGraphs package? I have some problems and think it may
>> be better to discuss if you have been using it. Thanks very much.
>>
>
> [[alternative HTML version deleted]]

Please don't post in HTML.



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] about smwrgraphs package

2016-07-11 Thread lily li
I still haven't heard back from anyone. Please let me know as I think it is
better to discuss here.

On Sun, Jul 10, 2016 at 1:25 PM, lily li  wrote:

> Has anyone used smwrGraphs package? I have some problems and think it may
> be better to discuss if you have been using it. Thanks very much.
>

[[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] Script/function/procedure with loop

2016-07-11 Thread Sarah Goslee
Taking your question at face value, except for the factors in your
original data frame, you can output anything you'd like to text
onscreen using cat(). Output can also be saved to text files with
sink() or using batch files, etc and so forth.



date <- 
c("07-jul-16","07-jul-16","07-jul-16","08-jul-16","08-jul-16","08-jul-16","09-jul-16","09-jul-16")
varA <- c("text A1","text A2","text A3","text A4","text A5","text
A6","text A7","text A8")
varB <- c("link B1","link B2","link B3","link B4","link B5","link
B6","link B7","link B8")
mydf <- data.frame(date, varA, varB, stringsAsFactors=FALSE)

for(i in sort(unique(mydf$date))) {
  thisdate <- subset(mydf, date==i)
  cat(i, "\n\n")
  for(j in seq_len(nrow(thisdate))) {
cat(thisdate$varA[j], "\n")
cat(thisdate$varB[j], "\n\n")
 }
}

This code prints to screen:

07-jul-16

text A1
link B1

text A2
link B2

text A3
link B3

08-jul-16

text A4
link B4

text A5
link B5

text A6
link B6

09-jul-16

text A7
link B7

text A8
link B8


On Mon, Jul 11, 2016 at 4:24 PM, Luca Meyer  wrote:
> Can anyone point me to an R script/function/procedure which, starting from
> the following sample data
>
> #sample data
> #NB: nrow(df) is variable
>
> date =
> c("07-jul-16","07-jul-16","07-jul-16","08-jul-16","08-jul-16","08-jul-16","09-jul-16","09-jul-16")
> varA = c("text A1","text A2","text A3","text A4","text A5","text A6","text
> A7","text A8")
> varB = c("link B1","link B2","link B3","link B4","link B5","link B6","link
> B7","link B8")
> df = data.frame(date, varA, varB)
>
> allows me to obtain a text output such as:
>
>> 07-jul-16
>
> text A1
> link B1
>
> text A2
> link B2
>
> text A3
> link B3
>
>> 08-jul-16
>
> text A4
> link B4
>
> text A5
> link B5
>
> text A6
> link B6
>
>> 09-jul-16
>
> text A7
> link B7
>
> text A8
> link B8
>
> etc...
>
> Thanks,
>
> Luca
>
> [[alternative HTML version deleted]]

Please post in plain text.

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] How to make the "apply" faster

2016-07-11 Thread William Dunlap via R-help
If you use Rcpp::Rcpp.package.skeleton() to make a package out
of the attached C++ code you can speed up the run counting quite
a bit - to 1.4 s. from 48 s. for the 101 x 107 x 17 x 103 example.

The package you make will define an R function called CountColumnRuns
that computes the number of runs of TRUE of a given minimum length
for each column in a matrix.  You can adapt it to your 4-dimensional array
with

f5 <- function (condition, spellLength = 2)
{
stopifnot(is.logical(condition), !anyNA(condition))
d <- dim(condition)
dn <- dimnames(condition)
tmp <- array(aperm(condition, c(3, 1, 2, 4)), c(d[3], prod(d[-3])))
runCounts <- RcppCountRuns::CountColumnRuns(tmp, spellLength)
array(runCounts, dim = d[-3], dimnames = dn[-3])
}

and call it as

f5( x > 1, spellLength=2)

to get the counts of all runs of length at least 2 in the 3rd dimension of
your 4-d array.



#include 

int CountRunsRaw(const int *x, int n, int minRun)
{
int count(0);
int runLength(0);
const int* lastX(x + n);
for( ; x != lastX ; x++)
{
if (*x)
{
runLength++;
}
else
{
if (runLength >= minRun)
{
count++;
}
runLength = 0;
}
}
if (runLength >= minRun)
{
count++;
}
return count;
}

// [[Rcpp::export]]
int CountRuns(const Rcpp::LogicalVector& x, int minRun)
{
return CountRunsRaw([0], x.size(), minRun);
}
// [[Rcpp::export]]
Rcpp::IntegerVector CountColumnRuns(const Rcpp::LogicalMatrix& x, int
minRun)
{
Rcpp::IntegerVector out(x.ncol());
for(int i = 0 ; i < x.ncol() ; i++)
{
out[i] = CountRuns(x(Rcpp::_, i), minRun);
}
return out;
}


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Jul 11, 2016 at 9:42 AM, William Dunlap  wrote:

> How fast is fast enough and what size and shape is your dataset
> (show the output of str(yourData))?  You will get the fastest execution
> time by using C or C++ or Fortran, but you will want to parameterize
> the problem well enough that you can amortize the time it takes to
> write the code over many problems.
>
> Peter Langflder's suggested you use aperm followed by colSums
> for your earlier problem.   For this one you can use aperm followed
> by filter (to identify the runs of a given minimum length, column by
> column) and then use colSums (to count the number of runs filter
> identifies in each column).  E.g.,
>
>   f4 <- function (condition, spellLength = 2)
>   {
>   # obscure way to count runs of length>spellLength
>   # in 3'rd dimension of logical array 'condition'.
>   stopifnot(is.logical(condition), !anyNA(condition))
>   coef <- c(-1, rep(1, spellLength))
>   d <- dim(condition)
>   dn <- dimnames(condition)
>   tmp <- array(aperm(condition * 2 - 1, c(3, 1, 2, 4)), c(d[3],
>   prod(d[-3])))
>   fTmp <- filter(rbind(tmp, -1), coef, sides = 1)
>  sfTmp <- colSums(fTmp == spellLength + 1, na.rm = TRUE)
>  array(sfTmp, dim = d[-3], dimnames = dn[-3])
>   }
>
> f4(x>=1) is not a great deal faster (48 s. vs. 67 s.) than
> apply(x>=1, c(1,2,4), FUN=f3) where f3 is
>   f3 <- function (condition, spellLength = 2)
>   {
>   stopifnot(is.logical(condition), !anyNA(condition))
>   y <- rle(condition)
>   sum(y$lengths[y$values] >= spellLength)
>   }
> and where x has dimensions c(101,107,17,103).
>
> The relative speed will depend on the size and shape of your dataset,
> so show the output of str(yourData).
>
>
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Sun, Jul 10, 2016 at 1:38 PM, Debasish Pai Mazumder 
> wrote:
>
>> Thanks for your response. It is faster than before but still very slow.
>> Any other suggestion ?
>> -Deb
>>
>>
>> On Sun, Jul 10, 2016 at 2:13 PM, William Dunlap 
>> wrote:
>>
>>> There is no need to test that a logical equals TRUE:
>>> 'logicalVector==TRUE' is the
>>> same as just 'logicalVector'.
>>>
>>> There is no need to convert logical vectors to numeric, since rle()
>>> works on both
>>> types.
>>>
>>> There is no need to use length(subset(x, logicalVector)) to count how
>>> many elements
>>> in logicalVector are TRUE, just use sum(logicalVector).
>>>
>>> There is no need to make a variable, 'ans', then immediately return it.
>>>
>>> Hence your
>>>
>>> b[b == TRUE] = 1
>>> y <- rle(b)
>>> ans <- length(subset(y$lengths[y$values == 1], y$lengths[y$values ==
>>> 1] >= 2))
>>> return(ans)
>>>
>>> could be replaced by
>>>
>>> y <- rle(b)
>>> sum(y$lengths[y$values] >= 2)
>>>
>>> This gives some speedup, mainly for long vectors, but I find it more
>>> understandable.
>>> E.g., if f1 is your original function and f2 has the above replacement I
>>> get:
>>>   > d <- -sin(1:1+sqrt(1:4))
>>>   > system.time(for(i in 1:1)f1(d,.3))
>>>  user  system elapsed
>>>  5.190.005.19
>>>   > 

[R] Script/function/procedure with loop

2016-07-11 Thread Luca Meyer
Can anyone point me to an R script/function/procedure which, starting from
the following sample data

#sample data
#NB: nrow(df) is variable

date =
c("07-jul-16","07-jul-16","07-jul-16","08-jul-16","08-jul-16","08-jul-16","09-jul-16","09-jul-16")
varA = c("text A1","text A2","text A3","text A4","text A5","text A6","text
A7","text A8")
varB = c("link B1","link B2","link B3","link B4","link B5","link B6","link
B7","link B8")
df = data.frame(date, varA, varB)

allows me to obtain a text output such as:

> 07-jul-16

text A1
link B1

text A2
link B2

text A3
link B3

> 08-jul-16

text A4
link B4

text A5
link B5

text A6
link B6

> 09-jul-16

text A7
link B7

text A8
link B8

etc...

Thanks,

Luca

[[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] Distribuciones de probabilidad

2016-07-11 Thread rafael_saturno


Ok. Muchas gracias


Obtener Outlook para Android






On Mon, Jul 11, 2016 at 3:59 PM -0400, "Carlos J. Gil Bellosta " 
 wrote:





Hola, ¿qué tal?

La respuesta breve es no.

Para los usos más habituales, sin embargo, bastaría con un mean(rXXX(1e5,
...)). Aunque cuidado

.

Si quieres la respuesta de libro, tendrás que consultar o deducir esos
estadísticos. Y tendrás que tener cuidado con la parametrización particular
que hace R cuando no hay una supercanónica.

Un saludo,

Carlos J. Gil Bellosta
http://www.datanalytics.com

El 11 de julio de 2016, 16:39, Rafael Saturno 
escribió:

> Hola Comunidad,
> Tenia al siguiente duda
> ¿hay alguna forma de que R me de la Esperanza y Varianza de una
> distribución según sus parámetros?
> es decir, si tengo una weibull de parámetros "X" y "Y" para la esperanza
> hay una formula, pero me gustaría saber si hay una función en R que le diga
> algo como
> Esperanza(weibull, shape = "X", scale = "Y") y ya devuelva esa esperanza
> así como la variaran de esa misma funcion
> Muchas gracias
> [[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 HTML version deleted]]

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


[R] use value in variable to be name of another variable

2016-07-11 Thread Matthew
I want to get a value that has been assigned to a variable, and then use 
that value to be the name of a variable.


For example,

tTargTFS[1,1]
# returns:
V1
"AT1G01010"

Now, I want to make AT1G01010 the name of a variable:
AT1G01010 <- tTargTFS[-1,1]

Then, go to the next tTargTFS[1,2]. Which produces
   V1
"AT1G01030"
And then,
AT1G01030 <- tTargTFS[-1,2]

I want to do this up to tTargTFS[1, 2666], so I want to do this in a 
script and not manually.
tTargTFS is a list of 2: chr [1:265, 1:2666], but I also have the data 
in a data frame of 265 observations of 2666 variables, if this data 
structure makes things easier.


My initial attempts are not working. Starting with a test data structure 
that is a little simpler I have tried:

for (i in 1:4)
{ ATG <- tTargTFS[1, i]
assign(cat(ATG), tTargTFS[-1, i]) }

Matthew

__
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] Distribuciones de probabilidad

2016-07-11 Thread Carlos J. Gil Bellosta
Hola, ¿qué tal?

La respuesta breve es no.

Para los usos más habituales, sin embargo, bastaría con un mean(rXXX(1e5,
...)). Aunque cuidado

.

Si quieres la respuesta de libro, tendrás que consultar o deducir esos
estadísticos. Y tendrás que tener cuidado con la parametrización particular
que hace R cuando no hay una supercanónica.

Un saludo,

Carlos J. Gil Bellosta
http://www.datanalytics.com

El 11 de julio de 2016, 16:39, Rafael Saturno 
escribió:

> Hola Comunidad,
> Tenia al siguiente duda
> ¿hay alguna forma de que R me de la Esperanza y Varianza de una
> distribución según sus parámetros?
> es decir, si tengo una weibull de parámetros "X" y "Y" para la esperanza
> hay una formula, pero me gustaría saber si hay una función en R que le diga
> algo como
> Esperanza(weibull, shape = "X", scale = "Y") y ya devuelva esa esperanza
> así como la variaran de esa misma funcion
> Muchas gracias
> [[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 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-es] Esperanza de vida librería 'demography'

2016-07-11 Thread Javier Marcuzzi
Estimada Carmen 

Tendría que estudiar su problema, pero posiblemente una regresión de cox, 
proporciona los valores, luego con estos calcular para la esperanza de vida.

Yo buscaría un ejemplo en R con las siguientes palabras:
r cox proportional average life expectancy

Javier Rubén Marcuzzi

De: CARMEN MARTINEZ OLMO___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] [FORGED] Regression with factors ?

2016-07-11 Thread Jeff Newmiller
Your clarification is promising.  A reproducible example is always preferred, 
though never a guarantee. I expect to be somewhat preoccupied this week so 
responses may be rather delayed, but the less setup we have to the more likely 
that someone on the list will tackle it.

Re an answer: If you can make the example simple enough that you can tell us 
what the right numerical result will be, we will have a better chance of 
understanding what you are after.  E.g. if you start with a solution and use it 
to create sample input data with then you don't need to actually solve it to 
illustrate what you are after. [1]

Note that I am not aware of any package dedicated to this type of problem, so 
unless someone else responds otherwise then you will likely have to use 
bootstrapping or your own statistical analysis (Bayesian?) of the result. 

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
-- 
Sent from my phone. Please excuse my brevity.

On July 11, 2016 7:28:41 AM PDT, stn021  wrote:
>Hello,
>
>thank you for the replies. Sorry about the html-email, I forgot.
>Should be OK with this email.
>
>
>Don't be fooled be the apparent simplicity of the problem. I have
>tried to reduce it to only a single relatively simple question.
>
>The idea here is to model cooperation of two persons. The model is
>about one specific aspect of that cooperation, namely that two persons
>with similar abilities may be able to produce better results that two
>very different persons.
>
>That is only one part of the model with other parts modeling for
>example the fact that of course two persons with a higher degree of
>ability will produce better results per se.
>
>
>It is not classic regression with factors. That can be easily done by
>something like lm( y ~ (p1-p2)^2 ).
>
>This expands to lm( y ~ p1^2 - 2*p1*p2 + p2^2 ). This contains a
>multiplicagtions and for lm() this implies interactions between the
>factor-levels and produces one parameter for each combination of
>factor-levels that occurs in the data. That is not what the question
>is about.
>
>Also p1 and p2 are different levels of the same factor, while for lm()
>it would be two different factors with different levels.
>
>
>As for the sensical part: this has a real world application therefore
>it makes sense.
>
>Also it is not so difficult to solve with non-linear optimization. I
>was hoping to be able to use R for that purpose because then the
>results could easily be checked with statistical tests.
>
>So my question is not "how to solve" but "how to solve with R".
>
>
>As for the excess degrees of freedom, in real observations there would
>of course be added noise due to either random variations or factors
>not included in the model. So to generate a more reality-conforming
>example I could add some random normal-distributed noise to the
>dependent variable y. I previously left that part out because to me it
>did not seem relevant.
>
>
>Would you like me to make a complete example dataset with more records
>and noise ?
>
>
>The answer I look for would be the numerical values of the
>factor-levels and numerical values for the multiplier (f) and the
>offset (o), with p1 and p2 given as names (here: persons) and y given
>as some level of achievement they reach by cooperating.
>
>y = f * ( o - ( p1 - p2 )^2 )
>
>Is that what you meant by "answer" ?
>
>
>THX
>stefan
>
>
>
>
>2016-07-10 2:27 GMT+02:00 Jeff Newmiller :
>>
>> I have seen less sensical questions.
>>
>> It would be nice if the example were a bit more complete (as in it
>should have excess degrees of freedom and an answer) and less like a
>homework problem (which are off topic here). It would of course also be
>helpful if the OP were to conform to the Posting Guide, particularly in
>respect to using plain text email.
>>
>> It looks like the kind of nonlinear optimization problem that
>evolutionary algorithms are often applied to. It doesn't look (to me)
>like a typical problem that factors get applied to in formulas though,
>because multiple instances of the same factor variable are present.
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On July 9, 2016 4:59:30 PM PDT, Rolf Turner 
>wrote:
>> >On 09/07/16 20:52, stn021 wrote:
>> >> Hello,
>> >>
>> >> I would like to analyse a model like this:
>> >>
>> >> y = 1 *  ( 1 - ( x1 - x2 )  ^ 2   )
>> >>
>> >> x1 and x2 are not continuous variables but factors, so the
>> >observation
>> >> contain the level.
>> >> Its numerical value is unknown and is to be estimated with the
>model.
>> >>
>> >>
>> >> The observations look like this:
>> >>
>> >> yx1 x2
>> >> 0.96  Alice  Bob
>> >> 0.84  Alice  Charlie
>> >> 0.96  Bob   Charlie
>> >> 0.64  Dave Alice
>> >> etc.
>> >>
>> >> Each person has a numerical value. Here for example Alice = 0.2
>and
>> >Bob =
>> >> 0.4
>> >>
>> >> Then y = 0.96 = 1* ( 1- ( 0.2-0.4 ) ^ 2 ) , see first observation.

Re: [R] [FORGED] Regression with factors ?

2016-07-11 Thread David Winsemius

> On Jul 11, 2016, at 7:28 AM, stn021  wrote:
> 
> Hello,
> 
> thank you for the replies. Sorry about the html-email, I forgot.
> Should be OK with this email.
> 
> 
> Don't be fooled be the apparent simplicity of the problem. I have
> tried to reduce it to only a single relatively simple question.

It would be useful to know whether this is a design effort and the data is not 
yet recorded or this is an analysis effort for data that is "in the can".
> 
> The idea here is to model cooperation of two persons. The model is
> about one specific aspect of that cooperation, namely that two persons
> with similar abilities may be able to produce better results that two
> very different persons.
> 
> That is only one part of the model with other parts modeling for
> example the fact that of course two persons with a higher degree of
> ability will produce better results per se.
> 
> 
> It is not classic regression with factors. That can be easily done by
> something like lm( y ~ (p1-p2)^2 ).

No. The caret "^" is an interaction operator in the formula context (not a 
power operator) and the minus sign causes variable removal.

Read:

?formula

If you want to create a calculated value that is the squared difference of two 
variables, then you need to do it either with `I` or in the dataframe before 
submission to the regression function.


> 
> This expands to lm( y ~ p1^2 - 2*p1*p2 + p2^2 ).

Used in a formula, p1^2 is exactly equal to p1.


> This contains a
> multiplicagtions and for lm() this implies interactions between the
> factor-levels and produces one parameter for each combination of
> factor-levels that occurs in the data. That is not what the question
> is about.
> 
> Also p1 and p2 are different levels of the same factor, while for lm()
> it would be two different factors with different levels.

Given your apparent lack of knowledge about R's formula syntax, we are also now 
unclear if you are using the word "factor" in the colloquial sense or as a 
technical term for discrete (factor) variables in R. What kind of values can p1 
and p2 take?


> As for the sensical part: this has a real world application therefore
> it makes sense.
> 
> Also it is not so difficult to solve with non-linear optimization. I
> was hoping to be able to use R for that purpose because then the
> results could easily be checked with statistical tests.
> 
> So my question is not "how to solve" but "how to solve with R".
> 
> 
> As for the excess degrees of freedom, in real observations there would
> of course be added noise due to either random variations or factors
> not included in the model. So to generate a more reality-conforming
> example I could add some random normal-distributed noise to the
> dependent variable y. I previously left that part out because to me it
> did not seem relevant.

Knowing the nature of the outcome variable is generally important in 
statistical design.
> 
> 
> Would you like me to make a complete example dataset with more records
> and noise ?

Yes. And preferably do it with R code.

> 
> The answer I look for would be the numerical values of the
> factor-levels and numerical values for the multiplier (f) and the
> offset (o), with p1 and p2 given as names (here: persons) and y given
> as some level of achievement they reach by cooperating.
> 
> y = f * ( o - ( p1 - p2 )^2 )
> 
> Is that what you meant by "answer" ?

Not really. We would expect to see some data, at least dummy data, in a form 
that could be used for testing and demonstration.  The nature of "f" is 
particularly unclear (in large part because the science or "reality" is not 
described.)  Is it a function?  The "o" is probably going to be returned as an 
"(Intercept)". You started out with `lm` which would have little to do with 
non-linear optimization. You then said it "would not be so difficult" to do 
non-linear optimization of "something" which was not really specified with any 
substance. Without data and code it still reads as a salad of fragments of 
terminology lacking reference to a well-described scientific substrate. 

An "answer" would be:

Describe an experiment or a well designed set of observations with a specific 
outcome. Describe the hypotheses. Present code or data with a desired analysis 
plan. Ask for problems in R coding.



An off-topic question would be:

Help me design my psychology class project.


-- 
David.


> 
> 
> THX
> stefan
> 
> 
> 
> 
> 2016-07-10 2:27 GMT+02:00 Jeff Newmiller :
>> 
>> I have seen less sensical questions.
>> 
>> It would be nice if the example were a bit more complete (as in it should 
>> have excess degrees of freedom and an answer) and less like a homework 
>> problem (which are off topic here). It would of course also be helpful if 
>> the OP were to conform to the Posting Guide, particularly in respect to 
>> using plain text email.
>> 
>> It looks like the kind of nonlinear optimization problem that evolutionary 
>> algorithms 

Re: [R] How to make the "apply" faster

2016-07-11 Thread William Dunlap via R-help
How fast is fast enough and what size and shape is your dataset
(show the output of str(yourData))?  You will get the fastest execution
time by using C or C++ or Fortran, but you will want to parameterize
the problem well enough that you can amortize the time it takes to
write the code over many problems.

Peter Langflder's suggested you use aperm followed by colSums
for your earlier problem.   For this one you can use aperm followed
by filter (to identify the runs of a given minimum length, column by
column) and then use colSums (to count the number of runs filter
identifies in each column).  E.g.,

  f4 <- function (condition, spellLength = 2)
  {
  # obscure way to count runs of length>spellLength
  # in 3'rd dimension of logical array 'condition'.
  stopifnot(is.logical(condition), !anyNA(condition))
  coef <- c(-1, rep(1, spellLength))
  d <- dim(condition)
  dn <- dimnames(condition)
  tmp <- array(aperm(condition * 2 - 1, c(3, 1, 2, 4)), c(d[3],
  prod(d[-3])))
  fTmp <- filter(rbind(tmp, -1), coef, sides = 1)
 sfTmp <- colSums(fTmp == spellLength + 1, na.rm = TRUE)
 array(sfTmp, dim = d[-3], dimnames = dn[-3])
  }

f4(x>=1) is not a great deal faster (48 s. vs. 67 s.) than
apply(x>=1, c(1,2,4), FUN=f3) where f3 is
  f3 <- function (condition, spellLength = 2)
  {
  stopifnot(is.logical(condition), !anyNA(condition))
  y <- rle(condition)
  sum(y$lengths[y$values] >= spellLength)
  }
and where x has dimensions c(101,107,17,103).

The relative speed will depend on the size and shape of your dataset,
so show the output of str(yourData).





Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sun, Jul 10, 2016 at 1:38 PM, Debasish Pai Mazumder 
wrote:

> Thanks for your response. It is faster than before but still very slow.
> Any other suggestion ?
> -Deb
>
>
> On Sun, Jul 10, 2016 at 2:13 PM, William Dunlap  wrote:
>
>> There is no need to test that a logical equals TRUE:
>> 'logicalVector==TRUE' is the
>> same as just 'logicalVector'.
>>
>> There is no need to convert logical vectors to numeric, since rle() works
>> on both
>> types.
>>
>> There is no need to use length(subset(x, logicalVector)) to count how
>> many elements
>> in logicalVector are TRUE, just use sum(logicalVector).
>>
>> There is no need to make a variable, 'ans', then immediately return it.
>>
>> Hence your
>>
>> b[b == TRUE] = 1
>> y <- rle(b)
>> ans <- length(subset(y$lengths[y$values == 1], y$lengths[y$values ==
>> 1] >= 2))
>> return(ans)
>>
>> could be replaced by
>>
>> y <- rle(b)
>> sum(y$lengths[y$values] >= 2)
>>
>> This gives some speedup, mainly for long vectors, but I find it more
>> understandable.
>> E.g., if f1 is your original function and f2 has the above replacement I
>> get:
>>   > d <- -sin(1:1+sqrt(1:4))
>>   > system.time(for(i in 1:1)f1(d,.3))
>>  user  system elapsed
>>  5.190.005.19
>>   > system.time(for(i in 1:1)f2(d,.3))
>>  user  system elapsed
>>  3.650.003.65
>>   > c(f1(d,.3), f2(d,.3))
>>   [1] 1492 1492
>>   > length(d)
>>   [1] 1
>>
>> If it were my function, I would also get rid of the part that deals with
>> the threshhold
>> and direction of the inequality and tell the user to to use f(data <=
>> 0.3) instead of
>> f(data, .3, "below").  I would also make the spell length an argument
>> instead of
>> fixing it at 2.  E.g.
>>
>>> f3 <- function (condition, spellLength = 2)
>>{
>>stopifnot(is.logical(condition), !anyNA(condition))
>>y <- rle(condition)
>>sum(y$lengths[y$values] >= spellLength)
>>}
>>> f3( d >= .3 )
>>[1] 1492
>>
>>
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>> On Sun, Jul 10, 2016 at 11:58 AM, Debasish Pai Mazumder <
>> pai1...@gmail.com> wrote:
>>
>>> Hi Everyone,
>>> Thanks for your help. It works. I have similar problem when I am
>>> calculating number of spell.
>>> I am also calculation spell (definition: period of two or more days
>>> where x
>>> exceeds 70) using similar way:
>>>
>>> *new = apply(x,c(1,2,4),FUN=function(y) {fun.spell.deb(y, 70)})*
>>>
>>> where fun.spell.deb.R:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *## Calculate spell durationfun.spell.deb <- function(data, threshold =
>>> 1,
>>> direction = c("above", "below")){  #coln <- grep(weather, names(data))#
>>> var <- data[,8]  if(missing(direction)) {direction <- "above"}
>>> if(direction=="below") {b <- (data <= threshold)} else  {b <- (data >=
>>> threshold)}b[b==TRUE] = 1  y <-rle(b)  ans
>>> <-length(subset((y$lengths[y$values==1]), (y$lengths[y$values==1])>=2))
>>> return(ans)}*
>>>
>>> Do you have any idea how to make the "apply" faster here?
>>>
>>> -Deb
>>>
>>>
>>> On Sat, Jul 9, 2016 at 3:46 PM, Charles C. Berry 
>>> wrote:
>>>
>>> > On Sat, 9 Jul 2016, Debasish Pai Mazumder wrote:
>>> >
>>> > I have 4-dimension array 

[R] gsl package installation problem: gsl-config not found (even though gsl has been installed)

2016-07-11 Thread pan yang
Dear R-community,

I faced this problem when I tried to install the R gsl wrapper in my
university's HPC cluster. Before installing the R wrapper, I have already
installed the 'gsl' version 2.1 in my own directory '/home/pyangac/dev'. I
have tested the gsl installation by compiling the simple program in the gsl
manual (
https://www.gnu.org/software/gsl/manual/html_node/An-Example-Program.html#An-Example-Program
).

After this, I followed the steps in page 30 of the R package's document (
https://cran.r-project.org/web/packages/gsl/gsl.pdf) to install the package
(I didn't do step 3 because I really don't know how to do it, and by
looking at the solutions posted online, nobody had done step 3):

$ /home/pyangac/dev/bin/gsl-config --libs
-L/home/pyangac/dev/lib -lgsl -lgslcblas -lm

$ /home/pyangac/dev/bin/gsl-config --cflags
-I/home/pyangac/dev/include

$ LDFLAGS="-L/home/pyangac/dev/lib -lgsl -lgslcblas -lm"; export LDFLAGS
$ CPPFALGS="-I/home/pyangac/dev/include"; export CPPFLAGS

$ R CMD INSTALL '/home/pyangac/gsl_1.9-10.1.tar.gz'
* installing to library '/home/pyangac/R_libs'
* installing *source* package 'gsl' ...
** package 'gsl' successfully unpacked and MD5 sums checked
checking for gsl-config... no
configure: error: gsl-config not found, is GSL installed?
ERROR: configuration failed for package 'gsl'
* removing '/home/pyangac/R_libs/gsl'

Does anyone know why this is happening? Is it because I have not go through
step 3?

Your generous help and assistance will be highly appreciated.

Best regards,
Pan

[[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] [FORGED] Regression with factors ?

2016-07-11 Thread stn021
Hello,

thank you for the replies. Sorry about the html-email, I forgot.
Should be OK with this email.


Don't be fooled be the apparent simplicity of the problem. I have
tried to reduce it to only a single relatively simple question.

The idea here is to model cooperation of two persons. The model is
about one specific aspect of that cooperation, namely that two persons
with similar abilities may be able to produce better results that two
very different persons.

That is only one part of the model with other parts modeling for
example the fact that of course two persons with a higher degree of
ability will produce better results per se.


It is not classic regression with factors. That can be easily done by
something like lm( y ~ (p1-p2)^2 ).

This expands to lm( y ~ p1^2 - 2*p1*p2 + p2^2 ). This contains a
multiplicagtions and for lm() this implies interactions between the
factor-levels and produces one parameter for each combination of
factor-levels that occurs in the data. That is not what the question
is about.

Also p1 and p2 are different levels of the same factor, while for lm()
it would be two different factors with different levels.


As for the sensical part: this has a real world application therefore
it makes sense.

Also it is not so difficult to solve with non-linear optimization. I
was hoping to be able to use R for that purpose because then the
results could easily be checked with statistical tests.

So my question is not "how to solve" but "how to solve with R".


As for the excess degrees of freedom, in real observations there would
of course be added noise due to either random variations or factors
not included in the model. So to generate a more reality-conforming
example I could add some random normal-distributed noise to the
dependent variable y. I previously left that part out because to me it
did not seem relevant.


Would you like me to make a complete example dataset with more records
and noise ?


The answer I look for would be the numerical values of the
factor-levels and numerical values for the multiplier (f) and the
offset (o), with p1 and p2 given as names (here: persons) and y given
as some level of achievement they reach by cooperating.

y = f * ( o - ( p1 - p2 )^2 )

Is that what you meant by "answer" ?


THX
stefan




2016-07-10 2:27 GMT+02:00 Jeff Newmiller :
>
> I have seen less sensical questions.
>
> It would be nice if the example were a bit more complete (as in it should 
> have excess degrees of freedom and an answer) and less like a homework 
> problem (which are off topic here). It would of course also be helpful if the 
> OP were to conform to the Posting Guide, particularly in respect to using 
> plain text email.
>
> It looks like the kind of nonlinear optimization problem that evolutionary 
> algorithms are often applied to. It doesn't look (to me) like a typical 
> problem that factors get applied to in formulas though, because multiple 
> instances of the same factor variable are present.
> --
> Sent from my phone. Please excuse my brevity.
>
> On July 9, 2016 4:59:30 PM PDT, Rolf Turner  wrote:
> >On 09/07/16 20:52, stn021 wrote:
> >> Hello,
> >>
> >> I would like to analyse a model like this:
> >>
> >> y = 1 *  ( 1 - ( x1 - x2 )  ^ 2   )
> >>
> >> x1 and x2 are not continuous variables but factors, so the
> >observation
> >> contain the level.
> >> Its numerical value is unknown and is to be estimated with the model.
> >>
> >>
> >> The observations look like this:
> >>
> >> yx1 x2
> >> 0.96  Alice  Bob
> >> 0.84  Alice  Charlie
> >> 0.96  Bob   Charlie
> >> 0.64  Dave Alice
> >> etc.
> >>
> >> Each person has a numerical value. Here for example Alice = 0.2 and
> >Bob =
> >> 0.4
> >>
> >> Then y = 0.96 = 1* ( 1- ( 0.2-0.4 ) ^ 2 ) , see first observation.
> >>
> >> How can this be done in R ?
> >
> >
> >This question makes about as little sense as it is possible to imagine.
> >
> >cheers,
> >
> >Rolf Turner
>

__
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] package flexmix: models for ordinal data?

2016-07-11 Thread Xin Shelia
Hi Klaus,

I saw you post “package flexmix: models for ordinal data?” on grokbase. I was 
wondering did you find the answer? Or what package did you use at the end? I 
really appreciate if you would like to help me. 

Best, 
Xin 
__
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] [R-pkgs] archivist.github 0.2.1 on CRAN - Task View: Reproducible Research

2016-07-11 Thread Marcin Kosiński
Hi all R devs,

archivist.github has appeared on CRAN in it's updated version.
You can check the last blog post on how has RHero saved the Backup City
with the power or archivist and GitHub
http://www.r-bloggers.com/r-hero-saves-backup-city-with-archivist-and-github/

There is also going to be a talk on useR2016 about it's core dependency -
archivist

How to use the archivist package to boost reproducibility of your research




If you would like to boost your reproducible engines then this is a talk
for you :)

Best,
archivist.github author
Marcin Kosiński

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
__
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] [R-pkgs] New package 'forestinventory: Design-Based Global and Small-Area Estimations for Multiphase Forest Inventories'

2016-07-11 Thread Hill Andreas
Dear R users,

We are happy to announce that the R package 'forestinventory: Design-Based 
Global and Small-Area Estimations for Multiphase Forest Inventories'
is now on CRAN (https://cran.r-project.org/web/packages/forestinventory/).

The aim of our package is to provide global- and smallarea estimators for 
twophase and threephase forest inventories under simple and cluster sampling.
The methods can be used for double sampling for stratification (i.e. classical 
ANOVA model as prediction model),
double sampling for regression (i.e. multiple regression model as prediction 
model) and double sampling for regression within strata
(i.e. classical ANCOVA model as prediction model). The implemented estimators 
have been developed by Daniel Mandallaz at ETH Zurich
and their implementation has been optimized according to current challenges and 
needs of multiphase inventories (e.g. use of remote sensing / geodata).

Relevant features:

-  Provides point - and variance estimators for 64 inventory scenarios 
in total,

according to sample design (simple and cluster sampling, two- and threephase 
inventory designs) and availability of auxiliary information

-  Allows for the computation of Confidence Intervals for the point 
estimates

-  Completes the range of the already published estimators for 
threephase small area estimations

-  Also includes estimators for onephase inventories (only using 
terrestrial inventory data)

Upcoming activities:
We will publish a vignette illustrating the use of the various estimators as 
soon as possible.


Best,

Andreas Hill
Alexander Massey


---
ETH Z�rich
Andreas Hill
Forstl. Ingenieurwesen, Heinimann
CHN K 75.1
Universit�tstrasse 16
8092 Z�rich

Telefon: +41 44 632 32 36
andreas.h...@usys.ethz.ch

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages__
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] Problem when installing Rmpi package in HPC cluster

2016-07-11 Thread pan yang
Dear R community,

I faced this problem when I am installing the Rmpi in our university's
linux86-64 cluster:

> install.packages('Rmpi',repos='http://cran.r-project.org
',configure.args=c(
+ '--with-Rmpi-include=/usr/mpi/gcc/openmpi-1.8.2/include/',
+ '--with-Rmpi-libpath=/usr/mpi/gcc/openmpi-1.8.2/lib64/',
+ '--with-Rmpi-type=OPENMPI'))
Installing package into ?d1/pyangac/R_lilbs?
(as 滎ib?is unspecified)
trying URL 'http://cran.r-project.org/src/contrib/Rmpi_0.6-6.tar.gz'
Content type 'application/x-gzip' length 105181 bytes (102 Kb)
opened URL
==
downloaded 102 Kb

* installing *source* package 槔mpi?...
** package 槔mpi?successfully unpacked and MD5 sums checked
checking for openpty in -lutil... no
checking for main in -lpthread... no
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -DPACKAGE_NAME=\"\"
-DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\"
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\"
-I/usr/mpi/gcc/openmpi-1.8.2/include/  -DMPI2 -DOPENMPI
-I/usr/local/include-fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
-fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64
-mtune=generic  -c Rmpi.c -o Rmpi.o
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -DPACKAGE_NAME=\"\"
-DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\"
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\"
-I/usr/mpi/gcc/openmpi-1.8.2/include/  -DMPI2 -DOPENMPI
-I/usr/local/include-fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
-fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64
-mtune=generic  -c conversion.c -o conversion.o
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -DPACKAGE_NAME=\"\"
-DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\"
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\"
-I/usr/mpi/gcc/openmpi-1.8.2/include/  -DMPI2 -DOPENMPI
-I/usr/local/include-fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
-fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64
-mtune=generic  -c internal.c -o internal.o
gcc -m64 -std=gnu99 -shared -L/usr/local/lib64 -o Rmpi.so Rmpi.o
conversion.o internal.o -L/usr/mpi/gcc/openmpi-1.8.2/lib64/ -lmpi
-L/usr/lib64/R/lib -lR
installing to /d1/pyangac/R_lilbs/Rmpi/libs
** R
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
  converting help for package 槔mpi?
finding HTML links ... done
hosts   html
internalhtml
mpi.abort   html
mpi.apply   html
mpi.barrier html
mpi.bcast   html
mpi.bcast.Robj  html
mpi.bcast.cmd   html
mpi.cart.coords html
mpi.cart.create html
mpi.cart.gethtml
mpi.cart.rank   html
mpi.cart.shift  html
mpi.cartdim.get html
mpi.commhtml
mpi.comm.disconnect html
mpi.comm.free   html
mpi.comm.inter  html
mpi.comm.set.errhandler html
mpi.comm.spawn  html
mpi.const   html
mpi.dims.create html
mpi.exithtml
mpi.finalizehtml
mpi.gather  html
mpi.gather.Robj html
mpi.get.count   html
mpi.get.processor.name  html
mpi.get.sourcetag   html
mpi.iapply  html
mpi.infohtml
mpi.intercomm.merge html
mpi.parSim  html
mpi.parapplyhtml
mpi.probe   html
mpi.realloc html
mpi.reduce  html
mpi.remote.exec html
mpi.scatter html
mpi.scatter.Robjhtml
mpi.sendhtml
mpi.send.Robj   html
mpi.sendrecvhtml
mpi.setup.rng   html
mpi.spawn.Rslaves   html
mpi.universe.size   html
mpi.waithtml
** building package indices
** testing if installed package can be loaded
--
Error obtaining unique transport key from ORTE

[R] r and fixed effect modeling

2016-07-11 Thread Cristina Cametti
Dear all,

I am having problem finding a reliable code for my country fixed effects model.
I have 21 countries in my database and individuals nested within them. I am 
running a multilevel analysis first, and then I am using the fixed effects 
approach to check the robustness of my findings. At this point, I need to 
include in my model some cross-level interaction effects between the country 
level factors and individual level variables. However, I am not sure if my r 
code is right:

model1<-lm(safety ~ mixed_neigh + ethnic_neigh + age + gndr + eduyrs + domicil 
+ partner + 
   tvpol + income + victim + trust + trustXprison_pop + 
trustXforeign_pop + victimXprison_pop + 
   victimXforeign_pop + mixed_neighXprison_pop + 
mixed_neighXforeign_pop + ethnic_neighXprison_pop + 
   ethnic_neighXforeign_pop + factor(cntry)-1, data=mydata)
As you can see, the interaction are between a individual level variable (such 
as trst, victim, mixed_neigh and ethnic_neigh) and two country level variables 
(prison population and foreign population). The code runs fine, so I don�t have 
warning messages and it is all spelled correctly. I just want to know if you 
think that this is the right code to do a fixed effect analysis (only cross 
sections and not cross time). Indeed, I I used the lm and not ppm because my 
dataset is from only one year. Do you think it is correct?

Thank you very much for your attention,

Cristina 
[[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] [R-pkgs] new version of the package fitdistrplus

2016-07-11 Thread Marie Laure Delignette-Muller
We are pleased to announce your a new version of fitdistrplus  (
https://cran.r-project.org/package=fitdistrplus). Among the new features of
the package (https://cran.r-project.org/web/packages/fitdistrplus/NEWS), a
FAQ vignette is now available (
https://cran.r-project.org/web/packages/fitdistrplus/vignettes/FAQ.html).
We will be delighted to update it with new questions sent by users. Do not
hesitate to send us any comment on this vignette or on the package in
general.

Best regards
Marie Laure DELIGNETTE-MULLER and Christophe DUTANG

[[alternative HTML version deleted]]

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

__
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] [R-pkgs] Seasonal PSF - Time Series Forecasting algorithm

2016-07-11 Thread Neeraj Dhanraj
Hi friends,
If you are interested in univariate time series data predictions, have a
look in PSF algorithm and it's R Packages available at :
CRAN: https://cran.r-project.org/web/packages/PSF/index.html

GitHub: https://github.com/neerajdhanraj/PSF

How to use:
https://www.researchgate.net/publication/304131481_PSF_Introduction_to_R_Package_for_Pattern_Sequence_Based_Forecasting_Algorithm

and

https://www.researchgate.net/publication/304580701_Introduction_of_seasonality_concept_in_PSF_algorithm_to_improve_univariate_time_series_predictions

For further details contact me at: http://www.neerajbokde.com

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
__
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] r and country fixed effect modeling

2016-07-11 Thread Cristina Cametti
Dear all,

I am having problem finding a reliable code for my country fixed effects model.
I have 21 countries in my database and individuals nested within them. I am 
running a multilevel analysis first, and then I am using the fixed effects 
approach to check the robustness of my findings. At this point, I need to 
include in my model some cross-level interaction effects between the country 
level factors and individual level variables. However, I am not sure if my r 
code is right:

model1<-lm(safety ~ mixed_neigh + ethnic_neigh + age + gndr + eduyrs + domicil 
+ partner + 
   tvpol + income + victim + trust + trustXprison_pop + 
trustXforeign_pop + victimXprison_pop + 
   victimXforeign_pop + mixed_neighXprison_pop + 
mixed_neighXforeign_pop + ethnic_neighXprison_pop + 
   ethnic_neighXforeign_pop + factor(cntry)-1, data=mydata)
As you can see, the interaction are between a individual level variable (such 
as trst, victim, mixed_neigh and ethnic_neigh) and two country level variables 
(prison population and foreign population). The code runs fine, so I don�t have 
warning messages and it is all spelled correctly. I just want to know if you 
think that this is the right code to do a fixed effect analysis (only cross 
sections and not cross time). Indeed, I I used the lm and not ppm because my 
dataset is from only one year. Do you think it is correct?

Thank you very much for your attention,

Cristina 


[[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] [R-pkgs] New package: simstudy

2016-07-11 Thread Goldfeld, Keith
Greetings –

A new package “simstudy” is now available on CRAN. What started as a small 
number of functions that enabled me to quickly generate simple data sets for 
teaching and power/sample size calculations has grown into a more robust set of 
tools that allows users to simulate more complex data sets in order to explore 
modeling techniques or better understand data generating processes. The user 
specifies a set of relationships between covariates in table form (the table 
can be built interactively or created externally as a csv file), and generates 
data based on these specifications. The final data sets can represent data from 
randomized control trials, observed (non-randomized) studies, repeated measure 
(longitudinal) designs, and cluster randomized trials. Missingness can be 
generated using various mechanisms (MCAR, MAR, NMAR). Currently, data can be 
generated from normal/Gaussian, binary, Poisson, truncated Poisson, Gamma, and 
uniform distributions. Survival data can also be generated.

I will be adding functionality over time, and will be particularly interested 
in knowing what userRs would be interested in having me add. I look forward to 
hearing your comments.

- Keith


Keith Goldfeld
Department of Population Health
School of Medicine, New York University
227 East 30th Street, 6th Floor
New York, NY  10016



This email message, including any attachments, is for the sole use of the 
intended recipient(s) and may contain information that is proprietary, 
confidential, and exempt from disclosure under applicable law. Any unauthorized 
review, use, disclosure, or distribution is prohibited. If you have received 
this email in error please notify the sender by return email and delete the 
original message. Please note, the recipient should check this email and any 
attachments for the presence of viruses. The organization accepts no liability 
for any damage caused by any virus transmitted by this email.
=

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
__
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] Nloptr vs Excel GRG optimization result

2016-07-11 Thread ProfJCNash
Note the "reproducible code" directive. We cannot check your calculations.

It would not surprise me if the objective for Excel was really, really
good BUT the parameters were out of bounds or violated other constraints.

At the EUSPRIG meeting in Klagenfurt in 2004 I sat next to Dan Fijlstra
of Frontline Systems at dinner. He complained that FS had offered
Microsoft a bug fix for GRG (they supply for-money improved versions as
well as the "free" solver) and were told it wasn't wanted. Sigh.

On the other hand, I think the interface Excel provides is nicely
designed for small to medium problems.

You may also want to be very careful with the call to nloptr. It can be
tricky, rendering its results more or less meaningless.

JN


On 16-07-11 10:38 AM, Narendra Modi wrote:
> Hi All,
> For a non-linear minimization optimization problem that I have, I am
> getting better objective function value in Excel(15) as compared to
> nloptr (73).
> 
> the nloptr is setup as:
> 
> opts = list("algorithm"="NLOPT_LN_COBYLA",
> "xtol_rel"=1.0e-8, "maxeval"= 1)
> lb = vector("numeric",length= length(my.data.var))
> 
> result <- nloptr(my.data.var,eval_f = Error.func,lb=lb,
>  ub =
> c(Inf,1,1,1,1,1,Inf,1,1,1,1,1,Inf,1,1,1,1,1,Inf,1,1,1,1,1),eval_g_ineq=constraint.func,opts
> = opts)
> 
> 
> As observed even with 1 as maximum evaluations, the objective
> function is way off as compared to Excel's GRG which solved it in 200
> iterations.
> 
> Is there a way to improve the objective function value from nloptr? OR
> is there any excel's GRG equivalent package in R.
> 
> Thanks for your time!
> 
> PD
> 
> __
> 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-es] Esperanza de vida librería 'demography'

2016-07-11 Thread Javier Marcuzzi
Estimada Carmen Martinez Olmo

Yo nunca usé demography, en las dependencias no figura survival, puede ser que 
no haga falta porque los autores de dermography contemplaron el código 
necesario,  pero posiblemente con survival pueda encontrar respuestas.

Javier Rubén Marcuzzi

De: CARMEN MARTINEZ OLMO___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

[R] Nloptr vs Excel GRG optimization result

2016-07-11 Thread Narendra Modi
Hi All,
For a non-linear minimization optimization problem that I have, I am
getting better objective function value in Excel(15) as compared to
nloptr (73).

the nloptr is setup as:

opts = list("algorithm"="NLOPT_LN_COBYLA",
"xtol_rel"=1.0e-8, "maxeval"= 1)
lb = vector("numeric",length= length(my.data.var))

result <- nloptr(my.data.var,eval_f = Error.func,lb=lb,
 ub =
c(Inf,1,1,1,1,1,Inf,1,1,1,1,1,Inf,1,1,1,1,1,Inf,1,1,1,1,1),eval_g_ineq=constraint.func,opts
= opts)


As observed even with 1 as maximum evaluations, the objective
function is way off as compared to Excel's GRG which solved it in 200
iterations.

Is there a way to improve the objective function value from nloptr? OR
is there any excel's GRG equivalent package in R.

Thanks for your time!

PD

__
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] Red Neuronal complicada categorías

2016-07-11 Thread Javier Marcuzzi
Estimado Carlos Ortega

Muchas gracias por su ayuda.

Tendré que estudiar RNNS, vi muy rápido el manual y parece interesante.

Le consulto, usted genera un valor al azar a partir de 432, código set.seed(432)

¿432?, ¿lo calcula?, ¿es por experiencia?, si bien los datos son inventados y 
el resultado por más que matemáticamente de cualquier cosa me sirve para 
resolver mi pregunta, me gustaría conocer el motivo del uso de este comando, 
puesto que corrí el mismo código sin set.seed(432) y también funciona (la 
computadora no indica que falte un parámetro o problema alguno).

Javier Rubén Marcuzzi

De: Carlos Ortega
[[alternative HTML version deleted]]

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


[R] Choropleth: Turnover by ZipCode

2016-07-11 Thread G . Maubach
Hi All,
Dear Readers,

I need to create a choropleth graph with turnover by zipcode. This is what 
I have so far:

# Not run (Begin)
# Install packages if needed
# install.packages(pkgs = c("maptools", "rgdal", "RColorBrewer", 
"grDevices"))
# Not run (End)

# Load libraries
library(maptools); library(rgdal); library(RColorBrewer); 
library(grDevices)

# Configuration
# Adjust if needed!
file_path <- file.path("C:", "temp")

# Read data 
# Source: http://arnulf.us/PLZ
url <- "http://www.metaspatial.net/download/plz.tar.gz;
file_name_gzip <- basename(url)
file_name_extract <- "post_pl.shp"

download.file(url, file.path(file_path, file_name_gzip))

untar(tarfile = file.path(file_path, file_name_gzip),
  compressed = "gzip",
  exdir = file_path)

# Dataset
# I have the data for all zipcodes available in my region
ds_temp <-
  structure(
list(
  ZipCode = c(1099, 10178, 13125, 21406, 32429, 41569),
  Sales = c(4, 2, 9, 5, 7, 3),
  Revenue = c(12, 9, 100, 80, 90,
  25)
),
.Names = c("ZipCode", "Sales", "Revenue"),
row.names = c(NA,
  6L),
class = "data.frame"
  )
print(ds_temp)

# Prepare graphic
file_name_pdf <- file.path(file_path, "sales-and-revenue-by-zipcodes.pdf")
cairo_pdf(bg = "grey98", file_name_pdf, width = 16, height = 9)

y <- readShapeSpatial(file.path(file_path, file_name_extract),
  proj4string = CRS("+proj=longlat"))
x <- spTransform(y,CRS=CRS("+proj=merc"))

# How do I need to change this line?
# Needs to be replaced by turnover from ds_temp
color <- sample(1:7, length(x), replace=T) 

# Create graphic
plot(x, 
 col = brewer.pal(7, "Oranges")[color],
 border = F)  # How to I tell R to plot turnover from ds_temp?

# Title
mtext(
  "Turnover by Zipcodes",
  side = 3,
  line = -4,
  adj = 0,
  cex = 1.7
)

# Write to disc
dev.off()

# Cleanup
rm("ds_temp", "color", "file_name_extract",
   "file_name_gzip", "file_name_pdf", "file_path",
   "url", "x", "y")
unlink(file.path(file_path, "plz.tar.gz"))
unlink(file.path(file_path, "post_pl.dbf"))
unlink(file.path(file_path, "post_pl.shp"))
unlink(file.path(file_path, "post_pl.shx"))

# unlink(file.path(file_path, "sales-and-revenue-by-zipcodes.pdf"))

What do I need to do to color the amount of turnover or the frequencies of 
sales from the ds_temp dataset in the graph?

Kind regards

Georg Maubach

__
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] Esperanza de vida librería 'demography'

2016-07-11 Thread CARMEN MARTINEZ OLMO

Buenos días,

Necesito calcular la vida media de cada uno de nuestros modelos de producto 
pero tengo un histórico incompleto (para los productos más nuevos tengo la vida 
completa de las cohortes, pero para los más antiguos tengo sólo la parte final 
de la vida de las cohortes). He decidido calcular la esperanza de vida dinámica 
con un modelo actuarial, concretamente la librería 'demography' y tengo varias 
dudas sobre su uso:


1-  Todas las funciones permiten el uso por 'cohortes' y por 'períodos', 
sin embargo, cuando uso la función 'lifeexpectancy' por cohortes da error ¿cómo 
habría que preparar los datos para analizar la información por cohortes?.

2-  ¿Se puede utilizar la función 'lifeexpectancy con meses en lugar de 
años?. El resultado parece razonable pero ¿es correcto?.

3-  ¿Cómo puedo ver el error asociado al ajuste de la función 
'lifeaxpectancy'?. Para algunos períodos tengo representación de todas las 
edades, pero cuanto más antiguo el período, menos representación de edades 
'elevadas' (porque mi histórico es limitado) ¿en qué período debo poner el 
límite para mantener el error en un límite razonable?.

Ejemplo de los datos:


Pop_201210

Pop_201301

Pop_201304

Evaporation_201210

Evaporation_201301

Evaporation_201304

Month 1

 11.087

 45.497

  13.244

  0,0489

  0,0089

  0,0280

Month 2

 10.412

 44.839

  12.798

  0,0464

  0,0068

  0,0188

Month 3

   9.853

 44.273

  12.499

  0,0419

  0,0101

  0,0233

Month 4

   9.368

 43.595

  12.144

  0,0006

  0,0363

  0,0196

Month 5

   9.297

 41.812

  11.830

  0,0128

  0,0171

  0,0195

Month 6

   9.121

 40.923

  11.547

  0,0115

  0,0252

  0,0248


En este caso 201301, 201304, etc... son períodos, no cohortes.

R script:

Evap_rate<-data.frame(datos$Evaporation_201210, datos$Evaporation_201301, 
datos$Evaporation_201304)
Pop <-data.frame(datos $Pop_201210, datos $Pop_201301, datos $Pop_201304)

colnames(Evap_rate)<-c(201210,201301,201304)
colnames(Pop)<-c(201210,201301,201304)


rownames(Evap_rate)<-c(rep(1:nrow(Evap_rate)))
rownames(Pop)<-c(rep(1:nrow(Pop)))


year<-c(201210,201301,201304) ###Es correcto usar meses en lugar de años?
age<-c(1:nrow(Evap_rate))

Renov_data<-demogdata(Evap_rate, Pop ,age, year, "mortality","SPAIN","device",1)

Lte_renov<-life.expectancy(Renov_data,years=Renov_data$year, type="cohort",
  age=min(Renov_data$age))

[cid:image001.png@01D1DB6D.E8E90AC0]###Por qué el resultado cuando uso el 
tipo 'cohort' es NA?







Este mensaje y sus adjuntos se dirigen exclusivamente a su destinatario, puede 
contener información privilegiada o confidencial y es para uso exclusivo de la 
persona o entidad de destino. Si no es usted. el destinatario indicado, queda 
notificado de que la lectura, utilización, divulgación y/o copia sin 
autorización puede estar prohibida en virtud de la legislación vigente. Si ha 
recibido este mensaje por error, le rogamos que nos lo comunique inmediatamente 
por esta misma vía y proceda a su destrucción.

The information contained in this transmission is privileged and confidential 
information intended only for the use of the individual or entity named above. 
If the reader of this message is not the intended recipient, you are hereby 
notified that any dissemination, distribution or copying of this communication 
is strictly prohibited. If you have received this transmission in error, do not 
read it. Please immediately reply to the sender that you have received this 
communication in error and then delete it.

Esta mensagem e seus anexos se dirigem exclusivamente ao seu destinatário, pode 
conter informação privilegiada ou confidencial e é para uso exclusivo da pessoa 
ou entidade de destino. Se não é vossa senhoria o destinatário indicado, fica 
notificado de que a leitura, utilização, divulgação e/ou cópia sem autorização 
pode estar proibida em virtude da legislação vigente. Se recebeu esta mensagem 
por erro, rogamos-lhe que nos o comunique imediatamente por esta mesma via e 
proceda a sua destruição
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es