Skip to content
Prev 19694 / 29559 Next

Fit a sine curve to raster stack

Dear Sofea,

You could try something like this:

fun3 <- function(x){
        time <- 1:length(x)
	xc <-cos(2*pi*t/365)
	xs <-sin(2*pi*t/365)
	fit <- lm(x~xc+xs)
        return(fit$coefficients[1])
        }

s3 <- calc(s,  fun = fun3)


But check for NA's within your time series as these might trigger
errors/warnings. Maybe also check na.action options like na.approx(). Can
you provide a reproducible example in that case?

Best,
Jan Verbesselt
Wageningen University
The Netherlands
On 31/10/13 21:39, "Sofea Wright" <sofeawright at gmail.com> wrote: