Re: [R-es] Error al cargar el paquete tidyr

2021-01-23 Thread Manuel Mendoza
Solucionado, aunque no estoy seguro de cómo. Sé que finalmente lo pude
instalar de nuevo, y ya funciona.
Gracias a todos,
Manuel

El sáb, 23 ene 2021 a las 22:27, Marcelino de la Cruz Rot (<
marcelino.delac...@urjc.es>) escribió:

> Si da *el mismo* error, entonces, es que no se ha actualizado.
>
> Probablemente tengas que desconectarlo primero, es decir:
>
> detach("package:vctrs")
> install.packages("vctrs")
>
>
>
> El 23/01/2021 a las 21:59, Manuel Mendoza escribió:
> > Lo he actualizado, pero me sigue dando el mismo error.
> >
> > El sáb, 23 ene 2021 a las 14:48, Jesús Para Fernández (<
> > j.para.fernan...@hotmail.com>) escribió:
> >
> >> Te pide actializar el paquete vctrs. Desde rstudio puedes hacerlo sin
> >> problema
> >>
> >> Obtener Outlook para Android 
> >> --
> >> *From:* R-help-es  on behalf of Manuel
> >> Mendoza 
> >> *Sent:* Saturday, January 23, 2021 2:45:40 PM
> >> *To:* Lista R 
> >> *Subject:* [R-es] Error al cargar el paquete tidyr
> >>
> >> Lo había utilizado hasta ahora sin problemas.
> >>
> >> Error: package or namespace load failed for ‘tidyr’ in loadNamespace(i,
> >> c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
> >>   namespace ‘vctrs’ 0.2.4 is already loaded, but >= 0.3.0 is required.
> >>
> >> Gracias,
> >> 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
> >>
> >   [[alternative HTML version deleted]]
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> > .
>
>
> --
> Marcelino de la Cruz Rot
> Depto. de Biología y Geología
> Física y Química Inorgánica
> Universidad Rey Juan Carlos
> Móstoles España
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

[[alternative HTML version deleted]]

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


Re: [R-es] Error al cargar el paquete tidyr

2021-01-23 Thread Marcelino de la Cruz Rot

Si da *el mismo* error, entonces, es que no se ha actualizado.

Probablemente tengas que desconectarlo primero, es decir:

detach("package:vctrs")
install.packages("vctrs")



El 23/01/2021 a las 21:59, Manuel Mendoza escribió:

Lo he actualizado, pero me sigue dando el mismo error.

El sáb, 23 ene 2021 a las 14:48, Jesús Para Fernández (<
j.para.fernan...@hotmail.com>) escribió:


Te pide actializar el paquete vctrs. Desde rstudio puedes hacerlo sin
problema

Obtener Outlook para Android 
--
*From:* R-help-es  on behalf of Manuel
Mendoza 
*Sent:* Saturday, January 23, 2021 2:45:40 PM
*To:* Lista R 
*Subject:* [R-es] Error al cargar el paquete tidyr

Lo había utilizado hasta ahora sin problemas.

Error: package or namespace load failed for ‘tidyr’ in loadNamespace(i,
c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
  namespace ‘vctrs’ 0.2.4 is already loaded, but >= 0.3.0 is required.

Gracias,
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


[[alternative HTML version deleted]]

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



--
Marcelino de la Cruz Rot
Depto. de Biología y Geología
Física y Química Inorgánica
Universidad Rey Juan Carlos
Móstoles España

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


Re: [R-es] Error al cargar el paquete tidyr

2021-01-23 Thread Manuel Mendoza
Lo he actualizado, pero me sigue dando el mismo error.

El sáb, 23 ene 2021 a las 14:48, Jesús Para Fernández (<
j.para.fernan...@hotmail.com>) escribió:

> Te pide actializar el paquete vctrs. Desde rstudio puedes hacerlo sin
> problema
>
> Obtener Outlook para Android 
> --
> *From:* R-help-es  on behalf of Manuel
> Mendoza 
> *Sent:* Saturday, January 23, 2021 2:45:40 PM
> *To:* Lista R 
> *Subject:* [R-es] Error al cargar el paquete tidyr
>
> Lo había utilizado hasta ahora sin problemas.
>
> Error: package or namespace load failed for ‘tidyr’ in loadNamespace(i,
> c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
>  namespace ‘vctrs’ 0.2.4 is already loaded, but >= 0.3.0 is required.
>
> Gracias,
> 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
>

[[alternative HTML version deleted]]

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


[R-es] predict.gbm

2021-01-23 Thread Manuel Mendoza
Muy buenas, utilizo el comando gbm.step (paquete dismo) para entrenar un
gradient boosting, directamente con el nº óptimo de árboles obtenido
mediante validación cruzada.

gbm.predict me permite obtener las predicciones para nuevos datos, pero yo
querría las que se obtuvieron en la VC (para las muestras test).

Con randomForest es muy fácil. Si yo no le indico los datos
en predict(fit), me da las predicciones sobre los datos OOB. Tenía la
esperanza de que fuera igual con predict.gbm, pero  me hace las
predicciones sobre los datos de entrenamiento.

En la documentación dice “predict.gbm produces predicted values for each
observation in newdata ... “. No encuentro en ningún sitio cómo obtener las
predicciones que se obtuvieron durante la VC. ¿Sabe alguien si es posible?

Gracias,

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-es] Error al cargar el paquete tidyr

2021-01-23 Thread Carlos J. Gil Bellosta
Hola, ¿qué tal?

¿Y si pruebas a actualizar R y todos los paquetes? ¿Sigue fallando entonces?

Un saludo,

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


El sáb, 23 ene 2021 a las 14:46, Manuel Mendoza ()
escribió:

> Lo había utilizado hasta ahora sin problemas.
>
> Error: package or namespace load failed for ‘tidyr’ in loadNamespace(i,
> c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
>  namespace ‘vctrs’ 0.2.4 is already loaded, but >= 0.3.0 is required.
>
> Gracias,
> 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
>

[[alternative HTML version deleted]]

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


[R-es] Error al cargar el paquete tidyr

2021-01-23 Thread Manuel Mendoza
Lo había utilizado hasta ahora sin problemas.

Error: package or namespace load failed for ‘tidyr’ in loadNamespace(i,
c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
 namespace ‘vctrs’ 0.2.4 is already loaded, but >= 0.3.0 is required.

Gracias,
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-es] Fwd: weighted random forest

2021-01-23 Thread Jose Luis Cañadas Reche
Hola. Si tienes una columna con los pesos. con tidyverse es sencillo
hacer la muestra usando


tam_muestra <- 1000

muestra <- df %>%
  sample_n(size = tam_muestra,
   replace = TRUE,
   weight = pesos)



El 22/1/21 a las 17:58, Manuel Mendoza escribió:
> Gracias Jesús, sí, haré remuestreos. Yo suelo usar una función que me pasó
> un colega:
>
> # A function to generate the equal number of samples (n) for different
> classes
>
> bsample <- function(data,cname,n) {
>   d <- data[-c(1:nrow(data)),]
>   u <- unique(data[,cname])
>   for (uu in u) {
> w <- which(data[,cname] == uu)
> if (length(w) >= n) {
>   s <- sample(w,n)
> } else {
>   s <- sample(w,n,replace=TRUE)
> }
> d <- rbind(d,data[s,])
>   }
>   d
> }
>
> # for your data:
> table(data$Clst)
> mean<-mean(table(data$Clst))
> data <- bsample(data,'Clst',mean) # this takes 100 records for each class
> in your dataset
> table(data$Clst)
>
> Por si le sirve a alguien, Clst sería la variable objetivo.
> En vez de  bsample(data,'Clst',mean) se puede, p.e.,  (data,'Clst', *2**mean)
>
>
> Manuel
>
> El vie, 22 ene 2021 a las 16:10, Jesús Para Fernández (<
> j.para.fernan...@hotmail.com>) escribió:
>
>> Has probado en usar en vez de algoritmos sensibles al coste, usar técnicas
>> de remuestreo? Hay un paquete de la UGR llamado imbalance que funciona muy
>> bien.
>>
>>
>> --
>> *De:* R-help-es  en nombre de Manuel
>> Mendoza 
>> *Enviado:* viernes, 22 de enero de 2021 11:43
>> *Para:* Lista R 
>> *Asunto:* [R-es] weighted random forest
>>
>> Buenos días, tengo una base de datos desequilibrados (unbalanced) en la que
>> las ausencias son 9 veces más abundantes que las presencias (*ratio *= 9).
>> Para árboles de clasificación utilizo una matriz de pérdidas
>> parms=list(loss=matrix(c(0,
>> FP,  *ratio  *,0)))o un vector de ponderación que le da 9 veces más peso a
>> las presencias. Como cabría esperar, la sensibilidad y sensitividad se
>> hacen parecidas. Pasan de ser
>> 89/39 a 79/76 y kappa sube de 0.24 a 0.30.
>>
>> El problema surge cuando intento hacer lo mismo con random forest, y
>> supongo que no lo estoy haciendo bien. Uso  RFfit <- randomForest(Dep ~. ,
>> classwt = c(1, *ratio * ), data=data). La sensibilidad y sensitividad se
>> quedan casi igual 90/40 y kappa también 0.25.
>>
>> Sé que se puede hacer con ranger, pero, por razones que no vienen al caso,
>> no me viene bien cambiar.
>>
>> Gracias, como siempre,
>> 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
>>
>   [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es

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


Re: [R] How to generate SE for the proportion value using a randomization process in R?

2021-01-23 Thread Marna Wagley
Yes Rui, I can see we don't need to divide by square root of sample size.
The example is great to understand it.
Thank you.
Marna


On Sat, Jan 23, 2021 at 12:28 AM Rui Barradas  wrote:

> Hello,
>
> Inline.
>
> Às 07:47 de 23/01/21, Marna Wagley escreveu:
> > Dear Rui,
> > I was wondering whether we have to square root of SD to find SE, right?
>
> No, we don't. var already divides by n, don't divide again.
> This is the code, that can be seen by running the function name at a
> command line.
>
>
> sd
> #function (x, na.rm = FALSE)
> #sqrt(var(if (is.vector(x) || is.factor(x)) x else as.double(x),
> #na.rm = na.rm))
> #
> #
>
>
>
> >
> > bootprop <- function(data, index){
> > d <- data[index, ]
> > sum(d[["BothTimes"]], na.rm = TRUE)/sum(d[["Time1"]], na.rm = TRUE)
> > }
> >
> > R <- 1e3
> > set.seed(2020)
> > b <- boot(daT, bootprop, R)
> > b
> > b$t0 # original
> > sd(b$t)  # bootstrapped estimate of the SE of the sample prop.
> > sd(b$t)/sqrt(1000)
> > pandit*(1-pandit)
> >
> > hist(b$t, freq = FALSE)
>
>
> Try plotting the normal densities for both cases, the red line is
> clearly wrong.
>
>
> f <- function(x, xbar, s){
>dnorm(x, mean = xbar, sd = s)
> }
>
> hist(b$t, freq = FALSE)
> curve(f(x, xbar = b$t0, s = sd(b$t)), from = 0, to = 1, col = "blue",
> add = TRUE)
> curve(f(x, xbar = b$t0, s = sd(b$t)/sqrt(R)), from = 0, to = 1, col =
> "red", add = TRUE)
>
>
> Hope this helps,
>
> Rui Barradas
>
> >
> >
> >
> >
> > On Fri, Jan 22, 2021 at 3:07 PM Rui Barradas  > > wrote:
> >
> > Hello,
> >
> > Something like this, using base package boot?
> >
> >
> > library(boot)
> >
> > bootprop <- function(data, index){
> > d <- data[index, ]
> > sum(d[["BothTimes"]], na.rm = TRUE)/sum(d[["Time1"]], na.rm =
> TRUE)
> > }
> >
> > R <- 1e3
> > set.seed(2020)
> > b <- boot(daT, bootprop, R)
> > b
> > b$t0 # original
> > sd(b$t)  # bootstrapped estimate of the SE of the sample prop.
> > hist(b$t, freq = FALSE)
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Às 21:57 de 22/01/21, Marna Wagley escreveu:
> >  > Hi All,
> >  > I was trying to estimate standard error (SE) for the proportion
> > value using
> >  > some kind of randomization process (bootstrapping or jackknifing)
> > in R, but
> >  > I could not figure it out.
> >  >
> >  > Is there any way to generate SE for the proportion?
> >  >
> >  > The example of the data and the code I am using is attached for
> your
> >  > reference. I would like to generate the value of proportion with
> > a SE using
> >  > a 1000 times randomization.
> >  >
> >  > dat<-structure(list(Sample = structure(c(1L, 12L, 13L, 14L, 15L,
> 16L,
> >  > 17L, 18L, 19L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L), .Label
> > = c("id1",
> >  > "id10", "id11", "id12", "id13", "id14", "id15", "id16", "id17",
> >  > "id18", "id19", "Id2", "id3", "id4", "id5", "id6", "id7", "id8",
> >  > "id9"), class = "factor"), Time1 = c(0L, 1L, 1L, 1L, 0L, 0L,
> >  > 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L), Time2 = c(1L,
> >  > 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L,
> >  > 1L, 1L)), .Names = c("Sample", "Time1", "Time2"), class =
> > "data.frame",
> >  > row.names = c(NA,
> >  > -19L))
> >  > daT<-data.frame(dat %>%
> >  >mutate(Time1.but.not.in.Time2 = case_when(
> >  >  Time1 %in% "1" & Time2 %in% "0"  ~ "1"),
> >  > Time2.but.not.in.Time1 = case_when(
> >  >  Time1 %in% "0" & Time2 %in% "1"  ~ "1"),
> >  >   BothTimes = case_when(
> >  >  Time1 %in% "1" & Time2 %in% "1"  ~ "1")))
> >  >   daT
> >  >   summary(daT)
> >  >
> >  > cols.num <- c("Time1.but.not.in.Time2","Time2.but.not.in.Time1",
> >  > "BothTimes")
> >  > daT[cols.num] <- sapply(daT[cols.num],as.numeric)
> >  > summary(daT)
> >  > ProportionValue<-sum(daT$BothTimes, na.rm=T)/sum(daT$Time1,
> na.rm=T)
> >  > ProportionValue
> >  > standard error??
> >  >
> >  >   [[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, 

Re: [R] How to generate SE for the proportion value using a randomization process in R?

2021-01-23 Thread Rui Barradas

Hello,

Inline.

Às 07:47 de 23/01/21, Marna Wagley escreveu:

Dear Rui,
I was wondering whether we have to square root of SD to find SE, right?


No, we don't. var already divides by n, don't divide again.
This is the code, that can be seen by running the function name at a 
command line.



sd
#function (x, na.rm = FALSE)
#sqrt(var(if (is.vector(x) || is.factor(x)) x else as.double(x),
#na.rm = na.rm))
#
#





bootprop <- function(data, index){
    d <- data[index, ]
    sum(d[["BothTimes"]], na.rm = TRUE)/sum(d[["Time1"]], na.rm = TRUE)
}

R <- 1e3
set.seed(2020)
b <- boot(daT, bootprop, R)
b
b$t0     # original
sd(b$t)  # bootstrapped estimate of the SE of the sample prop.
sd(b$t)/sqrt(1000)
pandit*(1-pandit)

hist(b$t, freq = FALSE)



Try plotting the normal densities for both cases, the red line is 
clearly wrong.



f <- function(x, xbar, s){
  dnorm(x, mean = xbar, sd = s)
}

hist(b$t, freq = FALSE)
curve(f(x, xbar = b$t0, s = sd(b$t)), from = 0, to = 1, col = "blue", 
add = TRUE)
curve(f(x, xbar = b$t0, s = sd(b$t)/sqrt(R)), from = 0, to = 1, col = 
"red", add = TRUE)



Hope this helps,

Rui Barradas






On Fri, Jan 22, 2021 at 3:07 PM Rui Barradas > wrote:


Hello,

Something like this, using base package boot?


library(boot)

bootprop <- function(data, index){
    d <- data[index, ]
    sum(d[["BothTimes"]], na.rm = TRUE)/sum(d[["Time1"]], na.rm = TRUE)
}

R <- 1e3
set.seed(2020)
b <- boot(daT, bootprop, R)
b
b$t0     # original
sd(b$t)  # bootstrapped estimate of the SE of the sample prop.
hist(b$t, freq = FALSE)


Hope this helps,

Rui Barradas

Às 21:57 de 22/01/21, Marna Wagley escreveu:
 > Hi All,
 > I was trying to estimate standard error (SE) for the proportion
value using
 > some kind of randomization process (bootstrapping or jackknifing)
in R, but
 > I could not figure it out.
 >
 > Is there any way to generate SE for the proportion?
 >
 > The example of the data and the code I am using is attached for your
 > reference. I would like to generate the value of proportion with
a SE using
 > a 1000 times randomization.
 >
 > dat<-structure(list(Sample = structure(c(1L, 12L, 13L, 14L, 15L, 16L,
 > 17L, 18L, 19L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L), .Label
= c("id1",
 > "id10", "id11", "id12", "id13", "id14", "id15", "id16", "id17",
 > "id18", "id19", "Id2", "id3", "id4", "id5", "id6", "id7", "id8",
 > "id9"), class = "factor"), Time1 = c(0L, 1L, 1L, 1L, 0L, 0L,
 > 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L), Time2 = c(1L,
 > 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L,
 > 1L, 1L)), .Names = c("Sample", "Time1", "Time2"), class =
"data.frame",
 > row.names = c(NA,
 > -19L))
 > daT<-data.frame(dat %>%
 >    mutate(Time1.but.not.in.Time2 = case_when(
 >              Time1 %in% "1" & Time2 %in% "0"  ~ "1"),
 > Time2.but.not.in.Time1 = case_when(
 >              Time1 %in% "0" & Time2 %in% "1"  ~ "1"),
 >   BothTimes = case_when(
 >              Time1 %in% "1" & Time2 %in% "1"  ~ "1")))
 >   daT
 >   summary(daT)
 >
 > cols.num <- c("Time1.but.not.in.Time2","Time2.but.not.in.Time1",
 > "BothTimes")
 > daT[cols.num] <- sapply(daT[cols.num],as.numeric)
 > summary(daT)
 > ProportionValue<-sum(daT$BothTimes, na.rm=T)/sum(daT$Time1, na.rm=T)
 > ProportionValue
 > standard error??
 >
 >       [[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.