Skip to main content
edited tags; edited title
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

Optimize while loop in R Solving for solving a seeedseed value in R

added 138 characters in body
Source Link
Hack-R
  • 262
  • 4
  • 17

I'm trying to reproduce a gbm model which was estimated without a set.seed value. To do so I need to determine what seed was used, which I can figure out based on one of the summary metrics from the estimated model (as shown below).

require(MatchIt) require(gbm) data("lalonde") i <- 1 while(!(tmp$rel.inf[1] == 82.3429390)){ gps <- gbm(treat ~ age + educ + nodegree + re74 + re75, distribution = "bernoulli", data = lalonde, n.trees = 100, interaction.depth = 4, train.fraction = 0.8, shrinkage=0.0005, set.seed(i)) tmp <- summary(gps, plotit=F) cat(i,"\n") i <- i + 1 } 

I think it would be very helpful both for this specific use case and for general future reference to know of any more efficient way of carrying this out. A multicore solution might be a good way to go; I'm researching that myself now. Or perhaps there's a way to improve it by using apply?

I'm trying to reproduce a gbm model which was estimated without a set.seed value. To do so I need to determine what seed was used, which I can figure out based on one of the summary metrics from the estimated model (as shown below).

require(MatchIt) require(gbm) data("lalonde") i <- 1 while(!(tmp$rel.inf[1] == 82.3429390)){ gps <- gbm(treat ~ age + educ + nodegree + re74 + re75, distribution = "bernoulli", data = lalonde, n.trees = 100, interaction.depth = 4, train.fraction = 0.8, shrinkage=0.0005, set.seed(i)) tmp <- summary(gps, plotit=F) cat(i,"\n") i <- i + 1 } 

I think it would be very helpful both for this specific use case and for general future reference to know of any more efficient way of carrying this out.

I'm trying to reproduce a gbm model which was estimated without a set.seed value. To do so I need to determine what seed was used, which I can figure out based on one of the summary metrics from the estimated model (as shown below).

require(MatchIt) require(gbm) data("lalonde") i <- 1 while(!(tmp$rel.inf[1] == 82.3429390)){ gps <- gbm(treat ~ age + educ + nodegree + re74 + re75, distribution = "bernoulli", data = lalonde, n.trees = 100, interaction.depth = 4, train.fraction = 0.8, shrinkage=0.0005, set.seed(i)) tmp <- summary(gps, plotit=F) cat(i,"\n") i <- i + 1 } 

I think it would be very helpful both for this specific use case and for general future reference to know of any more efficient way of carrying this out. A multicore solution might be a good way to go; I'm researching that myself now. Or perhaps there's a way to improve it by using apply?

solved part of the problem with , plotit=F
Source Link
Hack-R
  • 262
  • 4
  • 17

I'm trying to reproduce a gbm model which was estimated without a set.seed value. To do so I need to determine what seed was used, which I can figure out based on one of the summary metrics from the estimated model (as shown below).

require(MatchIt) require(gbm) data("lalonde") i <- 1 while(!(tmp$rel.inf[1] == 82.3429390)){ gps <- gbm(treat ~ age + educ + nodegree + re74 + re75, distribution = "bernoulli", data = lalonde, n.trees = 100, interaction.depth = 4, train.fraction = 0.8, shrinkage=0.0005, set.seed(i)) tmp <- summary(gps, plotit=F) cat(i,"\n") i <- i + 1 } 

Theoretically, the above code should work. However more times than not it freezes or crashes RStudio and sometimes (like now) it just seems to run forever. It's unclear if it's really running or not because my screen printing fails with the error:

Error in is.factor(f) : Shadow graphics device error: r error 4 (R code execution error)

I think it would be very helpful both for this specific use case and for general future reference to know of any more efficient way of carrying this out.

I'm trying to reproduce a gbm model which was estimated without a set.seed value. To do so I need to determine what seed was used, which I can figure out based on one of the summary metrics from the estimated model (as shown below).

require(MatchIt) require(gbm) data("lalonde") i <- 1 while(!(tmp$rel.inf[1] == 82.3429390)){ gps <- gbm(treat ~ age + educ + nodegree + re74 + re75, distribution = "bernoulli", data = lalonde, n.trees = 100, interaction.depth = 4, train.fraction = 0.8, shrinkage=0.0005, set.seed(i)) tmp <- summary(gps) cat(i,"\n") i <- i + 1 } 

Theoretically, the above code should work. However more times than not it freezes or crashes RStudio and sometimes (like now) it just seems to run forever. It's unclear if it's really running or not because my screen printing fails with the error:

Error in is.factor(f) : Shadow graphics device error: r error 4 (R code execution error)

I think it would be very helpful both for this specific use case and for general future reference to know of any more efficient way of carrying this out.

I'm trying to reproduce a gbm model which was estimated without a set.seed value. To do so I need to determine what seed was used, which I can figure out based on one of the summary metrics from the estimated model (as shown below).

require(MatchIt) require(gbm) data("lalonde") i <- 1 while(!(tmp$rel.inf[1] == 82.3429390)){ gps <- gbm(treat ~ age + educ + nodegree + re74 + re75, distribution = "bernoulli", data = lalonde, n.trees = 100, interaction.depth = 4, train.fraction = 0.8, shrinkage=0.0005, set.seed(i)) tmp <- summary(gps, plotit=F) cat(i,"\n") i <- i + 1 } 

I think it would be very helpful both for this specific use case and for general future reference to know of any more efficient way of carrying this out.

Source Link
Hack-R
  • 262
  • 4
  • 17
Loading