Re: [R] overlaying frequency histograms or density plots in R

2021-02-25 Thread Bogdan Tanasa
Dear Rui, and Petr,

many many thanks for your time and advice ! 'm still exploring the R code
that you have suggested !

On Thu, Feb 25, 2021 at 2:59 AM Rui Barradas  wrote:

> Hello,
>
> First of all, I believe you want argument fill, not colour. In ggplot2
> colour is about the border and fill about the interior.
>
> As for the question,
>
> 1. Create a basic plot with the common aesthetics.
>
>
> library(ggplot2)
>
> pp_ALL <- iris[c(1, 5)]
> names(pp_ALL) <- c("VALUE", "EXP")
>
> p <- ggplot(data = pp_ALL, mapping = aes(x = VALUE, fill = EXP))
>
>
>
> 2. geom_density should use alpha transparency, since the densities
> overlap. colour = NA removes the densities black border.
>
>
> p + geom_density(alpha = 0.5, colour = NA)
>
>
> 3. y = ..density.. plots relative frequencies histograms, for the
> default absolute frequencies or counts, comment the mapping out.
>
> position = position_dodge() allows for extra goodies, such as to change
> the space between bars, their width or to keep empty spaces when some
> factor levels are missing (preserve = "single").
>
> For the test data, with 50 elements per factor level, use a much smaller
> number of bins.
>
> Package scales has functions to display labels in percent format, there
> is no need to multiply by 100.
>
>
> p + geom_histogram(
>mapping = aes(y = ..density..),
>position = position_dodge(),
>bins = 10)
>
> p + geom_histogram(
>mapping = aes(y = ..density..),
>position = position_dodge(),
>bins = 10) +
>scale_y_continuous(labels = scales::label_percent())
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Às 07:43 de 25/02/21, Bogdan Tanasa escreveu:
> > Thanks a lot Petr !
> >
> > shall i uses "dodge" also for the RELATIVE FREQUENCY HISTOGRAMS :
> >
> > p <- ggplot(iris, aes(x=Sepal.Length, y=..count../sum(..count..)*100,
> > colour=Species))
> > p+geom_histogram(position="dodge")
> >
> > or is there any other way to display the RELATIVE FREQUENCY HISTOGRAMS ?
> >
> > thanks again !
> >
> > On Wed, Feb 24, 2021 at 11:00 PM PIKAL Petr 
> wrote:
> >
> >> Hi
> >>
> >> You should use position dodge.
> >>
> >> p <- ggplot(iris, aes(x=Sepal.Length, colour=Species))
> >> p+geom_density()
> >> p <- ggplot(iris, aes(x=Sepal.Length, y=..density.., colour=Species))
> >> p+geom_histogram(position="dodge")
> >>
> >> Cheers
> >> Petr
> >>> -Original Message-
> >>> From: R-help  On Behalf Of Bogdan Tanasa
> >>> Sent: Wednesday, February 24, 2021 11:07 PM
> >>> To: r-help 
> >>> Subject: [R] overlaying frequency histograms or density plots in R
> >>>
> >>> Dear all, we do have a dataframe with a FACTOR called EXP that has 3
> >> LEVELS ;
> >>>
> >>>   head(pp_ALL)
> >>>  VALUE  EXP
> >>> 1 1639742 DMSO
> >>> 2 1636822 DMSO
> >>> 3 1634202 DMSO
> >>>
> >>> shall i aim to overlay the relative frequency histograms, or the
> density
> >>> histograms for the FACTOR LEVELS,
> >>>
> >>> please would you let me know why the following 2 pieces of R code show
> >>> very different results :
> >>>
> >>> ggplot(pp_ALL, aes(x=VALUE, colour=EXP)) + geom_density()
> >>>
> >>> versus
> >>>
> >>> ggplot(data=pp_ALL) +
> >>> geom_histogram(mapping=aes(x=VALUE, y=..density.., colour=EXP),
> >>>   bins=1000)
> >>>
> >>> thanks,
> >>>
> >>> bogdan
> >>>
> >>> ps : perhaps i shall email to the folks on ggplot2 mailing list too ...
> >>>
> >>>[[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.
> >>
> >
> >   [[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.
> >
>

[[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-es] Fwd: Dos cuestiones relacionadas con rpart y printcp

2021-02-25 Thread Manuel Mendoza
-- Forwarded message -
De: Manuel Mendoza 
Date: mié, 24 feb 2021 a las 18:59
Subject: Dos cuestiones relacionadas con rpart y printcp
To: Lista R 


Muy buenas, tengo dos cuestiones relacionadas con  rpart para regresión y
printcp.
Entreno el algoritmo con  fitrp <- rpart(nspp ~ ., data=data, cp=0)
y obtengo el error relativo, xerror, del mejor árbol con
min(fitrp$cptable[,"xerror"]).
Hasta ahí muy fácil.

1. Para calcular mse, multiplico ese valor de xerror por el error del nodo
raíz.
¿es correcto?

2. Necesito el % de varianza (R2) de la variable objetivo explicada por el
mejor árbol, pero no está en ninguno de los objetos incluídos fitrp.
En la documentación encontré que rsq.rpart(fitrp) te representa
directamente la evolución de R2 tal y como se van añadiendo nuevas
divisiones (también te representa la evolución de xerror, pero esa ya la
tenía con plotcp(fitrp)).
Mi pregunta es:
¿cómo puedo obtener esa secuencia de valores de R2, cuyo máximo sería el R2
que busco?
Gracias, una vez más,
Manuel

[[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] Out from an R package

2021-02-25 Thread John Fox

Dear Goran,

It's not clear from your question what you want to do, but my guess is 
that you simply what a "printout" of your results. The usual way to 
obtain that is via the summary() function. In your case summary(Output).


That's typical of statistical modeling functions in R: They return 
objects, which can be used for further computing, rather than directly 
producing printouts.


If my guess is correct, then you probably should learn more about 
statistical modeling in R, and about R in general, before using it in 
your work.


One more thing: I doubt whether the command

Output <- lmer(G10ln ~ v191_ms + (1 | couno), data = 'G10R')

actually works. The data argument should be a data frame, not the *name* 
of a data frame, i.e., data = G10R .


I hope this helps,
 John

John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/


On 2021-02-25 10:24 a.m., Göran Djurfeldt wrote:

Help! I am going crazy for a very simple reason. I can’t access the output from 
for instance the lme4 package in R. I have been able to import an SPSS file 
into an R data frame. I have downloaded and installed the Lme4 package and I 
think I have also learnt how to produce a mixed model with lmer:

Output <- lmer(G10ln ~ v191_ms + (1 | couno), data = 'G10R')

How shall I define the output from lmer? What kind of object is it? How do I 
define it?

Goran

[[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] Out from an R package

2021-02-25 Thread Eric Berger
The str() function is your friend. Try
str(Output)


On Thu, Feb 25, 2021 at 12:09 PM David Winsemius 
wrote:

>
> On 2/25/21 7:24 AM, Göran Djurfeldt wrote:
> > Help! I am going crazy for a very simple reason. I can’t access the
> output from for instance the lme4 package in R. I have been able to import
> an SPSS file into an R data frame. I have downloaded and installed the Lme4
> package and I think I have also learnt how to produce a mixed model with
> lmer:
> >
> > Output <- lmer(G10ln ~ v191_ms + (1 | couno), data = 'G10R')
> >
> > How shall I define the output from lmer? What kind of object is it? How
> do I define it?
>
> I'm not sure what you mean by "How do I define" the output from a
> function. The function does the "definition", but you can correctly
> refer to the output of most regression functions as "a list". The best
> way to get the specific result from a function is to go to its help page
> and look at the Details and Values sections.
>
>
> --
>
> David.
>
> >
> > Goran
> >
> >   [[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.
>

[[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-es] Codificar ecuación no lineal

2021-02-25 Thread Luis Eduardo
Hola a todos, ¿cómo puedo codificar correctamente esta ecuación en R?

y <- Σi=3 ((1+sing(t-ti)) /2) *Bi*{1-exp[-ai*((t-ti) / ∆ti) ^(mi+1)]}
n=3
donde para t> ti; sign(t-ti) = 1, de lo contrario; sign(t-ti) = - 1;
limitar el parámetro (ai) entre 2,3 y 6,9;
B1 + B2 + B3 = 1

Cualquier ayuda es muy apreciada

[[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] time as a continuous factor in a linear mixed effects model

2021-02-25 Thread Bert Gunter
You should post this on the r-sig-mixed-models list rather than here.


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Feb 25, 2021 at 9:20 AM Laura Coco  wrote:

> Hello,
>
> I am interested in investigating the main effects of group, time, and group
> by time interaction on survey outcomes using linear mixed effects models.
> Time is considered as continuous (number of days since baseline), but isn't
> it also categorical, since I want to compare Session 1 vs Session 4 (for
> example)? How is that handled in the model? As of now, time (days since
> baseline) is being treated as one unit, rather than four separate sessions.
>
> Here is an example of my code: mdl.outcome <- lmer(outcome ~ time*Group +
> (1 | PID), data = dta)
>
> Thank you!!
> laura
>
> [[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.
>

[[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] time as a continuous factor in a linear mixed effects model

2021-02-25 Thread Laura Coco
Hello,

I am interested in investigating the main effects of group, time, and group
by time interaction on survey outcomes using linear mixed effects models.
Time is considered as continuous (number of days since baseline), but isn't
it also categorical, since I want to compare Session 1 vs Session 4 (for
example)? How is that handled in the model? As of now, time (days since
baseline) is being treated as one unit, rather than four separate sessions.

Here is an example of my code: mdl.outcome <- lmer(outcome ~ time*Group +
(1 | PID), data = dta)

Thank you!!
laura

[[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] Out from an R package

2021-02-25 Thread David Winsemius



On 2/25/21 7:24 AM, Göran Djurfeldt wrote:

Help! I am going crazy for a very simple reason. I can’t access the output from 
for instance the lme4 package in R. I have been able to import an SPSS file 
into an R data frame. I have downloaded and installed the Lme4 package and I 
think I have also learnt how to produce a mixed model with lmer:

Output <- lmer(G10ln ~ v191_ms + (1 | couno), data = 'G10R')

How shall I define the output from lmer? What kind of object is it? How do I 
define it?


I'm not sure what you mean by "How do I define" the output from a 
function. The function does the "definition", but you can correctly 
refer to the output of most regression functions as "a list". The best 
way to get the specific result from a function is to go to its help page 
and look at the Details and Values sections.



--

David.



Goran

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


[R] Out from an R package

2021-02-25 Thread Göran Djurfeldt
Help! I am going crazy for a very simple reason. I can’t access the output from 
for instance the lme4 package in R. I have been able to import an SPSS file 
into an R data frame. I have downloaded and installed the Lme4 package and I 
think I have also learnt how to produce a mixed model with lmer:

Output <- lmer(G10ln ~ v191_ms + (1 | couno), data = 'G10R')

How shall I define the output from lmer? What kind of object is it? How do I 
define it?

Goran

[[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] overlaying frequency histograms or density plots in R

2021-02-25 Thread Rui Barradas

Hello,

First of all, I believe you want argument fill, not colour. In ggplot2 
colour is about the border and fill about the interior.


As for the question,

1. Create a basic plot with the common aesthetics.


library(ggplot2)

pp_ALL <- iris[c(1, 5)]
names(pp_ALL) <- c("VALUE", "EXP")

p <- ggplot(data = pp_ALL, mapping = aes(x = VALUE, fill = EXP))



2. geom_density should use alpha transparency, since the densities 
overlap. colour = NA removes the densities black border.



p + geom_density(alpha = 0.5, colour = NA)


3. y = ..density.. plots relative frequencies histograms, for the 
default absolute frequencies or counts, comment the mapping out.


position = position_dodge() allows for extra goodies, such as to change 
the space between bars, their width or to keep empty spaces when some 
factor levels are missing (preserve = "single").


For the test data, with 50 elements per factor level, use a much smaller 
number of bins.


Package scales has functions to display labels in percent format, there 
is no need to multiply by 100.



p + geom_histogram(
  mapping = aes(y = ..density..),
  position = position_dodge(),
  bins = 10)

p + geom_histogram(
  mapping = aes(y = ..density..),
  position = position_dodge(),
  bins = 10) +
  scale_y_continuous(labels = scales::label_percent())


Hope this helps,

Rui Barradas


Às 07:43 de 25/02/21, Bogdan Tanasa escreveu:

Thanks a lot Petr !

shall i uses "dodge" also for the RELATIVE FREQUENCY HISTOGRAMS :

p <- ggplot(iris, aes(x=Sepal.Length, y=..count../sum(..count..)*100,
colour=Species))
p+geom_histogram(position="dodge")

or is there any other way to display the RELATIVE FREQUENCY HISTOGRAMS ?

thanks again !

On Wed, Feb 24, 2021 at 11:00 PM PIKAL Petr  wrote:


Hi

You should use position dodge.

p <- ggplot(iris, aes(x=Sepal.Length, colour=Species))
p+geom_density()
p <- ggplot(iris, aes(x=Sepal.Length, y=..density.., colour=Species))
p+geom_histogram(position="dodge")

Cheers
Petr

-Original Message-
From: R-help  On Behalf Of Bogdan Tanasa
Sent: Wednesday, February 24, 2021 11:07 PM
To: r-help 
Subject: [R] overlaying frequency histograms or density plots in R

Dear all, we do have a dataframe with a FACTOR called EXP that has 3

LEVELS ;


  head(pp_ALL)
 VALUE  EXP
1 1639742 DMSO
2 1636822 DMSO
3 1634202 DMSO

shall i aim to overlay the relative frequency histograms, or the density
histograms for the FACTOR LEVELS,

please would you let me know why the following 2 pieces of R code show
very different results :

ggplot(pp_ALL, aes(x=VALUE, colour=EXP)) + geom_density()

versus

ggplot(data=pp_ALL) +
geom_histogram(mapping=aes(x=VALUE, y=..density.., colour=EXP),
  bins=1000)

thanks,

bogdan

ps : perhaps i shall email to the folks on ggplot2 mailing list too ...

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




[[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] overlaying frequency histograms or density plots in R

2021-02-25 Thread PIKAL Petr
Hi.



My understanding is that position dodge places each bar in each histogram 
beside each other and position stack places all respective bars atop each 
other.



Relative frequency is something different.



Cheers

Petr



From: Bogdan Tanasa 
Sent: Thursday, February 25, 2021 8:43 AM
To: PIKAL Petr 
Cc: r-help 
Subject: Re: [R] overlaying frequency histograms or density plots in R



Thanks a lot Petr !



shall i uses "dodge" also for the RELATIVE FREQUENCY HISTOGRAMS :



p <- ggplot(iris, aes(x=Sepal.Length, y=..count../sum(..count..)*100, 
colour=Species))
p+geom_histogram(position="dodge")



or is there any other way to display the RELATIVE FREQUENCY HISTOGRAMS ?



thanks again !



On Wed, Feb 24, 2021 at 11:00 PM PIKAL Petr mailto:petr.pi...@precheza.cz> > wrote:

Hi

You should use position dodge.

p <- ggplot(iris, aes(x=Sepal.Length, colour=Species))
p+geom_density()
p <- ggplot(iris, aes(x=Sepal.Length, y=..density.., colour=Species))
p+geom_histogram(position="dodge")

Cheers
Petr
> -Original Message-
> From: R-help   > On Behalf Of Bogdan Tanasa
> Sent: Wednesday, February 24, 2021 11:07 PM
> To: r-help mailto:r-help@r-project.org> >
> Subject: [R] overlaying frequency histograms or density plots in R
>
> Dear all, we do have a dataframe with a FACTOR called EXP that has 3
LEVELS ;
>
>  head(pp_ALL)
> VALUE  EXP
> 1 1639742 DMSO
> 2 1636822 DMSO
> 3 1634202 DMSO
>
> shall i aim to overlay the relative frequency histograms, or the density
> histograms for the FACTOR LEVELS,
>
> please would you let me know why the following 2 pieces of R code show
> very different results :
>
> ggplot(pp_ALL, aes(x=VALUE, colour=EXP)) + geom_density()
>
> versus
>
> ggplot(data=pp_ALL) +
>geom_histogram(mapping=aes(x=VALUE, y=..density.., colour=EXP),
>  bins=1000)
>
> thanks,
>
> bogdan
>
> ps : perhaps i shall email to the folks on ggplot2 mailing list too ...
>
>   [[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.