[R] impute.transcan missing original variables

2021-06-03 Thread maicel


I’m trying to select only one dataframe, after performing an imputation with 
aregImpute and impute.transcan. However, I cannot get back a variable that was 
kept out of the imputation model. Can somebody tell me how to do it? If we 
illustrate this problem using the following reproducible example, how could I 
get the dataframe with all the variables that were not imputated, such as 
Species and id variables?
Best !


Data
data("iris") 
library(missForest)
library(tidyverse)
library(Hmisc)

# example
iris.missing <- iris %>% 
  group_by(Species) %>% 
  prodNA(noNA = 0.1) %>% 
  ungroup() %>% 
  mutate(id=row_number())

imputation_model <- aregImpute(~Sepal.Length+Sepal.Width+Petal.Width,
   n.impute=3,
   data=iris.missing,
   pr=F, 
   type='pmm')

data_imp <- impute.transcan(imputation_model,
  imputation=1,
  data=iris.missing,
  list.out=TRUE,
  pr=FALSE,
  check=FALSE)


datos_imp <- bind_rows(data_imp)


--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
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] incidence_fit model for simulation

2020-04-24 Thread maicel

Hello

How can I make a prediction with object type incidence_fit.
incidence_fit object is returned by the function fit in library(incidence).

Best regard
maicel







--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
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] purrr::map and xml2:: read_xml

2017-01-06 Thread maicel
Hi List, I am trying to extract the key words from 1403 papers in xml  
format. I programmed such codes but they do not work but they only do  
with the modification showed below. But that variation is not the one  
I need because the 1403 xml files do not match to those in my folder.  
Could you please tell me where are the mistakes in the codes list (A  
or B) to help me to correct them? The data frame columns are an id and  
the paths.


A-Does not work, but it is the one I need.

keyword <-
  muestra %>%
  select(path) %>%
  read_xmlmap(.f = function(x) { read_xml(x) %>%
   xml_find_all( ".//kwd") %>%
   xml_text(trim=T) })

B-It works but only with a small number of papers.

keyword <-
  muestra %>%
  select(path) %>%
   dplyr::sample_n(50) %>%
   unlist() %>%
  map(.f = function(x) { read_xml(x) %>%
   xml_find_all( ".//kwd") %>%
   xml_text(trim=T) })

Thank you,
Maicel Monzon MD, PHD







--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
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] dplyr : row total for all groups in dplyr summarise

2016-07-05 Thread maicel
Sorry, what I wanted to do was to add a total row at the end of the  
summary. The marginal totals by columns correspond to 100% and the sum  
of levels.

best reagard
Maicel Monzon


Ulrik Stervbo <ulrik.ster...@gmail.com> escribió:


Yes. But in the sample code the data is summarised. In which case you get 4
rows and not the correct 32.

On Tue, 5 Jul 2016, 07:48 David Winsemius, <dwinsem...@comcast.net> wrote:


nrow(mtcars)


Sent from my iPhone

On Jul 4, 2016, at 9:03 PM, Ulrik Stervbo <ulrik.ster...@gmail.com> wrote:

That will give you the wrong result when used on summarised data

David Winsemius <dwinsem...@comcast.net> schrieb am Di., 5. Juli 2016
02:10:


I thought there was an nrow() function?

Sent from my iPhone

On Jul 4, 2016, at 9:59 AM, Ulrik Stervbo <ulrik.ster...@gmail.com>
wrote:

If you want the total number of rows in the original data.frame after
counting the rows in each group, you can ungroup and sum the row counts,
like:

library("dplyr")


mtcars %>%
   group_by (am, gear) %>%
   summarise (n=n()) %>%
   mutate(rel.freq = paste0(round(100 * n/sum(n), 0), "%")) %>%
   ungroup() %>%
   mutate(row.tot = sum(n))

HTH
Ulrik

On Mon, 4 Jul 2016 at 18:23 David Winsemius <dwinsem...@comcast.net>
wrote:



> On Jul 4, 2016, at 6:56 AM, mai...@infomed.sld.cu wrote:
>
> Hello,
> How can I aggregate row total for all groups in dplyr summarise ?

Row total ? of what? Aggregate ? how? What is the desired answer?



> library(dplyr)
> mtcars %>%
>  group_by (am, gear) %>%
>  summarise (n=n()) %>%
>  mutate(rel.freq = paste0(round(100 * n/sum(n), 0), "%"))
>
> best regard
> Maicel Monzon
>
>
>
> 
>
>
>
>
> --
> Este mensaje le ha llegado mediante el servicio de correo electronico
que ofrece Infomed para respaldar el cumplimiento de las misiones del
Sistema Nacional de Salud. La persona que envia este correo asume el
compromiso de usar el servicio a tales fines y cumplir con las  
regulaciones

establecidas
>
> Infomed: http://www.sld.cu/
>
> __
> 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.














--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
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] dplyr : row total for all groups in dplyr summarise

2016-07-04 Thread maicel

Thank you!!! It's what I needed.
best regard
Maicel Monzon, PHD
Centro Nacional de Ensayos Clinicos


Ulrik Stervbo <ulrik.ster...@gmail.com> escribió:


If you want the total number of rows in the original data.frame after
counting the rows in each group, you can ungroup and sum the row counts,
like:

library("dplyr")


mtcars %>%
   group_by (am, gear) %>%
   summarise (n=n()) %>%
   mutate(rel.freq = paste0(round(100 * n/sum(n), 0), "%")) %>%
   ungroup() %>%
   mutate(row.tot = sum(n))

HTH
Ulrik

On Mon, 4 Jul 2016 at 18:23 David Winsemius <dwinsem...@comcast.net> wrote:



> On Jul 4, 2016, at 6:56 AM, mai...@infomed.sld.cu wrote:
>
> Hello,
> How can I aggregate row total for all groups in dplyr summarise ?

Row total ? of what? Aggregate ? how? What is the desired answer?



> library(dplyr)
> mtcars %>%
>  group_by (am, gear) %>%
>  summarise (n=n()) %>%
>  mutate(rel.freq = paste0(round(100 * n/sum(n), 0), "%"))
>
> best regard
> Maicel Monzon
>
>
>
> 
>
>
>
>
> --
> Este mensaje le ha llegado mediante el servicio de correo electronico
que ofrece Infomed para respaldar el cumplimiento de las misiones del
Sistema Nacional de Salud. La persona que envia este correo asume el
compromiso de usar el servicio a tales fines y cumplir con las regulaciones
establecidas
>
> Infomed: http://www.sld.cu/
>
> __
> 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.











--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
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] dplyr : row total for all groups in dplyr summarise

2016-07-04 Thread maicel

Hello,
How can I aggregate row total for all groups in dplyr summarise ?
library(dplyr)
mtcars %>%
  group_by (am, gear) %>%
  summarise (n=n()) %>%
  mutate(rel.freq = paste0(round(100 * n/sum(n), 0), "%"))

best regard
Maicel Monzon








--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
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] extract all dataframes from list

2015-10-06 Thread maicel
Hello List, I have list of named dataframe. How can I extract all dataframes
from this list? The dataframe names should be the same of the original list.
May I use the lapply function?

Thanks for your help. Best regards,
Maicel Monzon, MD
National Center of Clinical Trials
Havana, Cuba




--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
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] read Epidata level labels from R

2015-10-03 Thread maicel
Hello List, 
I need import data from Epidata version 3.1 to R data frame.  My problem is
that I need to import the level labels of from categorical variables to
factors. Epidata has two files, .red and .chk. I read on a post that the
best choice was to export them to .dta in epidat, and them to read the data
from R. I've used the functions stata.get from the library Hmisc,
read_statafrom library haven and read.dta from library foreign. Two of this
functions allow me to import the labels of the dataframe variables, not the
level labels of the factors I would like to get. How can I do it?
 Thanks for your help. Best regards,

Maicel Monzon ,MD
National Center of Clinical Trials
Havana, Cuba


--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
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] table

2015-03-02 Thread maicel

Hello List,

I am trying to obtain a table containing absolute and relative  
frequencies but it must be done by strata. Each strata have to contain  
totals and subtotals being the sum of the subtotals equal to the total  
in upper strata in same column. As this could be some vague I am  
including an example of such table:



data-data.frame(Provincial=rep(c(Prov1,Prov2,Prov1,Prov3),10),  
Municipios=rep(c(Mun1,Mun2,Mun3,Mun4),10),unit=rep(c(unit1,unit2,unit3,unit4),10))


VariableN   %
Province (i)
Municipalities (j)
Health units (k)
#8721;i,  #8721;j, #8721;k
And so on … i = 1 to 16

#8721;i,  #8721;j, #8721;k

If you could help me to obtain a function to get such table I would  
appreciate very much.


Best and thank you….
maicel monzon MD. MSc.








--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
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] Unique values in dataframe columns

2014-09-25 Thread Maicel Monzón Pérez
Hello  list
I would like to know how can  i detect  dataframe columns that have as
unique values elements of a list.
For example, at a  given dataframe to look for columns that unique values
are elements of a list like this one… 

dataframe-data.frame(
x = c(yes”, 1”, no”, no”),
y = c(black”, red”, NA”, white”),
z= c(T,F,T,T),
J= c(2,7,8,9))
Library(DescTools)

list-GetAllSubsets(c(NA,0,1,2,yes,y,no),min.n = 2, max.n = 5)

..and to obtain  the following vector..
TRUE,FALSE, FALSE, FALSE

Best regards
Maicel Monzon


--
Nunca digas nunca, di mejor: gracias, permiso, disculpe.

Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

__
R-help@r-project.org mailing list
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] script to data clear

2014-08-12 Thread Maicel Monzón Pérez
Hello List,

I did this script to clear data after import (I don’t know is ok ). After
its execution levels and label values got lost. Could some explain me to
reassign levels again in the script (new depurate value)? 

Best regard

Maicel Monzon MD, PHD

Center of Cybernetic Apply to Medicine

# data cleaning  script

library(stringr)

for(i in 1:length(data)) { 

  if (is.factor(data[[i]])==T) 

  {for(j in 1:sum(str_detect(data[,i],   ))) 

  {data[[i]]-str_replace_all(data[[i]],   ,  )}}

  data[[i]]-str_trim (data[[i]],side = both)

  data[[i]]-tolower(data[[i]])

}

Note: “   ” is 2 blank space  and “ “  only one

 



--
Nunca digas nunca, di mejor: gracias, permiso, disculpe.

Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.