<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><div>Boa noite,</div><div><br></div><div>estou com um código que necessita o uso de um for dentro de um while. Entretanto, o uso do for aumentou o tempo de execução.</div><div><br></div><div>Gostaria de saber se alguém tem alguma sugestão para contornar este problema???? Acredito que a questão seja organizacional, portanto, não estou enviando um CMR mas caso seja necessário será encaminhado!!!!!!!  </div><div>   </div><div>                          dif <- 1</div><div>                          tol <- 1e-05                                                                  </div><div>                          i <- 0</div><div>                          neff <- c(2)</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>                     <span style="background-color: rgb(255, 255, 0);">  while(dif > tol){</span></div><div>                                    i <- i + 1</div><div>                                    LHS <- rBind( cBind(XpX, XpZ), cBind(ZpX, (ZpZ + Ginv)) )</div><div>                                    invLHS <- solve(LHS)</div><div>                                    est <- solve(LHS,RHS)</div><div>                                    b <- est[1:ncol(X.f),]</div><div>                                    u <- est[(ncol(X.f) + 1):nrow(est),]</div><div>                                    sig2E <- (ypy - t(b)%*%Xpy - t(u)%*%Zpy)/(N - rankX)</div><div>                                    sig2U <- numeric(0)                                  </div><div>                                           <span style="background-color: rgb(255, 255, 0);"> for(j in 1:length(neff)){</span></div><div>                                                 sig2U <- c(sig2U, ( t(est[z[j]:lz[j],])%*%est[z[j]:lz[j],] + sig2E*sum(diag( invLHS[z[j]:lz[j], z[j]:lz[j]] )) )/neff[j])                                                                                                </div><div>                                            }                                    </div><div>                                    sig2U <- do.call(rBind,lapply(sig2U,as.matrix))                                     </div><div>                                    rel <- as.numeric(sig2E)/sig2U</div><div>                                         if(!is.null(var)){</div><div>                                                lamb <- rel</div><div>                                                ratio <- rep(lamb,neff)</div><div>                                                newvar <- rBind(sig2U,sig2E)</div><div>                                                cds <- sig2U/sum(newvar) </div><div>                                                dif <- as.numeric(max(abs(newvar - ovar)))                                           </div><div>                                         }</div><div>                                         if(is.null(var)){</div><div>                                                lamb <- rel</div><div>                                                ratio <- rep(lamb,neff)</div><div>                                                newvar <- rBind(sig2U,sig2E)</div><div>                                                cds <- sig2U/sum(newvar) </div><div>                                                dif <- as.numeric(max(abs(cds - ocds)))                                                                                           </div><div>                                         }                                     </div><div>                                     ovar <- newvar</div><div>                                     ocds <- cds</div><div>                                     oratio <- ratio</div><div>                                     olamb <- lamb </div><div>                                     Ginv <- Diagonal(sum(neff),oratio)                                                                                      </div><div>                              }</div><div>Desde já agradeço por qualquer colaboração.</div><div><br></div><div>Atenciosamente,</div><div><br></div><div>Tiago.</div><div><br></div><br><div>#################################################################</div><div> </div><div>Tiago de Souza Marçal - Graduando em Agronomia pelo CCA-UFES</div><div> </div><div>Bolsista de Iniciação Científica da área de Genética e Melhoramento de Plantas</div><div> </div><div>################################################################# </div>                                      </div></body>
</html>