[R] How I can calculate the value of response variable

Jim Lemon drjimlemon at gmail.com
Mon Jun 27 03:22:30 CEST 2016


Hi Rezvan,
Yes, and you can get fertilizer2 like this:

data1$fertilizer2<-data1fertilizer1*0.5

If I have the right idea, you want to substitute "fertilizer2" for
"fertilizer1" in your new model of nitrate (concentration?). I don't think
you want to include the coefficients (which are calculated by lm) into the
formula for lm.

Jim



On Mon, Jun 27, 2016 at 11:15 AM, rezvan hatami <rezvan.hatami_iut at yahoo.com
> wrote:

> For the sake of simplicity, I use my example to explain what I have
> written:
>
> nutrient<-lm(nitrate~0.9*fertilizer-0.02*flowrate+0.5*rain)
> datafram=data1
>
> Change the value of fertelizer--à datafram=data2
>
> predict(lm(nitrate~0.9*fertilizer2-0.02*flowrate+0.5*rain), datafram=data2
>
> Is that better now?
>
>
>
> ------------------------------
> *From:* Jim Lemon <drjimlemon at gmail.com>
> *To:* rezvan hatami <rezvan.hatami_iut at yahoo.com>; r-help mailing list <
> r-help at r-project.org>
> *Sent:* Monday, 27 June 2016, 10:28
>
> *Subject:* Re: [R] How I can calculate the value of response variable
>
> Hi Rezvan,
> This looks like a simple problem of solving linear equations (and very
> much like a homework exercise). Therefore I won't actually give you the
> answer, but suggest the steps for the solution. First you have to get the
> data into R, so here is one way:
>
> rhdat<-read.table(text="season,site,nitrate,fertilizer1,flowrate
> spring,site1,0.2,2,1
> spring,site2,1.2,3,1
> spring,site3,2.2,5,2
> summer,site1,3.2,1,2
> summer,site2,4.2,2,2
> summer,site3,5.2,3,2
> fall,site1,6.2,4,3
> fall,site2,7.2,5,3
> fall,site3,8.2,6,3
> winter,site1,9.2,4,4
> winter,site2,10.2,8,4
> winter,site3,11.2,9,4",sep=",",header=TRUE)
>
> You now have a data frame (rhdat) containing the values in your table.
>
> 1) calculate values for rain, which are missing from the table, e.g.
>
> rhdat$rain<-2*(rhdat$nitrate-0.9*rhdat$fertilizer+0.02*rhdat$flowrate)
>
> the above is an R expression to calculate the values for rain.
>
> 2) You may want explicitly calculate new values for rhdat$fertilizer, and
> you have indicated that you already know how to do that. The above should
> give you enough information about R syntax to translate the simple equation.
>
> 3) Now calculate new values for nitrate based on the equation you
> supplied, but substituting the calculated values for rain and the modified
> values for fertilizer.
>
> Jim
>
>
> On Mon, Jun 27, 2016 at 9:43 AM, rezvan hatami <
> rezvan.hatami_iut at yahoo.com> wrote:
>
> Hi Jim
> Thank you for your answer. nitrate=0.9*fertilizer-0.02*flowrate+0.5*rain
>
> my matrix:
> season site nitrate fertilizer1 flow rate
> spring site1 0.2 2 1
> spring site2 1.2 3 1
> spring site3 2.2 5 2
> summer site1 3.2 1 2
> summer site2 4.2 2 2
> summer site3 5.2 3 2
> fall site1 6.2 4 3
> fall site2 7.2 5 3
> fall site3 8.2 6 3
> winter site1 9.2 4 4
> winter site2 10.2 8 4
> winter site3 11.2 9 4
>
> I would like to know, what will be the values for variable "nitrate" if I
> divide the values of fertilizer by half and change the equation to:
>
> nitrate=0.9*fertilizer2-0.02*flowrate+0.5*rain
>
> in a matrix like:
>
> season site nitrate fertilizer2 flow rate
> spring site1 0.2 1 1
> spring site2 1.2 1.5 1
> spring site3 2.2 2.5 2
> summer site1 3.2 0.5 2
> summer site2 4.2 1 2
> summer site3 5.2 1.5 2
> fall site1 6.2 2 3
> fall site2 7.2 2.5 3
> fall site3 8.2 3 3
> winter site1 9.2 2 4
> winter site2 10.2 4 4
> winter site3 11.2 4.5 4
> Would you please tell me how I can do this in R?
>
> Cheers
>
> Rezvan
>
>
> ------------------------------
> *From:* Jim Lemon <drjimlemon at gmail.com>
> *To:* rezvan hatami <rezvan.hatami_iut at yahoo.com>; r-help mailing list <
> r-help at r-project.org>
> *Sent:* Monday, 27 June 2016, 8:07
> *Subject:* Re: [R] How I can calculate the value of response variable
>
> Hi Rezvan,
> I'll take a guess that you have been presented with a matrix of
> coefficients. You probably know that a linear model is going to look
> something like this:
>
> Y = ax1 + bx2 + cx3 ...
>
> So I will further guess that you want to infer a distribution of Y
> (the response variable) from more than one set of coefficients. If my
> guesses are correct, then you should be able to send an example that
> shows what you have and what you want to get.
>
> Jim
>
>
> On Sun, Jun 26, 2016 at 8:23 PM, rezvan hatami via R-help
> <r-help at r-project.org> wrote:
> >  How I can calculate the value of response variable in a linear model of
> a matrix of several variables?Can somebody please answer me?
> >
> >
> > Cheers
> > Rezvan Hatami
>
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> <http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list