Last data update: 2014.03.03
R: make predictions from a "HDtweedie" object.
predict.HDtweedie R Documentation
make predictions from a "HDtweedie" object.
Description
Similar to other predict methods, this functions predicts fitted values from a HDtweedie
object.
Usage
## S3 method for class 'HDtweedie'
predict(object, newx, s = NULL,
type=c("response","link"), ...)
Arguments
object
fitted HDtweedie
model object.
newx
matrix of new values for x
at which predictions are
to be made. Must be a matrix.
s
value(s) of the penalty parameter lambda
at which
predictions are required. Default is the entire sequence used to
create the model.
type
type of prediction required:
...
Not used. Other arguments to predict.
Details
s
is the new vector at which predictions are requested. If s
is not in the lambda sequence used for fitting the model, the predict
function will use linear interpolation to make predictions. The new values are interpolated using a fraction of predicted values from both left and right lambda
indices.
Value
The object returned depends on type.
Author(s)
Wei Qian, Yi Yang and Hui Zou
Maintainer: Wei Qian <weiqian@stat.umn.edu>
References
Qian, W., Yang, Y., Yang, Y. and Zou, H. (2013), “Tweedie's Compound
Poisson Model With Grouped Elastic Net,” submitted to Journal of Computational and Graphical Statistics .
See Also
coef
method
Examples
# load HDtweedie library
library(HDtweedie)
# load auto data set
data(auto)
# fit the lasso
m0 <- HDtweedie(x=auto$x,y=auto$y,p=1.5)
# predicted mean response at x[10,]
print(predict(m0,type="response",newx=auto$x[10,]))
# define group index
group1 <- c(rep(1,5),rep(2,7),rep(3,4),rep(4:14,each=3),15:21)
# fit the grouped lasso
m1 <- HDtweedie(x=auto$x,y=auto$y,group=group1,p=1.5)
# predicted the log mean response at x[1:5,]
print(predict(m1,type="link",newx=auto$x[1:5,]))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(HDtweedie)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/HDtweedie/predict.HDtweedie.Rd_%03d_medium.png", width=480, height=480)
> ### Name: predict.HDtweedie
> ### Title: make predictions from a "HDtweedie" object.
> ### Aliases: predict.HDtweedie
> ### Keywords: models regression
>
> ### ** Examples
>
> # load HDtweedie library
> library(HDtweedie)
>
> # load auto data set
> data(auto)
>
> # fit the lasso
> m0 <- HDtweedie(x=auto$x,y=auto$y,p=1.5)
>
> # predicted mean response at x[10,]
> print(predict(m0,type="response",newx=auto$x[10,]))
s0 s1 s2 s3 s4 s5 s6 s7
[1,] 4.112271 4.109742 4.107569 4.105684 4.104024 4.102541 4.101195 4.099956
s8 s9 s10 s11 s12 s13 s14 s15
[1,] 4.098801 4.097714 4.096684 4.095703 4.094766 4.093868 4.093008 4.092184
s16 s17 s18 s19 s20 s21 s22 s23
[1,] 4.091395 4.090641 4.08992 4.089232 4.088576 4.087953 4.08736 4.086797
s24 s25 s26 s27 s28 s29 s30 s31
[1,] 4.086264 4.08576 4.085282 4.084831 4.084406 4.084004 4.083626 4.08327
s32 s33 s34 s35 s36 s37 s38 s39
[1,] 4.082935 4.08262 4.082324 4.082046 4.081785 4.08154 4.081311 4.081096
s40 s41 s42 s43 s44 s45 s46 s47
[1,] 4.080894 4.084743 4.184984 4.284308 4.383077 4.478465 4.487355 4.495597
s48 s49 s50 s51 s52 s53 s54 s55
[1,] 4.503243 4.55191 4.643629 4.731178 4.817623 4.900928 4.98082 5.057297
s56 s57 s58 s59 s60 s61 s62 s63
[1,] 5.129569 5.197768 5.26188 5.321654 5.377776 5.430739 5.480149 5.52616
s64 s65 s66 s67 s68 s69 s70 s71
[1,] 5.538845 5.424084 5.319149 5.228447 5.180448 5.141667 5.106092 5.073468
s72 s73 s74 s75 s76 s77 s78 s79
[1,] 5.043369 5.015632 4.990055 4.966402 4.944524 4.924269 4.907512 4.893801
s80 s81 s82 s83 s84 s85 s86 s87
[1,] 4.891542 4.903057 4.913941 4.92435 4.93407 4.943223 4.944831 4.945509
s88 s89 s90 s91 s92 s93 s94 s95
[1,] 4.946151 4.972764 5.003124 5.031742 5.058521 5.084863 5.11567 5.169313
s96 s97 s98 s99
[1,] 5.226484 5.280443 5.331708 5.371295
>
> # define group index
> group1 <- c(rep(1,5),rep(2,7),rep(3,4),rep(4:14,each=3),15:21)
>
> # fit the grouped lasso
> m1 <- HDtweedie(x=auto$x,y=auto$y,group=group1,p=1.5)
>
> # predicted the log mean response at x[1:5,]
> print(predict(m1,type="link",newx=auto$x[1:5,]))
s0 s1 s2 s3 s4 s5 s6 s7
[1,] 1.413975 1.403985 1.394504 1.385567 1.377179 1.369334 1.362017 1.355207
[2,] 1.413975 1.405117 1.396722 1.388820 1.381413 1.374493 1.368047 1.362056
[3,] 1.413975 1.407962 1.402285 1.396960 1.391982 1.387342 1.383028 1.379026
[4,] 1.413975 1.403985 1.394504 1.385567 1.377179 1.369334 1.362017 1.355207
[5,] 1.413975 1.403985 1.394504 1.385567 1.377179 1.369334 1.362017 1.355207
s8 s9 s10 s11 s12 s13 s14 s15
[1,] 1.348880 1.343007 1.337561 1.332511 1.327827 1.323483 1.319450 1.315703
[2,] 1.356498 1.351348 1.346579 1.342167 1.338086 1.334310 1.330816 1.327583
[3,] 1.375318 1.371887 1.368717 1.365788 1.363084 1.360589 1.358287 1.356163
[4,] 1.348880 1.343007 1.337561 1.332511 1.327827 1.323483 1.319450 1.315703
[5,] 1.348880 1.343007 1.337561 1.332511 1.327827 1.323483 1.319450 1.315703
s16 s17 s18 s19 s20 s21 s22 s23
[1,] 1.312218 1.308972 1.305946 1.303118 1.300472 1.297990 1.295658 1.293460
[2,] 1.324588 1.321813 1.319240 1.316853 1.314635 1.312574 1.310656 1.308869
[3,] 1.354205 1.352401 1.350737 1.349205 1.347794 1.346496 1.345303 1.344207
[4,] 1.312218 1.308972 1.305946 1.303118 1.300472 1.297990 1.295658 1.293460
[5,] 1.312218 1.308972 1.305946 1.303118 1.300472 1.297990 1.295658 1.293460
s24 s25 s26 s27 s28 s29 s30 s31
[1,] 1.291385 1.289419 1.287551 1.285770 1.284066 1.282429 1.280852 1.279324
[2,] 1.307203 1.305647 1.304193 1.302833 1.301557 1.300361 1.299237 1.298179
[3,] 1.343202 1.342282 1.341443 1.340678 1.339985 1.339359 1.338798 1.338299
[4,] 1.291385 1.289419 1.287551 1.285770 1.284066 1.282429 1.280852 1.279324
[5,] 1.291385 1.289419 1.287551 1.285770 1.284066 1.282429 1.280852 1.279324
s32 s33 s34 s35 s36 s37 s38 s39
[1,] 1.277753 1.276236 1.274662 1.273037 1.271451 1.269678 1.267732 1.265610
[2,] 1.297150 1.296187 1.295247 1.294334 1.293480 1.292610 1.291736 1.290866
[3,] 1.337871 1.337500 1.337202 1.336977 1.336809 1.336746 1.336793 1.336963
[4,] 1.277753 1.276236 1.274662 1.273037 1.271451 1.269678 1.267732 1.265610
[5,] 1.277753 1.276236 1.274662 1.273037 1.271451 1.269678 1.267732 1.265610
s40 s41 s42 s43 s44 s45 s46 s47
[1,] 1.263188 1.260343 1.256832 1.252079 1.245398 1.235852 1.222846 1.207309
[2,] 1.289972 1.289038 1.288028 1.286852 1.285440 1.283714 1.281673 1.279519
[3,] 1.337301 1.337866 1.338769 1.340267 1.342719 1.346636 1.352414 1.359705
[4,] 1.263188 1.260343 1.256832 1.252079 1.245398 1.235852 1.222846 1.207309
[5,] 1.263188 1.260343 1.256832 1.252079 1.245398 1.235852 1.222846 1.207309
s48 s49 s50 s51 s52 s53 s54 s55
[1,] 1.190662 1.174083 1.158038 1.142756 1.128345 1.114689 1.102005 1.090162
[2,] 1.277451 1.275590 1.273954 1.272533 1.271306 1.270235 1.269312 1.268507
[3,] 1.367838 1.376197 1.384498 1.392576 1.400333 1.407793 1.414806 1.421418
[4,] 1.190662 1.174083 1.158038 1.142756 1.128345 1.114689 1.102005 1.090162
[5,] 1.190662 1.174083 1.158038 1.142756 1.128345 1.114689 1.102005 1.090162
s56 s57 s58 s59 s60 s61 s62
[1,] 1.079044 1.049960 1.017759 0.981004 0.9530841 0.9273939 0.9032199
[2,] 1.267794 1.241917 1.217004 1.194029 1.1730554 1.1534856 1.1352123
[3,] 1.427672 1.496436 1.565354 1.634327 1.6970752 1.7561260 1.8118757
[4,] 1.079044 1.049960 1.017759 0.981004 0.9530841 0.9273939 0.9032199
[5,] 1.079044 1.049960 1.017759 0.981004 0.9530841 0.9273939 0.9032199
s63 s64 s65 s66 s67 s68 s69
[1,] 0.8806802 0.8596872 0.8398686 0.8216475 0.8043587 0.7885325 0.7735143
[2,] 1.1181582 1.1022448 1.0873882 1.0735357 1.0606018 1.0485464 1.0372911
[3,] 1.8643519 1.9136843 1.9601422 2.0036268 2.0445519 2.0827704 2.1186933
[4,] 0.8806802 0.8596872 0.8398686 0.8216475 0.8043587 0.7885325 0.7735143
[5,] 0.8806802 0.8596872 0.8398686 0.8216475 0.8043587 0.7885325 0.7735143
s70 s71 s72 s73 s74 s75 s76
[1,] 0.7596464 0.746677 0.7399991 0.7355814 0.7314297 0.7275287 0.7238579
[2,] 1.0267968 1.017006 1.0146717 1.0139406 1.0132297 1.0125414 1.0118725
[3,] 2.1522598 2.183688 2.2173944 2.2495469 2.2796369 2.3077860 2.3341062
[4,] 0.7596464 0.746677 0.7399991 0.7355814 0.7314297 0.7275287 0.7238579
[5,] 0.7596464 0.746677 0.7399991 0.7355814 0.7314297 0.7275287 0.7238579
s77 s78 s79 s80 s81 s82 s83
[1,] 0.7204084 0.7173099 0.714396 0.7115897 0.7088243 0.7056808 0.7027383
[2,] 1.0112292 1.0106192 1.010037 1.0094786 1.0086098 1.0062524 1.0036172
[3,] 2.3587117 2.3816211 2.403049 2.4230985 2.4416464 2.4581974 2.4734454
[4,] 0.7204084 0.7173099 0.714396 0.7115897 0.7087580 0.7052122 0.7017377
[5,] 0.7204084 0.7173099 0.714396 0.7115897 0.7090068 0.7069511 0.7054093
s84 s85 s86 s87 s88 s89 s90
[1,] 0.6999681 0.6974674 0.6947501 0.6919536 0.6891953 0.6861787 0.6826976
[2,] 1.0005567 0.9969122 0.9939292 0.9919603 0.9902669 0.9889891 0.9884325
[3,] 2.4874287 2.5001265 2.5113713 2.5214196 2.5304096 2.5383047 2.5454772
[4,] 0.6982391 0.6947381 0.6923724 0.6914612 0.6911680 0.6915089 0.6929156
[5,] 0.7045097 0.7045168 0.7055270 0.7076596 0.7104336 0.7135115 0.7170804
s91 s92 s93 s94 s95 s96 s97
[1,] 0.6783405 0.6728991 0.6702569 0.6682901 0.6664776 0.6646241 0.6652250
[2,] 0.9883428 0.9816618 0.9724208 0.9640674 0.9563842 0.9492673 0.9431869
[3,] 2.5523312 2.5599915 2.5652932 2.5687693 2.5716627 2.5746186 2.5767185
[4,] 0.6957119 0.7060336 0.7201463 0.7338742 0.7471429 0.7598641 0.7727968
[5,] 0.7212281 0.7281895 0.7348367 0.7422693 0.7498095 0.7570866 0.7633717
s98 s99
[1,] 0.6679195 0.6705656
[2,] 0.9382190 0.9336368
[3,] 2.5779521 2.5792725
[4,] 0.7859912 0.7984137
[5,] 0.7687485 0.7739278
>
>
>
>
>
> dev.off()
null device
1
>