[R] Obtaining predicted values for glm() function
David L Carlson
dcarlson at tamu.edu
Fri Aug 15 17:07:28 CEST 2014
You don't show us your function call, so it is hard to be certain what the problem is. Have you read the manual page?
?predict.glm
Have you used the newdata= argument? If not, you should know that R's ability to read your mind will not be available until the 4.0 release.
David Carlson
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of DHIMAN BHADRA
Sent: Friday, August 15, 2014 4:28 AM
To: Jeff Newmiller
Cc: r-help at r-project.org
Subject: Re: [R] Obtaining predicted values for glm() function
Thanks Jeff for the suggestion - will explore the predict function. So far
I was working on the fitted() function but it seems to generate fitted
(response) values only for predictor values in the original data set, not
for values beyond that.
I never intended to spam the mailing list. I re-posted only when I did not
find my original post in my inbox, which led to think that my query has not
reached the R-family.
Thanks again for your suggestion,
Dhiman
On Fri, Aug 15, 2014 at 11:52 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
wrote:
> Please don't repeat post. In fact, you should definitely read the Posting
> Guide mentioned at the bottom if this or any other post from the list and
> follow its advice.
>
> The usual way to predict output of a model in R is to use the predict
> function appropriate to your model object class. You might find reading the
> help file ?predict.glm helpful. If not, then you might be needing to study
> some more basic use cases of R so you can interpret the help files.
> ---------------------------------------------------------------------------
> Jeff Newmiller The ..... ..... Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
> Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> On August 14, 2014 10:54:17 PM PDT, DHIMAN BHADRA <dhimanbhadra at gmail.com>
> wrote:
> >Dear all.
> >
> >I am trying to relate daily deaths in a given city with air pollution
> >values. The model I am using is as follows:
> >
> >model <- glm(deaths ~ pollution + ns(time, 13) + ns(temp, 7) + ns(rh,
> >5) +
> >dow + holiday, family=quasipoisson, data=city)
> >
> >Where -
> >deaths: daily number of deaths
> >pollution: daily measured levels of air pollution
> >ns(time, 13): smooth function (i.e. cubic spline) of time with 13
> >degrees
> >of freedom
> >ns(temp, 7): smooth function (i.e. cubic spline) of temperature with 7
> >degrees of freedom
> >ns(rh, 5): smooth function (i.e. cubic spline) of humidity with 5
> >degrees
> >of freedom
> >dow: day of the week
> >holiday: dummy variable to indicate public holidays
> >
> >Having run this model, how do I obtain predicted values of deaths for
> >any
> >given set of pollution values? Any suggestions will be much
> >appreciated.
> >
> >Thanks in advance,
> >Dhiman Bhadra
> >Assistant professor.
> >IIM Ahmedabad.
> >
> > [[alternative HTML version deleted]]
> >
> >______________________________________________
> >R-help at r-project.org mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
>
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list