> optimize(function(x) -scores(x), interval=c(0.5, 0))
$minimum
[1] 0.1830174
$objective
[1] -11.67820
So the maximum is at x=0.183 with a score of 11.7, numerically.
Uwe Ligges
On 17.04.2010 16:30, Akito Y. Kawahara wrote:
Hi, I am new to R, and have a quick question regarding an R script
that I received from a kind colleague.
I am trying to determine the "peak" (maximum value) of the graph that
is plotted when executing the following. There is an input file called
"rates_values.txt" which begins as:
rateValue
0.375693
0
1.71274
0
0
1.02832
0
0.16343
1.02349
0
0
1.47258
0.703522
0.390541
1.83415
The script, below, must run with the rates_values.txt in the same dir.
#-------
rates<-read.table("rates_values.txt",header=T)
attach(rates)
scores<-function(x){
l<-length(rateValue)
total<-0
for(i in 1:l){
value<-16*rateValue[i]*rateValue[i]*x*exp(-4*rateValue[i]*x)
total<-total+value
}
return(total)
}
#-------
#preparing the plot
linewidth=3
linetype=3
color="blue"
xvalue=0.5
plot(scores,xvalue,0,type="n",font.axis=2,xlim=c(xvalue,0))
curve(scores,xvalue,add=TRUE,col=color,lty=linetype,lwd=linewidth,xlim=c(xvalue,0))
#-------
Can anyone help me figure out how to determine the peak (maximum
"scores") value in the plot that is generated? It should be about 11.7
but I would like to get an exact value. This should be a relatively
easy question, but I'm new to R, and what I have tried doesn't seem to
work.
Thanks!
______________________________________________
[email protected] 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.
______________________________________________
[email protected] 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.