Re: [R] wanting to count instances of values in each cell of a series of simulated symmetric matrices of the same size

2021-06-01 Thread R. Mark Sharp via R-help
Bert, 

You are obviously correct about the diagonals. I was not thinking carefully. 
Typically they are expected to be at or near 0.5 in an outbred population but 
can theoretically go to 1.0 in completely inbred populations. This was subset 
from a madeup pedigree and I reused parents, hence the inbreeding.

Space is a concern since I will need to simulate more matrices for the same 
precision as the matrices (breeding populations) increase in size. However, I 
will certainly look into your suggestion. I am doing this on the side so it may 
take a few days.

Thank you for your kind attention. I will provide more definitive feedback 
later.

Mark
R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com











> On Jun 1, 2021, at 10:44 PM, Bert Gunter  wrote:
> 
> Come again?! The diagonal values in your example are not all .5.
> 
> If space is not an issue, a straightforward approach is to collect all the 
> matrices into a 3d array and use indexing.
> Here is a simple reprex (as you did not provide one in a convenient form, e.g 
> via dput())
> 
> x <- matrix(1:9, nr = 3); y <- x+10
> diag(x) <- diag(y) <- 0
> print(x) ; print(y)
> ## Now you need to populate a 3 x 3 x 2 array with these matrices
> ## How you do this depends on your naming conventions
> ## You might use a loop, or ls() and assign(),
> ##  or collect your matrices into a list and use do.call() or ...
> ## You will *not*want to do this if you have lots of matrices:
> list_of_mats <- list(x,y) 
> arr <- array(do.call(c,list_of_mats), dim = c(3,3,length(list_of_mats)))
> arr
> arr[2,3,] ## all the values in the [2,3] cell of the matrices; do whatever 
> you want with them.
> 
> Cheers,
> Bert
> 
> 
> 
> 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, Jun 1, 2021 at 7:00 PM R. Mark Sharp via R-help  > wrote:
> I want to capture the entire distribution of values for each cell in a 
> sequence of symmetric matrices of the same size. The diagonal values are all 
> 0.5 so I need only the values above or below the diagonal. 
> 
> A small example with three of the structures I am wanting to count follows:
>F  G  H  I J
> F 0.6250 0.3750 0.2500 0.1875 0.125
> G 0.3750 0.6250 0.2500 0.1875 0.125
> H 0.2500 0.2500 0.5000 0.1875 0.125
> I 0.1875 0.1875 0.1875 0.5000 0.250
> J 0.1250 0.1250 0.1250 0.2500 0.500
> 
>F  G  H  I J
> F 0.5625 0.3125 0.1875 0.1250 0.125
> G 0.3125 0.5625 0.1875 0.1250 0.125
> H 0.1875 0.1875 0.5000 0.1875 0.125
> I 0.1250 0.1250 0.1875 0.5000 0.250
> J 0.1250 0.1250 0.1250 0.2500 0.500
> 
> F   G  H   I  J
> F 0.5 0.25000 0.1250 0.09375 0.0625
> G 0.25000 0.5 0.1250 0.09375 0.0625
> H 0.12500 0.12500 0.5000 0.18750 0.1250
> I 0.09375 0.09375 0.1875 0.5 0.2500
> J 0.06250 0.06250 0.1250 0.25000 0.5000
> 
> 
> To be more specific, I have coded up a solution for a single cell with the 
> sequence of values (one from each matrix) in a vector. 
> 
> I used match() below and it works with a matrix but I do not know how to do 
> what is in the if statements with matrices. Since the number of values and 
> the values will be different among the various cells a simple array structure 
> does not seem appropriate and I am assuming I will need to use a list but I 
> would like to do as much as I can with matrices for speed and clarity.
> 
> #' Counts the number of occurrences of each kinship value seen for a pair of
> #' individuals.
> #'
> #' @examples
> #' \donttest{
> #' set.seed(20210529)
> #' kSamples <- sample(c(0, 0.0675, 0.125, 0.25, 0.5, 0.75), 1, replace = 
> TRUE,
> #'prob = c(0.005, 0.3, 0.15, 0.075, 0.0375, 0.01875))
> #' kVC <- list(kinshipValues = numeric(0),
> #' kinshipCounts = numeric(0))
> #' for (kSample in kSamples) {
> #'   kVC <- countKinshipValues(kSample, kVC$kinshipValues, kVC$kinshipCounts)
> #' }
> #' kVC
> #' ## $kinshipValues
> #' ## [1] 0.2500 0.1250 0.0675 0.7500 0.5000 0.
> #' ##
> #' ## $kinshipCounts
> #' ## [1]  301 2592 5096 1322  592   97
> #' }
> #'
> #' @param kValue numeric value being counted (kinship value in
> #' \emph{nprcgenekeepr})
> #' @param kinshipValues vector of unique values of \code{kValue} seen
> #' thus far.
> #' @param kinshipCounts vector of the counts of the unique values of
> #' \code{kValue} seen thus far.
> #' @export
> countKinshipValues <- function(kValue, kinshipValues = numeric(0),
>   kinshipCounts = numeric(0)) {
>   kinshipValue <- match(kValue, kinshipValues, nomatch = -1L)
>   if (kinshipValue == -1L) {
> kinshipValues <- c(kinshipValues, kValue)
> kinshipCounts[length(kinshipCounts) + 1] <- 1
>   } else {
> kinshipCounts[

Re: [R] wanting to count instances of values in each cell of a series of simulated symmetric matrices of the same size

2021-06-01 Thread Bert Gunter
Come again?! The diagonal values in your example are not all .5.

If space is not an issue, a straightforward approach is to collect all the
matrices into a 3d array and use indexing.
Here is a simple reprex (as you did not provide one in a convenient form,
e.g via dput())

x <- matrix(1:9, nr = 3); y <- x+10
diag(x) <- diag(y) <- 0
print(x) ; print(y)
## Now you need to populate a 3 x 3 x 2 array with these matrices
## How you do this depends on your naming conventions
## You might use a loop, or ls() and assign(),
##  or collect your matrices into a list and use do.call() or ...
## You will *not*want to do this if you have lots of matrices:
list_of_mats <- list(x,y)
arr <- array(do.call(c,list_of_mats), dim = c(3,3,length(list_of_mats)))
arr
arr[2,3,] ## all the values in the [2,3] cell of the matrices; do whatever
you want with them.

Cheers,
Bert



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, Jun 1, 2021 at 7:00 PM R. Mark Sharp via R-help <
r-help@r-project.org> wrote:

> I want to capture the entire distribution of values for each cell in a
> sequence of symmetric matrices of the same size. The diagonal values are
> all 0.5 so I need only the values above or below the diagonal.
>
> A small example with three of the structures I am wanting to count follows:
>F  G  H  I J
> F 0.6250 0.3750 0.2500 0.1875 0.125
> G 0.3750 0.6250 0.2500 0.1875 0.125
> H 0.2500 0.2500 0.5000 0.1875 0.125
> I 0.1875 0.1875 0.1875 0.5000 0.250
> J 0.1250 0.1250 0.1250 0.2500 0.500
>
>F  G  H  I J
> F 0.5625 0.3125 0.1875 0.1250 0.125
> G 0.3125 0.5625 0.1875 0.1250 0.125
> H 0.1875 0.1875 0.5000 0.1875 0.125
> I 0.1250 0.1250 0.1875 0.5000 0.250
> J 0.1250 0.1250 0.1250 0.2500 0.500
>
> F   G  H   I  J
> F 0.5 0.25000 0.1250 0.09375 0.0625
> G 0.25000 0.5 0.1250 0.09375 0.0625
> H 0.12500 0.12500 0.5000 0.18750 0.1250
> I 0.09375 0.09375 0.1875 0.5 0.2500
> J 0.06250 0.06250 0.1250 0.25000 0.5000
>
>
> To be more specific, I have coded up a solution for a single cell with the
> sequence of values (one from each matrix) in a vector.
>
> I used match() below and it works with a matrix but I do not know how to
> do what is in the if statements with matrices. Since the number of values
> and the values will be different among the various cells a simple array
> structure does not seem appropriate and I am assuming I will need to use a
> list but I would like to do as much as I can with matrices for speed and
> clarity.
>
> #' Counts the number of occurrences of each kinship value seen for a pair
> of
> #' individuals.
> #'
> #' @examples
> #' \donttest{
> #' set.seed(20210529)
> #' kSamples <- sample(c(0, 0.0675, 0.125, 0.25, 0.5, 0.75), 1, replace
> = TRUE,
> #'prob = c(0.005, 0.3, 0.15, 0.075, 0.0375, 0.01875))
> #' kVC <- list(kinshipValues = numeric(0),
> #' kinshipCounts = numeric(0))
> #' for (kSample in kSamples) {
> #'   kVC <- countKinshipValues(kSample, kVC$kinshipValues,
> kVC$kinshipCounts)
> #' }
> #' kVC
> #' ## $kinshipValues
> #' ## [1] 0.2500 0.1250 0.0675 0.7500 0.5000 0.
> #' ##
> #' ## $kinshipCounts
> #' ## [1]  301 2592 5096 1322  592   97
> #' }
> #'
> #' @param kValue numeric value being counted (kinship value in
> #' \emph{nprcgenekeepr})
> #' @param kinshipValues vector of unique values of \code{kValue} seen
> #' thus far.
> #' @param kinshipCounts vector of the counts of the unique values of
> #' \code{kValue} seen thus far.
> #' @export
> countKinshipValues <- function(kValue, kinshipValues = numeric(0),
>   kinshipCounts = numeric(0)) {
>   kinshipValue <- match(kValue, kinshipValues, nomatch = -1L)
>   if (kinshipValue == -1L) {
> kinshipValues <- c(kinshipValues, kValue)
> kinshipCounts[length(kinshipCounts) + 1] <- 1
>   } else {
> kinshipCounts[kinshipValue] <- kinshipCounts[kinshipValue] + 1
>   }
>   list(kinshipValues = kinshipValues,
>kinshipCounts = kinshipCounts)
> }
>
> Mark
>
>
> R. Mark Sharp, Ph.D.
> Data Scientist and Biomedical Statistical Consultant
> 7526 Meadow Green St.
> San Antonio, TX 78251
> mobile: 210-218-2868
> rmsh...@me.com
>
> __
> 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, 

[R] wanting to count instances of values in each cell of a series of simulated symmetric matrices of the same size

2021-06-01 Thread R. Mark Sharp via R-help
I want to capture the entire distribution of values for each cell in a sequence 
of symmetric matrices of the same size. The diagonal values are all 0.5 so I 
need only the values above or below the diagonal. 

A small example with three of the structures I am wanting to count follows:
   F  G  H  I J
F 0.6250 0.3750 0.2500 0.1875 0.125
G 0.3750 0.6250 0.2500 0.1875 0.125
H 0.2500 0.2500 0.5000 0.1875 0.125
I 0.1875 0.1875 0.1875 0.5000 0.250
J 0.1250 0.1250 0.1250 0.2500 0.500

   F  G  H  I J
F 0.5625 0.3125 0.1875 0.1250 0.125
G 0.3125 0.5625 0.1875 0.1250 0.125
H 0.1875 0.1875 0.5000 0.1875 0.125
I 0.1250 0.1250 0.1875 0.5000 0.250
J 0.1250 0.1250 0.1250 0.2500 0.500

F   G  H   I  J
F 0.5 0.25000 0.1250 0.09375 0.0625
G 0.25000 0.5 0.1250 0.09375 0.0625
H 0.12500 0.12500 0.5000 0.18750 0.1250
I 0.09375 0.09375 0.1875 0.5 0.2500
J 0.06250 0.06250 0.1250 0.25000 0.5000


To be more specific, I have coded up a solution for a single cell with the 
sequence of values (one from each matrix) in a vector. 

I used match() below and it works with a matrix but I do not know how to do 
what is in the if statements with matrices. Since the number of values and the 
values will be different among the various cells a simple array structure does 
not seem appropriate and I am assuming I will need to use a list but I would 
like to do as much as I can with matrices for speed and clarity.

#' Counts the number of occurrences of each kinship value seen for a pair of
#' individuals.
#'
#' @examples
#' \donttest{
#' set.seed(20210529)
#' kSamples <- sample(c(0, 0.0675, 0.125, 0.25, 0.5, 0.75), 1, replace = 
TRUE,
#'prob = c(0.005, 0.3, 0.15, 0.075, 0.0375, 0.01875))
#' kVC <- list(kinshipValues = numeric(0),
#' kinshipCounts = numeric(0))
#' for (kSample in kSamples) {
#'   kVC <- countKinshipValues(kSample, kVC$kinshipValues, kVC$kinshipCounts)
#' }
#' kVC
#' ## $kinshipValues
#' ## [1] 0.2500 0.1250 0.0675 0.7500 0.5000 0.
#' ##
#' ## $kinshipCounts
#' ## [1]  301 2592 5096 1322  592   97
#' }
#'
#' @param kValue numeric value being counted (kinship value in
#' \emph{nprcgenekeepr})
#' @param kinshipValues vector of unique values of \code{kValue} seen
#' thus far.
#' @param kinshipCounts vector of the counts of the unique values of
#' \code{kValue} seen thus far.
#' @export
countKinshipValues <- function(kValue, kinshipValues = numeric(0),
  kinshipCounts = numeric(0)) {
  kinshipValue <- match(kValue, kinshipValues, nomatch = -1L)
  if (kinshipValue == -1L) {
kinshipValues <- c(kinshipValues, kValue)
kinshipCounts[length(kinshipCounts) + 1] <- 1
  } else {
kinshipCounts[kinshipValue] <- kinshipCounts[kinshipValue] + 1
  }
  list(kinshipValues = kinshipValues,
   kinshipCounts = kinshipCounts)
}

Mark


R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com

__
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] replace NA into - for specific column

2021-06-01 Thread Jeff Newmiller
A unary negative sign with no number is not a number, so it has to be 
character. If you are done with computations you can format your numbers as 
character data and set the NA to "-", but such a conversion will prevent you 
from performing computations so it is only useful for creating report tables.

On June 1, 2021 4:58:38 PM PDT, Kai Yang via R-help  
wrote:
>Hi List,
>I have a column MMR in a data frame proband_crc2. The column contents
>missing value and + (means positive). 
>I need to replace all missing value into - (means negative)
>I did try with difference ways.  Below are my testing, but not any one
>works. Can someone help me?
>Thanks,
>Kai
>proband_crc2 %>% mutate(MMR=recode(MMR, '' = "-"))
>proband_crc2            <- data.frame (ifelse(proband_crc2$MMR !="+",
>"-", NA))
>proband_crc2$MMR <- ifelse(MMR %in% c(""," ","-"), NA, MMR)
>proband_crc2$MMR[proband_crc2$MMR==NA] <- "-"
>proband_crc2           <- data.frame( proband_crc2 %>%
>mutate(across(c("MMR"), ~ifelse(.==NA, "-", as.character(.)
>
>
>   [[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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] replace NA into - for specific column

2021-06-01 Thread Kai Yang via R-help
Hi List,
I have a column MMR in a data frame proband_crc2. The column contents missing 
value and + (means positive). 
I need to replace all missing value into - (means negative)
I did try with difference ways.  Below are my testing, but not any one works. 
Can someone help me?
Thanks,
Kai
proband_crc2 %>% mutate(MMR=recode(MMR, '' = "-"))
proband_crc2            <- data.frame (ifelse(proband_crc2$MMR !="+", "-", NA))
proband_crc2$MMR <- ifelse(MMR %in% c(""," ","-"), NA, MMR)
proband_crc2$MMR[proband_crc2$MMR==NA] <- "-"
proband_crc2           <- data.frame( proband_crc2 %>% mutate(across(c("MMR"), 
~ifelse(.==NA, "-", as.character(.)


[[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] r2rtf: Easily Create Production-Ready Rich Text Format (RTF) Table and Figure

2021-06-01 Thread Yilong Zhang
Dear all,



I am happy to announce that {r2rtf} v0.3.0 is now on CRAN.



r2rtf is an R package to create production-ready tables and figures in RTF
format. The R package is designed to provide simple “verb” functions that
correspond to each component of a table or figure.



I hope you find it helpful. Please feel free to reach out with feedback or
questions.



CRAN: https://cloud.r-project.org/web/packages/r2rtf/index.html

Documentation: https://merck.github.io/r2rtf/articles/index.html



Thanks,



Yilong

[[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] DBDA2E-utilities.R file download

2021-06-01 Thread John Kane
I have added this to the R Help mailing list as it increases your
chances of getting a helpful response.

That error message  can't "lazyload" indicates that you have
some serious problem(s) upstream.

Probably the best thing to do is copy and paste the entire
installation output here for people to examine.

However as a quicker approach, scroll through the output and look for
an earlier message that will say something like:
There is no package called ‘’.

This will indicate that for some reasan the package  is not being
installed automatically.

You should try an install.packages("") and then retry
remotes::install_github("kyusque/DBDA2E-utilities")

In some cases there may be one missing package.

On Tue, 1 Jun 2021 at 03:19, Nick Wray  wrote:
>
> Hi John  Thanks but that doesn't work.  When installing the needed packages R 
> is telling me that it can't "lazyload"  DBDA2E-utilities.  Tbh I don't 
> understand what that means. The page I quoted in my OP implies that one 
> should be able to easily upload the file but there are various error messages 
> which come up which again tbh mean nothing to me.  As far as I am aware this 
> file should simply be some straightforward data to do an exercise in the 
> book...  Nick
>
> On Tue, 1 Jun 2021 at 01:26, John Kane  wrote:
>>
>> If it seems to have installed correctly try:
>> library(DBDA2E)
>> which should load the DBDA@E-specific programmes.
>>
>>
>>
>> On Mon, 31 May 2021 at 16:27, Nick Wray  wrote:
>> >
>> > Hello I am trying to download the file "kyusque/DBDA2E-utilities.R" which
>> > is used in following through John Krushke's book on Bayesian stats.
>> > According to the net (kyusque/DBDA2E-utilities: Packaged One for
>> > DBDA2E-utilities.R in 'Kruschke, J. K. (2015). Doing Bayesian Data
>> > Analysis, Second Edition' version 0.1.0 from GitHub (rdrr.io)
>> > ) I needed to
>> >
>> > install.packages("remotes")
>> > remotes::install_github("kyusque/DBDA2E-utilities")
>> >
>> > which i have done, and seem to have done successfully
>> >
>> > but I can't get hold of the utilities file.  Does anyone know what I
>> > should now do?
>> >
>> > Thanks Nick Wray
>> >
>> > [[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.
>>
>>
>>
>> --
>> John Kane
>> Kingston ON Canada



-- 
John Kane
Kingston ON Canada

__
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] Binary data on JAGS

2021-06-01 Thread Massimiliano Tripoli
Thanks, for suggestions (To define p before).
I thought it and I put this line of code inside the loop:
p[i] <- y[i] / n[i]
but I received a RUNTIME ERROR and:
(Attempt to redefine node p[1]).
Thanks

Massimiliano

Il giorno mar 1 giu 2021 alle ore 17:22 Bert Gunter 
ha scritto:

> Where is p defined before it is used? (Is this part of what jags provides
> somehow?)
>
> 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, Jun 1, 2021 at 7:57 AM Massimiliano Tripoli <
> massimiliano.trip...@gmail.com> wrote:
>
>> Dear R users,
>> I'm trying to reproduce the example 6.5.1 (Dobson (1983)) in BUGS book in
>> linux using JAGS.
>> Below the code as
>>
>>
>>
>> https://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-the-bugs-book/bugs-book-examples/the-bugs-book-examples-chapter-6-6-5-1/
>>
>> # By R code:
>> library('rjags')
>>
>>  jags <- jags.model(
>> file = "651.bug",
>> list (x = c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610,
>> 1.8839),
>> n = c(59, 60, 62, 56, 63, 59, 62, 60),
>> y = c(6, 13, 18, 28, 52, 53, 61, 60)) ,
>> inits = list(beta = 0, alpha = 50),
>> n.chains = 3
>> )
>>
>> # By JAGS code: (651.bug)
>>
>> model {
>> for (i in 1:8) {
>> y[i] ~ dbin(p[i], n[i])
>> logit(p[i]) <- alpha + beta*(x[i] - mean(x[]))
>> phat[i] <- y[i]/n[i]
>> yhat[i] <- n[i]*p[i]
>> }
>> alpha ~ dnorm(0, 0.0001)
>> beta ~ dnorm(0, 0.0001)
>> }
>> # I received this error in R:
>>
>> # Resolving undeclared variables
>>
>> #   Allocating nodes
>>
>> #Graph information:
>>
>> #   Observed stochastic nodes: 8
>>
>> #   Unobserved stochastic nodes: 2
>>
>> #   Total graph size: 78
>>
>>
>>
>> #Initializing model
>>
>> #Deleting model
>>
>>
>>
>> #Error in jags.model(file = "651.bug", list(x = c(1.6907, 1.7242, 1.7552,
>>  :
>> #  Error in node y[1]
>>
>> #Node inconsistent with parents
>>
>> Thanks in advance
>> M. Tripoli
>>
>> [[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] Binary data on JAGS

2021-06-01 Thread Bert Gunter
Unless you have got reason not to, always reply to the list (included in
this response). I cannot help, but someone else may be able to.

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, Jun 1, 2021 at 10:34 AM Massimiliano Tripoli <
massimiliano.trip...@gmail.com> wrote:

> I tried to write
> p[i] (Attempt to redefine node p[1]).
> Thanks
>
> Il mar 1 giu 2021, 17:22 Bert Gunter  ha scritto:
>
>> Where is p defined before it is used? (Is this part of what jags provides
>> somehow?)
>>
>> 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, Jun 1, 2021 at 7:57 AM Massimiliano Tripoli <
>> massimiliano.trip...@gmail.com> wrote:
>>
>>> Dear R users,
>>> I'm trying to reproduce the example 6.5.1 (Dobson (1983)) in BUGS book in
>>> linux using JAGS.
>>> Below the code as
>>>
>>>
>>>
>>> https://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-the-bugs-book/bugs-book-examples/the-bugs-book-examples-chapter-6-6-5-1/
>>>
>>> # By R code:
>>> library('rjags')
>>>
>>>  jags <- jags.model(
>>> file = "651.bug",
>>> list (x = c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610,
>>> 1.8839),
>>> n = c(59, 60, 62, 56, 63, 59, 62, 60),
>>> y = c(6, 13, 18, 28, 52, 53, 61, 60)) ,
>>> inits = list(beta = 0, alpha = 50),
>>> n.chains = 3
>>> )
>>>
>>> # By JAGS code: (651.bug)
>>>
>>> model {
>>> for (i in 1:8) {
>>> y[i] ~ dbin(p[i], n[i])
>>> logit(p[i]) <- alpha + beta*(x[i] - mean(x[]))
>>> phat[i] <- y[i]/n[i]
>>> yhat[i] <- n[i]*p[i]
>>> }
>>> alpha ~ dnorm(0, 0.0001)
>>> beta ~ dnorm(0, 0.0001)
>>> }
>>> # I received this error in R:
>>>
>>> # Resolving undeclared variables
>>>
>>> #   Allocating nodes
>>>
>>> #Graph information:
>>>
>>> #   Observed stochastic nodes: 8
>>>
>>> #   Unobserved stochastic nodes: 2
>>>
>>> #   Total graph size: 78
>>>
>>>
>>>
>>> #Initializing model
>>>
>>> #Deleting model
>>>
>>>
>>>
>>> #Error in jags.model(file = "651.bug", list(x = c(1.6907, 1.7242, 1.7552,
>>>  :
>>> #  Error in node y[1]
>>>
>>> #Node inconsistent with parents
>>>
>>> Thanks in advance
>>> M. Tripoli
>>>
>>> [[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] Binary data on JAGS

2021-06-01 Thread Bert Gunter
Where is p defined before it is used? (Is this part of what jags provides
somehow?)

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, Jun 1, 2021 at 7:57 AM Massimiliano Tripoli <
massimiliano.trip...@gmail.com> wrote:

> Dear R users,
> I'm trying to reproduce the example 6.5.1 (Dobson (1983)) in BUGS book in
> linux using JAGS.
> Below the code as
>
>
>
> https://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-the-bugs-book/bugs-book-examples/the-bugs-book-examples-chapter-6-6-5-1/
>
> # By R code:
> library('rjags')
>
>  jags <- jags.model(
> file = "651.bug",
> list (x = c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610,
> 1.8839),
> n = c(59, 60, 62, 56, 63, 59, 62, 60),
> y = c(6, 13, 18, 28, 52, 53, 61, 60)) ,
> inits = list(beta = 0, alpha = 50),
> n.chains = 3
> )
>
> # By JAGS code: (651.bug)
>
> model {
> for (i in 1:8) {
> y[i] ~ dbin(p[i], n[i])
> logit(p[i]) <- alpha + beta*(x[i] - mean(x[]))
> phat[i] <- y[i]/n[i]
> yhat[i] <- n[i]*p[i]
> }
> alpha ~ dnorm(0, 0.0001)
> beta ~ dnorm(0, 0.0001)
> }
> # I received this error in R:
>
> # Resolving undeclared variables
>
> #   Allocating nodes
>
> #Graph information:
>
> #   Observed stochastic nodes: 8
>
> #   Unobserved stochastic nodes: 2
>
> #   Total graph size: 78
>
>
>
> #Initializing model
>
> #Deleting model
>
>
>
> #Error in jags.model(file = "651.bug", list(x = c(1.6907, 1.7242, 1.7552,
>  :
> #  Error in node y[1]
>
> #Node inconsistent with parents
>
> Thanks in advance
> M. Tripoli
>
> [[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] Binary data on JAGS

2021-06-01 Thread Massimiliano Tripoli
Dear R users,
I'm trying to reproduce the example 6.5.1 (Dobson (1983)) in BUGS book in
linux using JAGS.
Below the code as


https://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-the-bugs-book/bugs-book-examples/the-bugs-book-examples-chapter-6-6-5-1/

# By R code:
library('rjags')

 jags <- jags.model(
file = "651.bug",
list (x = c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610,
1.8839),
n = c(59, 60, 62, 56, 63, 59, 62, 60),
y = c(6, 13, 18, 28, 52, 53, 61, 60)) ,
inits = list(beta = 0, alpha = 50),
n.chains = 3
)

# By JAGS code: (651.bug)

model {
for (i in 1:8) {
y[i] ~ dbin(p[i], n[i])
logit(p[i]) <- alpha + beta*(x[i] - mean(x[]))
phat[i] <- y[i]/n[i]
yhat[i] <- n[i]*p[i]
}
alpha ~ dnorm(0, 0.0001)
beta ~ dnorm(0, 0.0001)
}
# I received this error in R:

# Resolving undeclared variables

#   Allocating nodes

#Graph information:

#   Observed stochastic nodes: 8

#   Unobserved stochastic nodes: 2

#   Total graph size: 78



#Initializing model

#Deleting model



#Error in jags.model(file = "651.bug", list(x = c(1.6907, 1.7242, 1.7552,
 :
#  Error in node y[1]

#Node inconsistent with parents

Thanks in advance
M. Tripoli

[[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] Plot GEE confindence interval band ggplot2

2021-06-01 Thread Rui Barradas

Hello,

I don't know if the following is what you want but it gives confidence 
bars. The error in your code is to have Esp as id.



dat$Id <- as.integer(factor(dat$Esp))

m5 <- geeglm(
  formula = tim ~ Pa*Pt,
  family = Gamma(link = log),
  data = dat,
  id = Id,
  corstr = "exchangeable"
)
plot_model(m5, type = "pred", terms = c("Pa", "Pt"))


Hope this helps,

Rui Barradas

Às 23:10 de 31/05/21, Luis Fernando García escreveu:

Dear all,

I want to plot a Generalized Estimating Equation (GEE) model, with
interactions  and the confidence interval using a similar style to ggplot2
. I have tried several packages but all of them produce errors. My idea

I wanted to know if anyone knows a graphical package which works with GEE
or simular solution

Dataset in this link:
https://docs.google.com/spreadsheets/d/1nXerN91Iehe9OM1VGDMS3jnbvvF1tWcuS9bGtlrj_Ss/edit?usp=sharing

Thanks!

code below:

library(geepack)
library(ggplot2)
library(visreg)
library(sjPlot)

#Copy dataset before following the code

dat <- read.delim("clipboard", dec=","); attach(dat)
head(dat)
str(dat)
names(dat)
m5<- geeglm(tim~Pa*Pt,id=Esp, Gamma(link=log), corstr="exchangeable")
anova(m5,test="Chisq")
visreg(m5, "Pt", by="Pa",band=T, overlay=TRUE)
plot_model(m5, type = "pred", terms = c("Pa","Pt"))

[[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] if statement and for loop question

2021-06-01 Thread Michael Dewey

Dear Kai

When you ask again it is best to tell us what your input is and what 
output you were hoping for and what you actually got. If you can make a 
small data-set which shows all that then your post will be much more 
likely to get a helpful response. If you want to transfer the data-set 
to us then using dput() will ensure that we have exactly the same as you 
have. Do not forget to tell us what libraries, if any, you have loaded too.


Michael

On 31/05/2021 17:26, Kai Yang via R-help wrote:

   Hi Jim,
Sorry to post "same" question, because
1. I was asking to use plain text format. I have to post my question again. But 
I don't know if it is working.
2. I'm a beginner for R (< 2 month). It may not easy for me to ask a "clear" R 
question. My current work is to transfer my SAS code into R, especially for data 
manipulation part.
I'll do my best to ask a non."same" question later.
Thanks,
Kai
 On Sunday, May 30, 2021, 10:44:41 PM PDT, Jim Lemon  
wrote:
  
  Hi Kai,

You seem to be asking the same question again and again. This does not
give us the warm feeling that you know what you want.

testdf<-data.frame(a=c("Negative","Positive","Neutral","Random","VUS"),
  b=c("No","Yes","No","Maybe","Yes"),
  c=c("Off","On","Off","Off","On"),
  d=c("Bad","Good","Bad","Bad","Good"),
  stringsAsFactors=FALSE)
testdf
match_strings<-c("Positive","VUS")
testdf$b<-ifelse(testdf$a %in% match_strings,testdf$b,"")
testdf$c<-ifelse(testdf$a %in% match_strings,testdf$c,"")
testdf$d<-ifelse(testdf$a %in% match_strings,testdf$d,"")
testdf

I have assumed that you mean "zero length strings" rather than
"zeros". Also note that your initial code was producing logical values
that were never assigned to anything.

Jim

On Mon, May 31, 2021 at 2:29 AM Kai Yang via R-help
 wrote:


Hello List,I have a data frame which having the character columns:

| a1 | b1 | c1 | d1 |
| a2 | b2 | c2 | d2 |
| a3 | b3 | c3 | d3 |
| a4 | b4 | c4 | d4 |
| a5 | b5 | c5 | d5 |



I need to do: if a1 not = "Positive" and not = "VUS" then values of  b1, c1 and 
d1 will be zero out. And do the same thing for the a2 to a5 series.
I write the code below to do this. But it doesn't work. Would you please 
correct my code?
Thank you,
Kai


for (i in 1:5)
{
   if (isTRUE(try$a[i] != "Positive" && try$a[i] != "VUS"))
   {
     try$b[i]== ''
     try$c[i] == ''
     try$d[i]== ''
   }
}


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



--
Michael
http://www.dewey.myzen.co.uk/home.html

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