Steven Matthew Anderson
2009-Jun-26 03:30 UTC
[R] predicted values after fitting gamma2 function
Question: after fitting a gamma function to some data, how do I get
predicted values? I'm a SAS programmer, I new R, and am having
problems getting my brain to function with the concept of "object as
class ...". The following is specifics of what I am doing:
I'm trying to determine the pdf from data I have created in a
simulation.
I have generated frequency counts using the following:
Max.brks <- pretty(range(Max.Spread$Distance), 100)
Max.f<-hist(x=Max.Spread$Distance,
breaks=Max.brks,plot=FALSE )
Max.cnt<-as.data.frame(cbind(sim,Max.f$mids,Max.f$counts))
colnames(Max.cnt)<-c("Simulation","MidPoint","Count")
then I fit this to a gamma distribution function:
modl<-
vglm
(Count
~
MidPoint
,gamma2
,data
=subset(Max.cnt,select=(simulation,MidPoint,Count),trace=TRUE,crit="c")
print(coef(modl2,matrix=TRUE))
print(summary(modl2))
This produces the output:
VGLM linear loop 1 : coefficients 3.231473495, 0.597085743, -0.195591168
...
VGLM linear loop 20 : coefficients 3.663316903, 0.897355891,
-0.620449146
log(mu) log(shape)
(Intercept) 3.6633169 0.8973559
MidPoint -0.6204491 0.0000000
Call:
vglm(formula = Count ~ MidPoint, family = gamma2, data = modl.subset,
trace = TRUE, crit = "c")
Pearson Residuals:
Min 1Q Median 3Q Max
log(mu) -1.4846 -0.715285 -0.15436 0.61641 2.17298
log(shape) -5.8348 -0.099617 0.42094 0.61865 0.70901
Coefficients:
Value Std. Error t value
(Intercept):1 3.66332 0.131643 27.8277
(Intercept):2 0.89736 0.138591 6.4749
MidPoint -0.62045 0.047505 -13.0607
Number of linear predictors: 2
Names of linear predictors: log(mu), log(shape)
Dispersion Parameter for gamma2 family: 1
Log-likelihood: -276.0009 on 181 degrees of freedom
Number of Iterations: 20
Now - how do I get this information to give me predicted values given
the same x-values I used in the experimental model (i.e. from Max.brks
<- pretty(range(Max.Spread$Distance), 100)).
Steven Matthew Anderson
Anderson Research, LLC
Statistical Programming and Analysis
SAS (R) Certified Professional
AdAstra69 at mac.com
Ad Astra per Aspera
???????
On Jun 25, 2009, at 11:30 PM, Steven Matthew Anderson wrote:> Question: after fitting a gamma function to some data, how do I get > predicted values? I'm a SAS programmer, I new R, and am having > problems getting my brain to function with the concept of "object as > class ...". The following is specifics of what I am doing: > > I'm trying to determine the pdf from data I have created in a > simulation. > I have generated frequency counts using the following: > > Max.brks <- pretty(range(Max.Spread$Distance), 100) > Max.f<-hist(x=Max.Spread$Distance, > breaks=Max.brks,plot=FALSE ) > Max.cnt<-as.data.frame(cbind(sim,Max.f$mids,Max.f$counts)) > colnames(Max.cnt)<-c("Simulation","MidPoint","Count") > > then I fit this to a gamma distribution function:Using a non-base function without including the appropriate require() or library() call is a bit like asking a SAS programmer to debug code but not telling what PROC it's from;> modl<- > vglm > (Count > ~ > MidPoint > ,gamma2 > ,data > = > subset(Max.cnt,select=(simulation,MidPoint,Count),trace=TRUE,crit="c") > print(coef(modl2,matrix=TRUE)) > print(summary(modl2)) > > This produces the output: >snipped output> > > Now - how do I get this information to give me predicted values > given the same x-values I used in the experimental model (i.e. from > Max.brks <- pretty(range(Max.Spread$Distance), 100)).Most regression functions in R, and vglm is no exception, have predict methods. The default is to give back predictions for the data from which the parameters were estimated, but if you want predictions on specific new values there is a newdata option. ?predict.vglm David Winsemius, MD Heritage Laboratories West Hartford, CT
Apparently Analagous Threads
- p-values from VGAM function vglm
- Generation from COX PH with gamma frailty
- bug: sample( x, size, replace = TRUE, prob= skewed.probs) produces uniform sample
- use same breaks and colors, but the displayed scale are different-image.plot()
- SpatialPolygon with the max value gets no color assigned in spplot function when using "at" parameter