简体   繁体   中英

How to solve an equation in R with mean and SD?

I have to resolve both equations that you can see in the graph (see below)

y1 = 38 + 0.067 x

and

y2 = 38 + 0.047 x

for ax value of x = 70

My goal is to get y values (which is easy to get manually) AND a standard deviation. Is there any way to get it with R ?

Thank you!

在此处输入图片说明

Basically, you are looking at regression model ie using lm in R. However to use it, you need to have a y variable. So based on the given x and y , the model will learn beta ie coefficients which gives the best result, in this case Rˆ2 .

So, in case you don't have a y and want to use the above equation, you can write a simple function, something like:

compute_y = function(intercept = 38, x=70, coefficient){
  y <- intercept + (coefficient * x)
  sdev <-  sd(y)
  return(list(y = y, sdev=  sdev))
}

y1 <- compute_y(coefficient=0.067)
y2 <- compute_y(coefficient=0.047)

This should give the y values. However, to calculate standard deviation, you need a vector of x or y values, you can't calculate sd for a scalar value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM