predict.funHDDC: Predict new results from a funHDDC model

Description Usage Arguments Value Examples

View source: R/predict.funHDDC.R

Description

It provides predictions for a new functional dataset using the funHDDC model you train.

Usage

1
2
  ## S3 method for class 'funHDDC'
predict(object,newdata,...)

Arguments

object

An object produced by funHDDC function

newdata

In the univariate case: a functional data object produced by the fda package, in the multivariate case: a list of functional data objects, for which you want to predict the group membership from the model.

...

Some additional parameters.

Value

class

The clustering partition.

t

The probability of each individual to belong to each cluster.

L

The loglikelihood.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
##Univariate example
    data("trigo")
    basis<- create.bspline.basis(c(0,1), nbasis=25)
    suppressWarnings(RNGversion("3.5.0"))
    set.seed(1)
    z<-sample(1:100,0.8*100,replace=FALSE)
    var1_train<-smooth.basis(argvals=seq(0,1,length.out = 100),y=t(trigo[z,1:100]),
                             fdParobj=basis)$fd
    var1_test<-smooth.basis(argvals=seq(0,1,length.out = 100),y=t(trigo[-z,1:100]),
                            fdParobj=basis)$fd

    model<-funHDDC(var1_train,K=2)
    pred<-predict(model,var1_test)

##Multivariate example
    data("triangle")
    basis<- create.bspline.basis(c(1,21), nbasis=25)
    suppressWarnings(RNGversion("3.5.0"))
    set.seed(1)
    z<-sample(1:100,0.8*100,replace=FALSE)
    var1_train<-smooth.basis(argvals=seq(1,21,length.out = 101),y=t(triangle[z,1:101]),
                              fdParobj=basis)$fd
    var1_test<-smooth.basis(argvals=seq(1,21,length.out = 101),y=t(triangle[-z,1:101]),
                            fdParobj=basis)$fd
    var2_train<-smooth.basis(argvals=seq(1,21,length.out = 101),y=t(triangle[z,102:202]),
                            fdParobj=basis)$fd
    var2_test<-smooth.basis(argvals=seq(1,21,length.out = 101),y=t(triangle[-z,102:202]),
                            fdParobj=basis)$fd

    model<-funHDDC(list(var1_train,var2_train),K=3)
    pred<-predict(model,list(var1_test,var2_test))

##NOT RUN: another example on Canadian data
    ##Clustering the "Canadian temperature" data (Ramsey & Silverman): univariate case
    daybasis65 <- create.fourier.basis(c(0, 365), nbasis=65, period=365)
    #z<-sample(1:35,0.9*35,replace=FALSE)
    #daytempfd_train <- smooth.basis(day.5, CanadianWeather$dailyAv[,z,"Temperature.C"],
    #daybasis65,fdnames=list("Day", "Station", "Deg C"))$fd
    #daytempfd_test <- smooth.basis(day.5, CanadianWeather$dailyAv[,-z,"Temperature.C"],
    #daybasis65,fdnames=list("Day", "Station", "Deg C"))$fd

     #model<-funHDDC(daytempfd_train,K=3)
     #pred<-predict.funHDDC(model,daytempfd_test)


    ##Clustering the "Canadian temperature" data (Ramsey & Silverman): multivariate case
    #daybasis65 <- create.fourier.basis(c(0, 365), nbasis=65, period=365)
    #z<-sample(1:35,0.9*35,replace=FALSE)
    #daytempfd_train <- smooth.basis(day.5, CanadianWeather$dailyAv[,z,"Temperature.C"],
    #daybasis65,fdnames=list("Day", "Station", "Deg C"))$fd
    #daytempfd_test <- smooth.basis(day.5, CanadianWeather$dailyAv[,-z,"Temperature.C"],
    #daybasis65,fdnames=list("Day", "Station", "Deg C"))$fd
    #dayprecfd_train<-smooth.basis(day.5, CanadianWeather$dailyAv[,z,"Precipitation.mm"],
    #daybasis65,fdnames=list("Day", "Station", "Mm"))$fd
    #dayprecfd_test<-smooth.basis(day.5, CanadianWeather$dailyAv[,-z,"Precipitation.mm"],
    #daybasis65,fdnames=list("Day", "Station", "Mm"))$fd

    #model<-funHDDC(list(daytempfd_train,dayprecfd_train),K=3)
    #pred<-predict.funHDDC(model,list(daytempfd_test,dayprecfd_test))

    

funHDDC documentation built on March 17, 2021, 5:06 p.m.