Hello,
I am having difficulty with the ns function. I am
trying to use natural spline of a list of dates
in order to create a time series analysis where
date does not need to have a linear relationship
with the outcome.
Here is my code and the error message - I have
tried changing the class of variable but doesn't
seem to help.
> library(splines)
> date <- dataset$date
> mode(date)
[1] "numeric"> class(date)
[1] "factor"> try1 <- ns(date,6) ## with date as factor
Error in (1 - h) * qs[i] : non-numeric argument
to binary operator>
> date <- strptime(admissions$date,"%d%b%y")
> mode(date)
[1] "list"> class(date)
[1] "POSIXt" "POSIXlt"> foo <- ns(date,6) ## with date as POSIXt
Error in as.POSIXct.default(X[[2]], ...) :
do not know how to convert 'X[[2]]' to
class "POSIXlt"
> try <- as.character(date)
> mode(try)
[1] "character"> class(try)
[1] "character"> foo <- ns(try,6)
Error in qsort(x, FALSE) : argument is not a
numeric vector