I am trying to fit a helix to some 3 dimensional data using the nls function in R. I keep getting this error and I can’t figure out what is wrong with the syntax of my formula:
Error in str2lang(x) : :2:0: unexpected end of input 1: ~
Here is the code:
helix_model <- function(t, a, b) {
data.frame(
x = a * cos(t),
y = a * sin(t),
z = b * t
)
}
data <- data.frame(
x = c(1, 2, 3, 4, 5),
y = c(2, 3, 4, 5, 6),
z = c(0.1, 0.2, 0.3, 0.4, 0.5)
)
fit <- nls(
cbind(x, y, z) ~ helix_model(t, a, b),
data = data,
start = list(a = 1, b = 0.1) # Initial values for parameters a and b
)
I am sure it is something simple that I am missing. Any help would be appreciated! Thank you!