Get the summary of results from the use of LOESS

4

I'd like to know how I can get the points that are generated by my curve. I'm having trouble getting the results of my last code statement.

In addition, I got the maximum and minimum points of the curve, but I would also like to get the first and last point of the curve. Can you get the first and last point on my curve?

I tried to use some concepts like head or summary, but they did not work for my last statement. My code is as follows:

 plot(dados.frame)
 dados.loess <- loess(duracao ~date_time, data=dados.frame)
 xl <- with(dados.frame, seq(min(date_time),max(date_time), (max(date_time) - min(date_time))/1000))
 y.predict <- predict(dados.loess, xl)
 lines(xl,y.predict)
 infl <- c(FALSE, diff(diff(y.predict)>0)!=0)
 points(xl[infl ], y.predict[infl ], col="Red", pch=19, cex=1.25)

As a result I have:

    
asked by anonymous 21.09.2015 / 05:30

2 answers

1

It's easier to answer by explaining each of your commands:

the command:

xl <- with(dados.frame, seq(min(date_time),max(date_time), (max(date_time) - min(date_time))/1000))

create a sequence with all dates between the minimum date and the maximum date you had in your database.

then:

y.predict <- predict(dados.loess, xl)

creates the predicted value of the duration, according to each date that was set to xl .

At this point you could already save a file with date and duration predicted by doing:

cbind(xl, y.predict)

Next commands look for inflection points. The following command creates a vector of TRUE or FALSE. TRUE indicating that the point is inflection.

infl <- c(FALSE, diff(diff(y.predict)>0)!=0)

So if you do

cbind(xl, y.predict)[infl,]

You will only get the lines that have inflection points.

To get the first and last point of the curve, you can do the following:

cbind(xl, y.predict)[xl == min(xl),] and cbind(xl, y.predict)[xl == max(xl),]

    
21.09.2015 / 16:40
0

You have to post a reproducible code. You can try:

cbind(xl,y.predict) # a curva
cbind(xl[infl ], y.predict[infl ])  # os pontos max/min
    
21.09.2015 / 16:27