Re: [R] for loop implementation in below problem

2021-03-21 Thread Jim Lemon
Hi Goyani,
You are setting "PRE" to the return value of "if" which is one of TRUE
(1), FALSE(0) or NULL. Because GAY is always missing in your example,
"PRE" is always set to 1. Then you always want to pass 1 in the sample
list, and that will not assign anything to PRE. By correcting the "if"
clause and defining matrices that are unlikely to be singular, I can
run a "for" loop as follows:

selection.index<- function(ID, phen_mat, gen_mat, weight_mat, GAY){
 p<-as.matrix(phen_mat)
 g<-as.matrix(gen_mat)
 w<-as.matrix(weight_mat)
 bmat<- solve(phen_mat) %*% gen_mat %*% weight_mat
 GA<- 2.063 * t(bmat) %*% g %*% w / (t(bmat) %*% p %*% bmat)^0.5
 if(missing(GAY)) PRE<-(GA/GA) * 100
 else PRE<-(GA/GAY) * 100
 result<-list(ID=ID,b=matrix(round(bmat,4),nrow=1),
  GA=round(GA,4),PRE=round(PRE,4))
 return(data.frame(result))
}

pmat<-matrix(sample(1:16,16),4)
gmat<-matrix(sample(17:32),16,4)
wmat<-matrix(sample(1:4,4),4)

mi<-combn(1:4,2)
sc<-list()
for(i in 1:ncol(matindx)) {
 as.numeric(ID<-paste0(mi[,i]))
 sc[[i]]<-selection.index(ID,pmat[mi[,i],mi[,i]],gmat[mi[,i],mi[,i]],
  wmat[mi[,i]],1)
}

This produces output for me. Good luck with whatever you are doing with this.

Jim





On Mon, Mar 22, 2021 at 2:51 PM Goyani Zankrut  wrote:
>
> Greetings of the day,
> Thank you for your response, Sir.
> The full problem statement is given below:
>
> In our case, I'm taking 4 traits.
> library(arrangements)
> a<- combinations(4,2) # gives 6 pairwise combinations
> class(a) # it's a "matrix" "array"
>
> now hypothetical data of three matrix for further calculation:
> pmat<- matrix(1:16, nrow = 4)
> gmat<- matrix(17:32, nrow = 4)
> wmat<- matrix(1:4, nrow = 4)
>
> My custom function for further calculations:
> selection.index<- function(ID, phen_mat, gen_mat, weight_mat, GAY){
>   ID = toString(ID)
>   p<- as.matrix(phen_mat)
>   g<- as.matrix(gen_mat)
>   w<- as.matrix(weight_mat)
>   bmat<- solve(phen_mat) %*% gen_mat %*% weight_mat
>   GA<- 2.063 * t(bmat) %*% g %*% w / (t(bmat) %*% p %*% bmat)^0.5
>   PRE<- if(missing(GAY)){
> (GA/GA) * 100
>   } else {
> (GA/GAY) * 100
>   }
>   result<- list("ID" = ID, "b" = matrix(round(bmat,4), nrow = 1), "GA" = 
> round(GA,4), "PRE" = round(PRE,4))
>   return(data.frame(result))
> }
>
> Now I want to store this data into a list for further calculation:
> sc<- list()
> sc[[1]]<- selection.index(ID = 12, phen_mat = pmat[c(1,2),c(1,2)], gen_mat = 
> gmat[c(1,2),c(1,2)], weight_mat = wmat[c(1,2),1])
> sc[[2]]<- selection.index(ID = 13, phen_mat = pmat[c(1,3),c(1,3)], gen_mat = 
> gmat[c(1,3),c(1,3)], weight_mat = wmat[c(1,3),1])
> sc[[3]]<- selection.index(ID = 14, phen_mat = pmat[c(1,4),c(1,4)], gen_mat = 
> gmat[c(1,4),c(1,4)], weight_mat = wmat[c(1,4),1])
> sc[[4]]<- selection.index(ID = 23, phen_mat = pmat[c(2,3),c(2,3)], gen_mat = 
> gmat[c(2,3),c(2,3)], weight_mat = wmat[c(2,3),1])
> sc[[5]]<- selection.index(ID = 24, phen_mat = pmat[c(2,4),c(2,4)], gen_mat = 
> gmat[c(2,4),c(2,4)], weight_mat = wmat[c(2,4),1])
> sc[[6]]<- selection.index(ID = 34, phen_mat = pmat[c(3,4),c(3,4)], gen_mat = 
> gmat[c(3,4),c(3,4)], weight_mat = wmat[c(3,4),1])
> above list code is monotonous and time consuming for large data combination 
> cycles like (7,2) = 21 combinations, (10,2) = 45 combinations. So I want to 
> use the matrix a's each row as a vector in the selection.index function and 
> result stores in a list.
>
> I hope now you will understand the full problem. I have checked the 
> selection.index which has no issues and works well.
> Thank you.
>

__
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] using aws.s3::s3 sync to dowlaod files from public s3 Bucket without credentials?

2021-03-21 Thread nevil amos
Hi I am developing a package that reives on some large datasets stored in
aws s3.
I have made the bucket and all objects in the bucket public, but still
cannot sync them to my local directory without providing my AWS key pair.
without these credentials I get a "bucket does not exist" message.

Should it be possible to "see" and use
Sys.setenv("AWS_DEFAULT_REGION" =MYDEFAULTREGION)
aws.s3::s3sync (path ="./", bucket=MYBUCKETNAME,check_region = F,direction
= "download")

to download the bucket contents without providing a keypair where both
bucket and contents are public?

thanks

Nevil Amos

[[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] Rstudio crashed when I try to train a nnet model.

2021-03-21 Thread Jiefei Wang
Hi Baki,

This should be a different issue. It looks like there is no problem in the
R terminal. Does the crash happen every time when you run the code in
RStudio? If so, this should be a bug in RStudio and you need to consult
RStudio's mailing list as R and RStudio are maintained by different teams.

Best,
Jiefei

On Mon, Mar 22, 2021 at 12:57 AM Baki UNAL  wrote:

> Hi Jiefei
>
> I run the code below in RGui
>
> > nn2 <- nnet(TQ~.,data = train, size=c(15,15), linout=T, MaxNWts =4000,
> maxit=2000)
>
> But I got the following output:
>
> # weights:  435
> initial  value 55650.887782
> final  value 55650.887782
> converged
>
> Program early converged. Program didn't any calculations.
>
> Best,
> Baki
>
> On Sunday, March 21, 2021, 07:35:31 PM GMT+3, Jiefei Wang <
> szwj...@gmail.com> wrote:
>
>
> Hi Baki,
>
> Perhaps out of memory? Would you be able to run your code through the R
> terminal? It probably can give us more information to debug the issue.
>
> Best,
> Jiefei
>
> On Mon, Mar 22, 2021 at 12:23 AM Baki UNAL via R-help <
> r-help@r-project.org> wrote:
>
> Hi,
> I tried to train a neural network with following code:
> nn2 <- nnet(TQ~.,data = train, size=c(15,15), linout=T, MaxNWts =4000,
> maxit=2000)
>
> When I executed the code R studio crashed with following error:
> "R Session Aborted
> R encountered a fatal error.
> The session was terminated.
> Start new session"
> When I set the hidden layer as c(15) as below the code works fine.
> nn2 <- nnet(TQ~.,data = train, size=c(15), linout=T, MaxNWts =4000,
> maxit=2000)
>
> What could be the problem?
>
> Best regards.
>
>
> [[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] for loop implementation in below problem

2021-03-21 Thread Jim Lemon
Hi Goyani,
In its present form, the function stalls because you haven't defined
pmat before trying to pass it to the function. gmat and wmat suffered
the same fate. Even if I define these matrices as I think you have,
"solve" fails because at least one is singular. First, put the
function in order as below. I think this is what you sent made
readable.

selection.index<- function(ID, phen_mat, gen_mat, weight_mat, GAY){
 ID<-toString(ID)
 p<-as.matrix(phen_mat)
 g<-as.matrix(gen_mat)
 w<-as.matrix(weight_mat)
 bmat<- solve(phen_mat) %*% gen_mat %*% weight_mat
 GA<- 2.063 * t(bmat) %*% g %*% w / (t(bmat) %*% p %*% bmat)^0.5
 if(missing(GAY)) PRE<-(GA/GA) * 100
 else PRE<-(GA/GAY) * 100
 result<-list(ID=ID,b=matrix(round(bmat,4),nrow=1),
  GA=round(GA,4),PRE=round(PRE,4))
 return(data.frame(result))
}

Next, what sort of matrices do you want to pass? Then an answer may emerge.

Jim

On Mon, Mar 22, 2021 at 6:03 AM Goyani Zankrut  wrote:
>
> I created custom function according to my requirement which is given below:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *selection.index<- function(ID, phen_mat, gen_mat, weight_mat, GAY){  ID =
> toString(ID)  p<- as.matrix(phen_mat)  g<- as.matrix(gen_mat)  w<-
> as.matrix(weight_mat)  bmat<- solve(phen_mat) %*% gen_mat %*% weight_mat
> GA<- 2.063 * t(bmat) %*% g %*% w / (t(bmat) %*% p %*% bmat)^0.5  PRE<-
> if(missing(GAY)){(GA/GA) * 100  } else {(GA/GAY) * 100  }  result<-
> list("ID" = ID, "b" = matrix(round(bmat,4), nrow = 1), "GA" = round(GA,4),
> "PRE" = round(PRE,4))  return(data.frame(result))}*
>
> *sc<- list()*
> *sc[[1]]<- selection.index(ID = 12, pmat[1:2,1:2], gmat[1:2,1:2],
> wmat[1:2,1])*
> *sc[[2]]<- selection.index(ID = 13, pmat[c(1,3),c(1,3)],
> gmat[c(1,3),c(1,3)], wmat[c(1,3),1])*
>
> for more detail about question follow stack overflow link:
> https://stackoverflow.com/questions/66734928/how-to-solve-this-through-loop
> *"Healthy soil, Healthy life."*
> *"A war based on Satyagraha is always of two kinds. One is the war we wage
> against injustice, and the other we fight our won weaknesses."* - *Sardar
> Patel*
> *"You have to dream before your dreams can come true."* - *A. P. J.* *Abdul
> Kalam*
> *"Think before you print and save a tree."*
>
> *ZANKRUT GOYANI*
> *B.Sc. (Hons.) Agriculture*
>
> [[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] Colorizing contribution of variables

2021-03-21 Thread Mahmood Naderan-Tahan
Yes I am using factoextra.


>When you choose the argument "contrib" the colors are based on the
>strength of the relationship overall (the length of the arrow), not
>the contribution of any individual direction.


Then, the question is why the legend is not in 0 to 1 scale?


Regards,
Mahmood


From: Sarah Goslee 
Sent: Sunday, March 21, 2021 8:26:55 PM
To: Mahmood Naderan-Tahan
Cc: r-help@r-project.org
Subject: Re: [R] Colorizing contribution of variables

Hi,

I am going to assume that you are using factoextra, and are working
the example from the function in question, but it would be useful for
you to explicitly state that when you're asking a question about a
particular package and function.

When you choose the argument "contrib" the colors are based on the
strength of the relationship overall (the length of the arrow), not
the contribution of any individual direction.

See here 
http://www.sthda.com/english/wiki/factoextra-r-package-easy-multivariate-data-analyses-and-elegant-visualization
and the various other sources of documentation for the packages.

Sarah

On Sun, Mar 21, 2021 at 1:32 PM Mahmood Naderan-Tahan
 wrote:
>
> Hi
>
> I use the following function to plot the variables with their contributions.
>
>
> fviz_famd_var(res.famd, "quanti.var", col.var = "contrib",
>   gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
>   repel = TRUE)
>
>
> The result can be seen at https://i.stack.imgur.com/Kbq1j.png
>
> When I use "quanti.var$contrib" I see multiple dimensions and the question is 
> which dimension is used for colorizing the contributions? For example, is the 
> blue color of V2 related to low contribution on Dim1 or Dim2?
>
>
> Regards,
> Mahmood
>
> [[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.



--
Sarah Goslee (she/her)
http://www.numberwright.com

[[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] About fviz_famd_ind()

2021-03-21 Thread Sarah Goslee
The way to start is looking at the help for that function, which includes:

... Arguments to be passed to the function fviz()

so you may have more low-level control through those arguments. If
fviz() itself doesn't do what you want, it also allows you to pass
additional arguments to its lower-level functions. If you go down far
enough, you should be able to control everything.

Sarah

On Sun, Mar 21, 2021 at 1:12 PM Mahmood Naderan-Tahan
 wrote:
>
> Hi
>
> I use fviz_famd_ind() from factoextra and I would like to know
>
> 1) How can I decrease the font size?
>
> 2) How to increase max.overlaps?
>
>
> ind <- get_famd_ind(res.famd)
> fviz_famd_ind(res.famd, col.ind = "cos2",
>   gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
>   repel = TRUE)
>
>
> Regards,
> Mahmood
>
> [[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.



-- 
Sarah Goslee (she/her)
http://www.numberwright.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] Colorizing contribution of variables

2021-03-21 Thread Sarah Goslee
Hi,

I am going to assume that you are using factoextra, and are working
the example from the function in question, but it would be useful for
you to explicitly state that when you're asking a question about a
particular package and function.

When you choose the argument "contrib" the colors are based on the
strength of the relationship overall (the length of the arrow), not
the contribution of any individual direction.

See here 
http://www.sthda.com/english/wiki/factoextra-r-package-easy-multivariate-data-analyses-and-elegant-visualization
and the various other sources of documentation for the packages.

Sarah

On Sun, Mar 21, 2021 at 1:32 PM Mahmood Naderan-Tahan
 wrote:
>
> Hi
>
> I use the following function to plot the variables with their contributions.
>
>
> fviz_famd_var(res.famd, "quanti.var", col.var = "contrib",
>   gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
>   repel = TRUE)
>
>
> The result can be seen at https://i.stack.imgur.com/Kbq1j.png
>
> When I use "quanti.var$contrib" I see multiple dimensions and the question is 
> which dimension is used for colorizing the contributions? For example, is the 
> blue color of V2 related to low contribution on Dim1 or Dim2?
>
>
> Regards,
> Mahmood
>
> [[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.



-- 
Sarah Goslee (she/her)
http://www.numberwright.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.


[R] for loop implementation in below problem

2021-03-21 Thread Goyani Zankrut
I created custom function according to my requirement which is given below:














*selection.index<- function(ID, phen_mat, gen_mat, weight_mat, GAY){  ID =
toString(ID)  p<- as.matrix(phen_mat)  g<- as.matrix(gen_mat)  w<-
as.matrix(weight_mat)  bmat<- solve(phen_mat) %*% gen_mat %*% weight_mat
GA<- 2.063 * t(bmat) %*% g %*% w / (t(bmat) %*% p %*% bmat)^0.5  PRE<-
if(missing(GAY)){(GA/GA) * 100  } else {(GA/GAY) * 100  }  result<-
list("ID" = ID, "b" = matrix(round(bmat,4), nrow = 1), "GA" = round(GA,4),
"PRE" = round(PRE,4))  return(data.frame(result))}*

*sc<- list()*
*sc[[1]]<- selection.index(ID = 12, pmat[1:2,1:2], gmat[1:2,1:2],
wmat[1:2,1])*
*sc[[2]]<- selection.index(ID = 13, pmat[c(1,3),c(1,3)],
gmat[c(1,3),c(1,3)], wmat[c(1,3),1])*

for more detail about question follow stack overflow link:
https://stackoverflow.com/questions/66734928/how-to-solve-this-through-loop
*"Healthy soil, Healthy life."*
*"A war based on Satyagraha is always of two kinds. One is the war we wage
against injustice, and the other we fight our won weaknesses."* - *Sardar
Patel*
*"You have to dream before your dreams can come true."* - *A. P. J.* *Abdul
Kalam*
*"Think before you print and save a tree."*

*ZANKRUT GOYANI*
*B.Sc. (Hons.) Agriculture*

[[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] Optimization function producing negative parameter values

2021-03-21 Thread J C Nash
This is likely because Hessian is being approximated.

Numerical approximation to Hessian will overstep the bounds because
the routines that are called don't respect the bounds (they likely
don't have the bounds available).

Writing numerical approximations that respect bounds and other constraints
is an interesting and very challenging problem. It's likely a lot easier to
do the work and get the derivatives analytically.

JN

On 2021-03-21 1:50 p.m., Bill Dunlap wrote:
> Does optim go out of bounds when you specify hessian=FALSE?
> hessian=TRUE causes some out-of-bounds evaluations of f.
> 
>> optim(c(X=1,Y=1), 
>> function(XY){print(unname(XY));(XY[["X"]]+1)^4+(XY[["Y"]]-2)^4}, method= 
>> "L-BFGS-B", lower=c(0.001,0.001), upper=c(1.5,1.5), hessian=TRUE)
> [1] 1 1
> [1] 1.001 1.000
> [1] 0.999 1.000
> [1] 1.000 1.001
> [1] 1.000 0.999
> [1] 0.001 1.500
> [1] 0.002 1.500
> [1] 0.001 1.500
> [1] 0.001 1.500
> [1] 0.001 1.499
> [1] 0.003 1.500
> [1] 0.001 1.500
> [1] 0.002 1.501
> [1] 0.002 1.499
> [1] 0.001 1.500
> [1] -0.001  1.500
> [1] 0.000 1.501
> [1] 0.000 1.499
> [1] 0.002 1.501
> [1] 0.000 1.501
> [1] 0.001 1.502
> [1] 0.001 1.500
> [1] 0.002 1.499
> [1] 0.000 1.499
> [1] 0.001 1.500
> [1] 0.001 1.498
> $par
> X Y
> 0.001 1.500
> 
> $value
> [1] 1.066506
> 
> On Sun, Mar 21, 2021 at 10:22 AM Shah Alam  wrote:
>>
>> Dear all,
>>
>> I am using optim() to estimate unknown parameters by minimizing the
>> residual sums of squares. I created a function with the model. The model is
>> working fine. The optim function is producing negative parameter values, even
>> I have introduced upper and lower bounds (given in code). Therefore,
>> the model produces *NAs*.
>>
>> Following is my code.
>>
>> param <<- c(0.002,0.002, 0.14,0.012,0.01,0.02, 0.03, 0.001)# initial
>>> parameter values
>>> opt <- optim(param, fn= f.opt, obsdata =obsdata_1, method= "L-BFGS-B",
>>> lower = c(0.001, 0.001, 0.08,0.008, 0.009, 0.008, 0.009, 0.001),
>>
>> upper = c(0.00375, 0.002, 0.2, 0.018, 0.08, 0.08, 0.08, 0.01),
>>> control=list(maxit=10), hessian = T)
>>
>>
>> Error:
>>
>> *"NAs producedError in if (rnd_1 < liferisk) { : missing value where
>> TRUE/FALSE needed "*
>>
>> The model function which produces NA due to negative parameter values
>>
>> liferisk <- rnorm(n = 1, mean =
>> (calib_para[which(names(calib_para)=="r_mu")]),sd =
>> (calib_para[which(names(calib_para)=="r_sd")]))
>>
>>   rnd_1 <- runif(1, 0, 1)
>>
>>   if (rnd_1 < liferisk) { ca_case <- 1} else {ca_case <- 0}
>>
>>
>> How to design/ modify optim() function, and upper-lower bounds to stop
>> producing negative values during parameter search?
>> Thanks
>>
>> Best regards,
>> Shah
>>
>> [[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.
>

__
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] Optimization function producing negative parameter values

2021-03-21 Thread Bill Dunlap
Does optim go out of bounds when you specify hessian=FALSE?
hessian=TRUE causes some out-of-bounds evaluations of f.

> optim(c(X=1,Y=1), 
> function(XY){print(unname(XY));(XY[["X"]]+1)^4+(XY[["Y"]]-2)^4}, method= 
> "L-BFGS-B", lower=c(0.001,0.001), upper=c(1.5,1.5), hessian=TRUE)
[1] 1 1
[1] 1.001 1.000
[1] 0.999 1.000
[1] 1.000 1.001
[1] 1.000 0.999
[1] 0.001 1.500
[1] 0.002 1.500
[1] 0.001 1.500
[1] 0.001 1.500
[1] 0.001 1.499
[1] 0.003 1.500
[1] 0.001 1.500
[1] 0.002 1.501
[1] 0.002 1.499
[1] 0.001 1.500
[1] -0.001  1.500
[1] 0.000 1.501
[1] 0.000 1.499
[1] 0.002 1.501
[1] 0.000 1.501
[1] 0.001 1.502
[1] 0.001 1.500
[1] 0.002 1.499
[1] 0.000 1.499
[1] 0.001 1.500
[1] 0.001 1.498
$par
X Y
0.001 1.500

$value
[1] 1.066506

On Sun, Mar 21, 2021 at 10:22 AM Shah Alam  wrote:
>
> Dear all,
>
> I am using optim() to estimate unknown parameters by minimizing the
> residual sums of squares. I created a function with the model. The model is
> working fine. The optim function is producing negative parameter values, even
> I have introduced upper and lower bounds (given in code). Therefore,
> the model produces *NAs*.
>
> Following is my code.
>
> param <<- c(0.002,0.002, 0.14,0.012,0.01,0.02, 0.03, 0.001)# initial
> > parameter values
> > opt <- optim(param, fn= f.opt, obsdata =obsdata_1, method= "L-BFGS-B",
> > lower = c(0.001, 0.001, 0.08,0.008, 0.009, 0.008, 0.009, 0.001),
>
> upper = c(0.00375, 0.002, 0.2, 0.018, 0.08, 0.08, 0.08, 0.01),
> > control=list(maxit=10), hessian = T)
>
>
> Error:
>
> *"NAs producedError in if (rnd_1 < liferisk) { : missing value where
> TRUE/FALSE needed "*
>
> The model function which produces NA due to negative parameter values
>
> liferisk <- rnorm(n = 1, mean =
> (calib_para[which(names(calib_para)=="r_mu")]),sd =
> (calib_para[which(names(calib_para)=="r_sd")]))
>
>   rnd_1 <- runif(1, 0, 1)
>
>   if (rnd_1 < liferisk) { ca_case <- 1} else {ca_case <- 0}
>
>
> How to design/ modify optim() function, and upper-lower bounds to stop
> producing negative values during parameter search?
> Thanks
>
> Best regards,
> Shah
>
> [[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.


[R] Colorizing contribution of variables

2021-03-21 Thread Mahmood Naderan-Tahan
Hi

I use the following function to plot the variables with their contributions.


fviz_famd_var(res.famd, "quanti.var", col.var = "contrib",
  gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
  repel = TRUE)


The result can be seen at https://i.stack.imgur.com/Kbq1j.png

When I use "quanti.var$contrib" I see multiple dimensions and the question is 
which dimension is used for colorizing the contributions? For example, is the 
blue color of V2 related to low contribution on Dim1 or Dim2?


Regards,
Mahmood

[[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] Optimization function producing negative parameter values

2021-03-21 Thread J C Nash
Can you put together your example as a single runnable scipt?

If so, I'll try some other tools to see what is going on. There
have been rumours of some glitches in the L-BFGS-B R implementation,
but so far I've not been able to acquire any that I can reproduce.

John Nash (maintainer of optimx package and some other optimization tools)





On 2021-03-21 1:20 p.m., Shah Alam wrote:
> Dear all,
> 
> I am using optim() to estimate unknown parameters by minimizing the
> residual sums of squares. I created a function with the model. The model is
> working fine. The optim function is producing negative parameter values, even
> I have introduced upper and lower bounds (given in code). Therefore,
> the model produces *NAs*.
> 
> Following is my code.
> 
> param <<- c(0.002,0.002, 0.14,0.012,0.01,0.02, 0.03, 0.001)# initial
>> parameter values
>> opt <- optim(param, fn= f.opt, obsdata =obsdata_1, method= "L-BFGS-B",
>> lower = c(0.001, 0.001, 0.08,0.008, 0.009, 0.008, 0.009, 0.001),
> 
> upper = c(0.00375, 0.002, 0.2, 0.018, 0.08, 0.08, 0.08, 0.01),
>> control=list(maxit=10), hessian = T)
> 
> 
> Error:
> 
> *"NAs producedError in if (rnd_1 < liferisk) { : missing value where
> TRUE/FALSE needed "*
> 
> The model function which produces NA due to negative parameter values
> 
> liferisk <- rnorm(n = 1, mean =
> (calib_para[which(names(calib_para)=="r_mu")]),sd =
> (calib_para[which(names(calib_para)=="r_sd")]))
> 
>   rnd_1 <- runif(1, 0, 1)
> 
>   if (rnd_1 < liferisk) { ca_case <- 1} else {ca_case <- 0}
> 
> 
> How to design/ modify optim() function, and upper-lower bounds to stop
> producing negative values during parameter search?
> Thanks
> 
> Best regards,
> Shah
> 
>   [[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.


[R] Optimization function producing negative parameter values

2021-03-21 Thread Shah Alam
Dear all,

I am using optim() to estimate unknown parameters by minimizing the
residual sums of squares. I created a function with the model. The model is
working fine. The optim function is producing negative parameter values, even
I have introduced upper and lower bounds (given in code). Therefore,
the model produces *NAs*.

Following is my code.

param <<- c(0.002,0.002, 0.14,0.012,0.01,0.02, 0.03, 0.001)# initial
> parameter values
> opt <- optim(param, fn= f.opt, obsdata =obsdata_1, method= "L-BFGS-B",
> lower = c(0.001, 0.001, 0.08,0.008, 0.009, 0.008, 0.009, 0.001),

upper = c(0.00375, 0.002, 0.2, 0.018, 0.08, 0.08, 0.08, 0.01),
> control=list(maxit=10), hessian = T)


Error:

*"NAs producedError in if (rnd_1 < liferisk) { : missing value where
TRUE/FALSE needed "*

The model function which produces NA due to negative parameter values

liferisk <- rnorm(n = 1, mean =
(calib_para[which(names(calib_para)=="r_mu")]),sd =
(calib_para[which(names(calib_para)=="r_sd")]))

  rnd_1 <- runif(1, 0, 1)

  if (rnd_1 < liferisk) { ca_case <- 1} else {ca_case <- 0}


How to design/ modify optim() function, and upper-lower bounds to stop
producing negative values during parameter search?
Thanks

Best regards,
Shah

[[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] About fviz_famd_ind()

2021-03-21 Thread Mahmood Naderan-Tahan
Hi

I use fviz_famd_ind() from factoextra and I would like to know

1) How can I decrease the font size?

2) How to increase max.overlaps?


ind <- get_famd_ind(res.famd)
fviz_famd_ind(res.famd, col.ind = "cos2",
  gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
  repel = TRUE)


Regards,
Mahmood

[[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] Rstudio crashed when I try to train a nnet model.

2021-03-21 Thread Baki UNAL via R-help
 Hi Jiefei
I run the code below in RGui
> nn2 <- nnet(TQ~.,data = train, size=c(15,15), linout=T, MaxNWts =4000, 
> maxit=2000)

But I got the following output:
# weights:  435initial  value 55650.887782 final  value 55650.887782 converged
Program early converged. Program didn't any calculations. 
Best,Baki
On Sunday, March 21, 2021, 07:35:31 PM GMT+3, Jiefei Wang 
 wrote:  
 
 Hi Baki,
Perhaps out of memory? Would you be able to run your code through the R 
terminal? It probably can give us more information to debug the issue. 
Best,Jiefei
On Mon, Mar 22, 2021 at 12:23 AM Baki UNAL via R-help  
wrote:

Hi,
I tried to train a neural network with following code:
nn2 <- nnet(TQ~.,data = train, size=c(15,15), linout=T, MaxNWts =4000, 
maxit=2000)

When I executed the code R studio crashed with following error:
"R Session Aborted
R encountered a fatal error.
The session was terminated.
Start new session"
When I set the hidden layer as c(15) as below the code works fine.
nn2 <- nnet(TQ~.,data = train, size=c(15), linout=T, MaxNWts =4000, maxit=2000)

What could be the problem?

Best regards.


        [[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] Rstudio crashed when I try to train a nnet model.

2021-03-21 Thread Jiefei Wang
Hi Baki,

Perhaps out of memory? Would you be able to run your code through the R
terminal? It probably can give us more information to debug the issue.

Best,
Jiefei

On Mon, Mar 22, 2021 at 12:23 AM Baki UNAL via R-help 
wrote:

> Hi,
> I tried to train a neural network with following code:
> nn2 <- nnet(TQ~.,data = train, size=c(15,15), linout=T, MaxNWts =4000,
> maxit=2000)
>
> When I executed the code R studio crashed with following error:
> "R Session Aborted
> R encountered a fatal error.
> The session was terminated.
> Start new session"
> When I set the hidden layer as c(15) as below the code works fine.
> nn2 <- nnet(TQ~.,data = train, size=c(15), linout=T, MaxNWts =4000,
> maxit=2000)
>
> What could be the problem?
>
> Best regards.
>
>
> [[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] Rstudio crashed when I try to train a nnet model.

2021-03-21 Thread Baki UNAL via R-help
Hi,
I tried to train a neural network with following code:
nn2 <- nnet(TQ~.,data = train, size=c(15,15), linout=T, MaxNWts =4000, 
maxit=2000)

When I executed the code R studio crashed with following error:
"R Session Aborted
R encountered a fatal error.
The session was terminated.
Start new session"
When I set the hidden layer as c(15) as below the code works fine.
nn2 <- nnet(TQ~.,data = train, size=c(15), linout=T, MaxNWts =4000, maxit=2000)

What could be the problem?

Best regards.


[[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] How to average minutes per hour per month in the form of '# hours #minutes'

2021-03-21 Thread Dr Eberhard W Lisse

Hi,

I have minutes worked by day (with some more information)

which when using

library(tidyverse)
library(lubridate)

run through

CONSMINUTES %>%
select(datum, dauer) %>%
arrange(desc(datum))

look somewhat like

# A tibble: 142 x 2
   datum  dauer

 1 2021-03-1830
 2 2021-03-1730
 3 2021-03-1630
 4 2021-03-1630
 5 2021-03-1630
 6 2021-03-1630
 7 2021-03-1130
 8 2021-03-1130
 9 2021-03-1130
10 2021-03-1130
# … with 132 more rows

I can extract minutes per hour

CONSMINUTES %>%
select(datum, dauer) %>%
group_by(week = format(datum, '%Y %V'))%>%
summarise_if(is.numeric, sum)

and minutes per month

CONSMINUTES %>%
select(datum, dauer) %>%
group_by(month = format(datum, '%Y %m'))%>%
summarise_if(is.numeric, sum)

I need to show the time worked per week per month in the format of

'# hours # minutes'

and would like to also be able to show the average time per week per
month.

How can I do that (preferably with tidyverse :-)-O)?

greetings, el

__
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] R-help Digest, Vol 217, Issue 20

2021-03-21 Thread Bert Gunter
... or a George Box (I believe) said: The crucial "Declaration of
Independence."


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 Sat, Mar 20, 2021 at 4:25 PM John Maindonald 
wrote:

> No, it is not distribution free.  Independent random sampling is assumed.
> That is a non-trivial assumption, and one that is very often not true or
> not
> strictly true.
>
>
> John Maindonald email: john.maindon...@anu.edu.au john.maindon...@anu.edu.au>
>
>
> On 21/03/2021, at 00:00, r-help-requ...@r-project.org r-help-requ...@r-project.org> wrote:
>
> From: Jiefei Wang mailto:szwj...@gmail.com>>
> Subject: Re: [R] about a p-value < 2.2e-16
> Date: 20 March 2021 at 04:41:33 NZDT
> To: Spencer Graves  spencer.gra...@effectivedefense.org>>
> Cc: Bogdan Tanasa mailto:tan...@gmail.com>>, Vivek Das <
> vd4mm...@gmail.com>, r-help <
> r-help@r-project.org>
>
>
> Hi Spencer,
>
> Thanks for your test results, I do not know the answer as I haven't
> used wilcox.test for many years. I do not know if it is possible to compute
> the exact distribution of the Wilcoxon rank sum statistic, but I think it
> is very likely, as the document of `Wilcoxon` says:
>
> This distribution is obtained as follows. Let x and y be two random,
> independent samples of size m and n. Then the Wilcoxon rank sum statistic
> is the number of all pairs (x[i], y[j]) for which y[j] is not greater than
> x[i]. This statistic takes values between 0 and m * n, and its mean and
> variance are m * n / 2 and m * n * (m + n + 1) / 12, respectively.
>
> As a nice feature of the non-parametric statistic, it is usually
> distribution-free so you can pick any distribution you like to compute the
> same statistic. I wonder if this is the case, but I might be wrong.
>
> Cheers,
> Jiefei
>
>
>
> [[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.