Re: [R] [External Email] Re: how to make the far right section of a smoother line look different from the rest of that line?

2021-11-16 Thread Bert Gunter
Well, of course Deepayan is right. But perhaps worth noting is that the
U.S. government and presumably many others publishes tons of economic
estimates of time series that are revised as later data comes in --
employment statistics were a recent prominent example that made the news.

I leave it to the OP to figure out how he wants to deal with these
statistical realities. The simple truth is that simple truth may be
unattainable.

Best,
Bert


On Tue, Nov 16, 2021 at 9:44 PM Deepayan Sarkar 
wrote:

> On Wed, Nov 17, 2021 at 1:04 AM Christopher W Ryan via R-help
>  wrote:
> >
> > Thanks Bert, that looks promising.
> >
> > panel.smoother() is from latticeExtra
> >
> > https://rdrr.io/cran/latticeExtra/man/panel.smoother.html
>
> I'm a bit unsure about your premise. If I understand correctly, the
> data for the last week is incomplete and may change. When it does, the
> loess smooth is potentially affected for the preceding weeks as well
> (in your case, with span = 0.3, upto around 30% of the preceding
> weeks). So wouldn't it be misleading to suggest that the smoother
> lines are "tentative" only for the last week or two?
>
> It makes more sense to me to just highlight the last data point as
> (potentially) incomplete.
>
> Best,
> -Deepayan
>
> > --Chris Ryan
> >
> > On Tue, Nov 16, 2021 at 2:08 PM Bert Gunter 
> wrote:
> >
> > > Where did you get panel.smoother()? There is no such panel function in
> > > lattice.
> > >
> > > Is something like this what you want?
> > >
> > > x <- 1:100
> > > y <- rnorm(100, mean =5)
> > > end <- 91 # tentative smooth after this
> > > xyplot(y ~x, cutoff = end, col1 = "black", col2 = "red"
> > >, panel = function(x, y,  col1, col2, cutoff) {
> > >   sqleft <- seq_len(cutoff)
> > >   sqright <- seq.int(cutoff +1, length(x))
> > >   col <- rep(c(col1,col2), times = c(cutoff, length(x) -
> cutoff))
> > >   panel.points(x, y, col = col)
> > >   ylo <- predict(loess(y ~ x))
> > >   panel.lines(x[sqleft], ylo[sqleft], col = col1, lwd =2)
> > >   panel.lines(x[sqright], ylo[sqright], col = col2, lwd = 2,
> lty =
> > > "dotted")
> > >})
> > >
> > > Notes:
> > > 1. This works because of loess default to predict at given x's. Modify
> as
> > > required if you change to another smoother or wish to use different
> points
> > > at which to plot the smoother.
> > > 2. This can almost certainly be done by creating a grouping variable to
> > > separate the two plotting regimes and might be slicker and more robust
> with
> > > that approach.
> > >
> > >
> > > 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 Tue, Nov 16, 2021 at 7:45 AM Christopher W Ryan via R-help <
> > > r-help@r-project.org> wrote:
> > >
> > >> eclrs.3 %>%
> > >> mutate(start.week = floor_date(realCollectionDate, unit = "week")) %>%
> > >> group_by(start.week, k12) %>%
> > >> summarise(n = n(), pctpos = 100 * mean(realResult))  %>%
> > >> xyplot(pctpos ~ start.week | k12, col = "red", data = ., layout =
> c(1,2),
> > >> ylab = "percent of test results positive", xlab = "specimen collection
> > >> date",  strip = strip.custom(strip.names = c(TRUE, TRUE)),  sub = "The
> > >> final week shown may not yet be complete so is likely inaccurate",
>  panel
> > >> = function(...){
> > >> panel.xyplot(..., type = "p", cex = 0.8)
> > >> panel.smoother(..., span = 0.3, col.se = "red", alpha.se = 0.08,
> lwd
> > >> =
> > >> 2)})
> > >>
> > >> The above takes patient-level data, each record containing a date, and
> > >> aggregates them by week according to that date, then plots 2 weekly
> time
> > >> series, one for k12 and one for not-k12, each with a smoother. Note my
> > >> disclaimer in the subtitle that "the final week shown may not yet be
> > >> complete . . . ." since I might run this on any arbitrary day. How
> might I
> > >> change the appearance of the smoother lines to emphasize to the viewer
> > >> that
> > >> the recent trends are tentative due to daily data still coming in?
> For
> > >> example, how might I make the far right-end stretch of the lines,
> > >> representing the most recent week or two, dotted?
> > >>
> > >> Thanks.
> > >>
> > >> --Chris Ryan
> > >>
> > >> [[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
> > 

Re: [R] [External Email] Re: how to make the far right section of a smoother line look different from the rest of that line?

2021-11-16 Thread Deepayan Sarkar
On Wed, Nov 17, 2021 at 1:04 AM Christopher W Ryan via R-help
 wrote:
>
> Thanks Bert, that looks promising.
>
> panel.smoother() is from latticeExtra
>
> https://rdrr.io/cran/latticeExtra/man/panel.smoother.html

I'm a bit unsure about your premise. If I understand correctly, the
data for the last week is incomplete and may change. When it does, the
loess smooth is potentially affected for the preceding weeks as well
(in your case, with span = 0.3, upto around 30% of the preceding
weeks). So wouldn't it be misleading to suggest that the smoother
lines are "tentative" only for the last week or two?

It makes more sense to me to just highlight the last data point as
(potentially) incomplete.

Best,
-Deepayan

> --Chris Ryan
>
> On Tue, Nov 16, 2021 at 2:08 PM Bert Gunter  wrote:
>
> > Where did you get panel.smoother()? There is no such panel function in
> > lattice.
> >
> > Is something like this what you want?
> >
> > x <- 1:100
> > y <- rnorm(100, mean =5)
> > end <- 91 # tentative smooth after this
> > xyplot(y ~x, cutoff = end, col1 = "black", col2 = "red"
> >, panel = function(x, y,  col1, col2, cutoff) {
> >   sqleft <- seq_len(cutoff)
> >   sqright <- seq.int(cutoff +1, length(x))
> >   col <- rep(c(col1,col2), times = c(cutoff, length(x) - cutoff))
> >   panel.points(x, y, col = col)
> >   ylo <- predict(loess(y ~ x))
> >   panel.lines(x[sqleft], ylo[sqleft], col = col1, lwd =2)
> >   panel.lines(x[sqright], ylo[sqright], col = col2, lwd = 2, lty =
> > "dotted")
> >})
> >
> > Notes:
> > 1. This works because of loess default to predict at given x's. Modify as
> > required if you change to another smoother or wish to use different points
> > at which to plot the smoother.
> > 2. This can almost certainly be done by creating a grouping variable to
> > separate the two plotting regimes and might be slicker and more robust with
> > that approach.
> >
> >
> > 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 Tue, Nov 16, 2021 at 7:45 AM Christopher W Ryan via R-help <
> > r-help@r-project.org> wrote:
> >
> >> eclrs.3 %>%
> >> mutate(start.week = floor_date(realCollectionDate, unit = "week")) %>%
> >> group_by(start.week, k12) %>%
> >> summarise(n = n(), pctpos = 100 * mean(realResult))  %>%
> >> xyplot(pctpos ~ start.week | k12, col = "red", data = ., layout = c(1,2),
> >> ylab = "percent of test results positive", xlab = "specimen collection
> >> date",  strip = strip.custom(strip.names = c(TRUE, TRUE)),  sub = "The
> >> final week shown may not yet be complete so is likely inaccurate",   panel
> >> = function(...){
> >> panel.xyplot(..., type = "p", cex = 0.8)
> >> panel.smoother(..., span = 0.3, col.se = "red", alpha.se = 0.08, lwd
> >> =
> >> 2)})
> >>
> >> The above takes patient-level data, each record containing a date, and
> >> aggregates them by week according to that date, then plots 2 weekly time
> >> series, one for k12 and one for not-k12, each with a smoother. Note my
> >> disclaimer in the subtitle that "the final week shown may not yet be
> >> complete . . . ." since I might run this on any arbitrary day. How might I
> >> change the appearance of the smoother lines to emphasize to the viewer
> >> that
> >> the recent trends are tentative due to daily data still coming in?  For
> >> example, how might I make the far right-end stretch of the lines,
> >> representing the most recent week or two, dotted?
> >>
> >> Thanks.
> >>
> >> --Chris Ryan
> >>
> >> [[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.


[R] How to create a proper S4 class?

2021-11-16 Thread Leonard Mada via R-help

Dear List-Members,


I want to create an S4 class with 2 data slots, as well as a plot and a 
line method.



Unfortunately I lack any experience with S4 classes. I have put together 
some working code - but I presume that it is not the best way to do it. 
The actual code is also available on Github (see below).



1.) S4 class
- should contain 2 data slots:
Slot 1: the agents:
 = agentMatrix class (defined externally, NetlogoR S4 class);
Slot 2: the path traveled by the agents:
  = a data frame: (x, y, id);
 - my current code: defines only the agents ("t");
setClass("agentsWithPath", contains = c(t="agentMatrix"));

1.b.) Attribute with colors specific for each agent
- should be probably an attribute attached to the agentMatrix and not a 
proper data slot;

Note:
- it is currently an attribute on the path data.frame, but I will 
probably change this once I get the S4 class properly implemented;
- the agentMatrix does NOT store the colors (which are stored in another 
class - but it is useful to have this information available with the 
agents);


2.) plot & line methods for this class
plot.agentsWithPath;
lines.agentsWithPath;


I somehow got stuck with the S4 class definition. Though it may be a 
good opportunity to learn about S4 classes (and it is probably better 
suited as an S4 class than polynomials).



The GitHub code draws the agents, but was somehow hacked together. For 
anyone interested:


https://github.com/discoleo/R/blob/master/Stat/ABM.Models.Particles.R


Many thanks,


Leonard

__
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] [External Email] Re: how to make the far right section of a smoother line look different from the rest of that line?

2021-11-16 Thread Christopher W Ryan via R-help
Thanks Bert, that looks promising.

panel.smoother() is from latticeExtra

https://rdrr.io/cran/latticeExtra/man/panel.smoother.html

--Chris Ryan

On Tue, Nov 16, 2021 at 2:08 PM Bert Gunter  wrote:

> Where did you get panel.smoother()? There is no such panel function in
> lattice.
>
> Is something like this what you want?
>
> x <- 1:100
> y <- rnorm(100, mean =5)
> end <- 91 # tentative smooth after this
> xyplot(y ~x, cutoff = end, col1 = "black", col2 = "red"
>, panel = function(x, y,  col1, col2, cutoff) {
>   sqleft <- seq_len(cutoff)
>   sqright <- seq.int(cutoff +1, length(x))
>   col <- rep(c(col1,col2), times = c(cutoff, length(x) - cutoff))
>   panel.points(x, y, col = col)
>   ylo <- predict(loess(y ~ x))
>   panel.lines(x[sqleft], ylo[sqleft], col = col1, lwd =2)
>   panel.lines(x[sqright], ylo[sqright], col = col2, lwd = 2, lty =
> "dotted")
>})
>
> Notes:
> 1. This works because of loess default to predict at given x's. Modify as
> required if you change to another smoother or wish to use different points
> at which to plot the smoother.
> 2. This can almost certainly be done by creating a grouping variable to
> separate the two plotting regimes and might be slicker and more robust with
> that approach.
>
>
> 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 Tue, Nov 16, 2021 at 7:45 AM Christopher W Ryan via R-help <
> r-help@r-project.org> wrote:
>
>> eclrs.3 %>%
>> mutate(start.week = floor_date(realCollectionDate, unit = "week")) %>%
>> group_by(start.week, k12) %>%
>> summarise(n = n(), pctpos = 100 * mean(realResult))  %>%
>> xyplot(pctpos ~ start.week | k12, col = "red", data = ., layout = c(1,2),
>> ylab = "percent of test results positive", xlab = "specimen collection
>> date",  strip = strip.custom(strip.names = c(TRUE, TRUE)),  sub = "The
>> final week shown may not yet be complete so is likely inaccurate",   panel
>> = function(...){
>> panel.xyplot(..., type = "p", cex = 0.8)
>> panel.smoother(..., span = 0.3, col.se = "red", alpha.se = 0.08, lwd
>> =
>> 2)})
>>
>> The above takes patient-level data, each record containing a date, and
>> aggregates them by week according to that date, then plots 2 weekly time
>> series, one for k12 and one for not-k12, each with a smoother. Note my
>> disclaimer in the subtitle that "the final week shown may not yet be
>> complete . . . ." since I might run this on any arbitrary day. How might I
>> change the appearance of the smoother lines to emphasize to the viewer
>> that
>> the recent trends are tentative due to daily data still coming in?  For
>> example, how might I make the far right-end stretch of the lines,
>> representing the most recent week or two, dotted?
>>
>> Thanks.
>>
>> --Chris Ryan
>>
>> [[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.


Re: [R] how to make the far right section of a smoother line look different from the rest of that line?

2021-11-16 Thread Bert Gunter
Where did you get panel.smoother()? There is no such panel function in
lattice.

Is something like this what you want?

x <- 1:100
y <- rnorm(100, mean =5)
end <- 91 # tentative smooth after this
xyplot(y ~x, cutoff = end, col1 = "black", col2 = "red"
   , panel = function(x, y,  col1, col2, cutoff) {
  sqleft <- seq_len(cutoff)
  sqright <- seq.int(cutoff +1, length(x))
  col <- rep(c(col1,col2), times = c(cutoff, length(x) - cutoff))
  panel.points(x, y, col = col)
  ylo <- predict(loess(y ~ x))
  panel.lines(x[sqleft], ylo[sqleft], col = col1, lwd =2)
  panel.lines(x[sqright], ylo[sqright], col = col2, lwd = 2, lty =
"dotted")
   })

Notes:
1. This works because of loess default to predict at given x's. Modify as
required if you change to another smoother or wish to use different points
at which to plot the smoother.
2. This can almost certainly be done by creating a grouping variable to
separate the two plotting regimes and might be slicker and more robust with
that approach.


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 Tue, Nov 16, 2021 at 7:45 AM Christopher W Ryan via R-help <
r-help@r-project.org> wrote:

> eclrs.3 %>%
> mutate(start.week = floor_date(realCollectionDate, unit = "week")) %>%
> group_by(start.week, k12) %>%
> summarise(n = n(), pctpos = 100 * mean(realResult))  %>%
> xyplot(pctpos ~ start.week | k12, col = "red", data = ., layout = c(1,2),
> ylab = "percent of test results positive", xlab = "specimen collection
> date",  strip = strip.custom(strip.names = c(TRUE, TRUE)),  sub = "The
> final week shown may not yet be complete so is likely inaccurate",   panel
> = function(...){
> panel.xyplot(..., type = "p", cex = 0.8)
> panel.smoother(..., span = 0.3, col.se = "red", alpha.se = 0.08, lwd =
> 2)})
>
> The above takes patient-level data, each record containing a date, and
> aggregates them by week according to that date, then plots 2 weekly time
> series, one for k12 and one for not-k12, each with a smoother. Note my
> disclaimer in the subtitle that "the final week shown may not yet be
> complete . . . ." since I might run this on any arbitrary day. How might I
> change the appearance of the smoother lines to emphasize to the viewer that
> the recent trends are tentative due to daily data still coming in?  For
> example, how might I make the far right-end stretch of the lines,
> representing the most recent week or two, dotted?
>
> Thanks.
>
> --Chris Ryan
>
> [[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] how to make the far right section of a smoother line look different from the rest of that line?

2021-11-16 Thread Christopher W Ryan via R-help
eclrs.3 %>%
mutate(start.week = floor_date(realCollectionDate, unit = "week")) %>%
group_by(start.week, k12) %>%
summarise(n = n(), pctpos = 100 * mean(realResult))  %>%
xyplot(pctpos ~ start.week | k12, col = "red", data = ., layout = c(1,2),
ylab = "percent of test results positive", xlab = "specimen collection
date",  strip = strip.custom(strip.names = c(TRUE, TRUE)),  sub = "The
final week shown may not yet be complete so is likely inaccurate",   panel
= function(...){
panel.xyplot(..., type = "p", cex = 0.8)
panel.smoother(..., span = 0.3, col.se = "red", alpha.se = 0.08, lwd =
2)})

The above takes patient-level data, each record containing a date, and
aggregates them by week according to that date, then plots 2 weekly time
series, one for k12 and one for not-k12, each with a smoother. Note my
disclaimer in the subtitle that "the final week shown may not yet be
complete . . . ." since I might run this on any arbitrary day. How might I
change the appearance of the smoother lines to emphasize to the viewer that
the recent trends are tentative due to daily data still coming in?  For
example, how might I make the far right-end stretch of the lines,
representing the most recent week or two, dotted?

Thanks.

--Chris Ryan

[[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] How to use contour plot?

2021-11-16 Thread Ivan Krylov
On Tue, 16 Nov 2021 09:45:34 +0100
Luigi Marongiu  wrote:

> contour(df$X, df$Y, df$Z)  

contour() works on matrices (sometimes called "wide format" data). Z
must be a numeric matrix, X must be a numeric vector with length(X) ==
nrow(Z), and Y must be a numeric vector with length(Y) == ncol(Z). This
is described in ?contour.

Since you have a three-column data.frame ("long format" data), you can
use lattice::contourplot instead (e.g. contourplot(Z ~ X + Y, data =
df)) or the appropriate combination of ggplot2 functions.

Alternatively, if your data is already on a grid, you can make a matrix
out of your three-column data.frame, but the procedure is a bit awkward:

ret <- reshape(
 df, direction = "wide", v.names = 'Z', idvar = 'X', timevar = 'Y'
)
contour(
 X <- ret[, 1],
 Y <- attr(ret, "reshapeWide")$times,
 Z <- as.matrix(ret[,-1])
)

(Can be also done with xtabs(); reshape2 and many other contributed
packages also offer some ways of doing that.)

-- 
Best regards,
Ivan

__
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 use contour plot?

2021-11-16 Thread Duncan Murdoch

On 16/11/2021 3:45 a.m., Luigi Marongiu wrote:

Hello,
I have a dataframe with 3 values and that I would like to plot with contour:
```

head(df)

Y   X  Z
1 0.0008094667  50 1
2 0.0012360955  50 1
3 0.0016627243  50 1
4 0.0020893531  50 1
5 0.0025159819  50 1
6 0.0029426108  50 1

contour(df$X, df$Y, df$Z)

Error in contour.default(df$X, df$Y, df$Z) :
increasing 'x' and 'y' values expected
```
Y is increasing, whereas X is decreasing. How shall I set the function?
Thank you



Contour needs the Z data in a grid, with the X and Y data corresponding 
to rows and columns.  The interp::interp() function in the interp 
package should be able to convert your data to this format; see its help 
page.  An alternative is the akima::interp() function, which may have 
licensing issues.


Duncan Murdoch

__
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 run prop.test on 3-level factors?

2021-11-16 Thread Jim Lemon
Hi Luigi,
Maybe multinomial regression?

https://www.r-bloggers.com/2020/05/multinomial-logistic-regression-with-r/

Jim

On Tue, Nov 16, 2021 at 7:33 PM Luigi Marongiu  wrote:
>
> Hello,
> I have a large database with a column containing a factor:
> ```
> > str(df)
> 'data.frame': 500 obs. of  4 variables:
> $ MR   : num  0.000809 0.001236 0.001663 0.002089 0.002516 ...
> $ FCN  : num  2 2 2 2 2 2 2 2 2 2 ...
> $ Class: Factor w/ 3 levels "negative","positive",..: 1 1 1 1 1 1 1 1 1 1 ...
> $ Set  : int  1 1 1 1 1 1 1 1 1 1 ...
> - attr(*, "out.attrs")=List of 2
> ..$ dim : Named int [1:2] 1000 1000
> .. ..- attr(*, "names")= chr [1:2] "X1" "X2"
> ..$ dimnames:List of 2
> .. ..$ X1: chr [1:1000] "X1=0.0008094667" "X1=0.0012360955"
> "X1=0.0016627243" "X1=0.0020893531" ...
> .. ..$ X2: chr [1:1000] "X2= 2.00" "X2= 2.048048" "X2= 2.096096"
> "X2= 2.144144" ...
> ```
> I would like to run prop.test on df$Class, but:
> ```
> > prop.test(x=point$Class, n=length(point$Class),
> + conf.level=.95, correct=FALSE)
> Error in prop.test(x = point$Class, n = length(point$Class),
> conf.level = 0.95,  :
> 'x' and 'n' must have the same length
> ```
> Since `x` is "a vector of counts of successes, a one-dimensional table
> with two entries, or a two-dimensional table (or matrix) with 2
> columns, giving the counts of successes and failures, respectively." I
> provided point$Class. The total number of tests is
> length(point$Class).
> There are three levels:
> ```
> > unique(df$Class)
> [1] negative  positive  uncertain
> Levels: negative positive uncertain
> ```
> I tried to remove the levels to check if the levels were interfering
> with the test:
> ```
> > df$Class = levels(droplevels(df$Class))
> Error in `$<-.data.frame`(`*tmp*`, Class, value = c("negative", "positive",  :
> replacement has 3 rows, data has 500
> ```
> What would be the syntax for this test? The idea is to get the most
> common value for each unique(df$Set) and prop.test will provide also
> the 95% CI for the estimate.
> Thanks
>
> __
> 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] How to use contour plot?

2021-11-16 Thread Luigi Marongiu
Hello,
I have a dataframe with 3 values and that I would like to plot with contour:
```
> head(df)
   Y   X  Z
1 0.0008094667  50 1
2 0.0012360955  50 1
3 0.0016627243  50 1
4 0.0020893531  50 1
5 0.0025159819  50 1
6 0.0029426108  50 1
> contour(df$X, df$Y, df$Z)
Error in contour.default(df$X, df$Y, df$Z) :
increasing 'x' and 'y' values expected
```
Y is increasing, whereas X is decreasing. How shall I set the function?
Thank you

__
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] How to run prop.test on 3-level factors?

2021-11-16 Thread Luigi Marongiu
Hello,
I have a large database with a column containing a factor:
```
> str(df)
'data.frame': 500 obs. of  4 variables:
$ MR   : num  0.000809 0.001236 0.001663 0.002089 0.002516 ...
$ FCN  : num  2 2 2 2 2 2 2 2 2 2 ...
$ Class: Factor w/ 3 levels "negative","positive",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Set  : int  1 1 1 1 1 1 1 1 1 1 ...
- attr(*, "out.attrs")=List of 2
..$ dim : Named int [1:2] 1000 1000
.. ..- attr(*, "names")= chr [1:2] "X1" "X2"
..$ dimnames:List of 2
.. ..$ X1: chr [1:1000] "X1=0.0008094667" "X1=0.0012360955"
"X1=0.0016627243" "X1=0.0020893531" ...
.. ..$ X2: chr [1:1000] "X2= 2.00" "X2= 2.048048" "X2= 2.096096"
"X2= 2.144144" ...
```
I would like to run prop.test on df$Class, but:
```
> prop.test(x=point$Class, n=length(point$Class),
+ conf.level=.95, correct=FALSE)
Error in prop.test(x = point$Class, n = length(point$Class),
conf.level = 0.95,  :
'x' and 'n' must have the same length
```
Since `x` is "a vector of counts of successes, a one-dimensional table
with two entries, or a two-dimensional table (or matrix) with 2
columns, giving the counts of successes and failures, respectively." I
provided point$Class. The total number of tests is
length(point$Class).
There are three levels:
```
> unique(df$Class)
[1] negative  positive  uncertain
Levels: negative positive uncertain
```
I tried to remove the levels to check if the levels were interfering
with the test:
```
> df$Class = levels(droplevels(df$Class))
Error in `$<-.data.frame`(`*tmp*`, Class, value = c("negative", "positive",  :
replacement has 3 rows, data has 500
```
What would be the syntax for this test? The idea is to get the most
common value for each unique(df$Set) and prop.test will provide also
the 95% CI for the estimate.
Thanks

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