@@ -4,19 +4,20 @@ predict.fregre.gkam<-function (object, newx = NULL, type = "response", ...)
4
4
{
5
5
namesx <- names(object $ result )
6
6
nvars = length(namesx )
7
+ if (is.null(newx )) stop(" Provide a newx object." )
7
8
nr = nrow(newx [[namesx [1 ]]])
8
9
pr = matrix (NA , nrow = nr , ncol = nvars + 3 )
9
10
colnames(pr ) = c(colnames(object $ effects ), " eta" , " mu" )
10
11
pr [, " Intercept" ] = rep(object $ effects [1 , " Intercept" ], nr )
11
12
for (i in 1 : nvars ) {
12
13
pr [, namesx [i ]] = predict(object $ result [[namesx [i ]]],newx [[namesx [i ]]])
13
14
}
14
- if (nr == 1 )
15
- pr [, " eta" ] <- sum(pr [, 1 : (nvars + 1 )])
16
- else pr [, " eta" ] = rowSums(pr [, 1 : (nvars + 1 )])
15
+ if (nr == 1 ) {
16
+ pr [, " eta" ] <- sum(pr [, 1 : (nvars + 1 )])
17
+ } else { pr [, " eta" ] = rowSums(pr [, 1 : (nvars + 1 )])}
17
18
# pr[, "eta"] = apply(pr[, 1:(nvars + 1)], 1, sum)
18
- pr <- switch ( type , response = object $ family $ linkinv(pr [,
19
- " eta " ]) , link = pr [, " eta" ])
19
+ pr [, " mu " ] <- object $ family $ linkinv(pr [," eta " ])
20
+ pr <- switch ( type , response = pr [, " mu " ] , link = pr [, " eta" ], terms = pr [, 1 : ( nvars + 1 ) ])
20
21
return (pr )
21
22
}
22
23
0 commit comments