简体   繁体   中英

How do I graph my equation in R

I have the following equation that I would like to graphy for y values between 0 - 20. However I am not sure how to set the data up to use the function plot (x,y) .

I first defined my y values as:

y <- data.frame(x = c(1:20))

And then my x values as:

x<- (exp (-1.973 + 0.598*y) )/ (1+ exp (-1.973+ 0.598*y)) 

I get back this error when using plot(x,y)

Erreur dans stripchart.default(x1, ...) : méthode graphique incorrecte (error in stripchart: method graphic incorrect)

any tips?

You could simply create a data.frame object with y and x value, and afterwards plot it.

y <- c(1:20)
x <- exp (-1.973 + 0.598*y) / 1+ exp (-1.973+ 0.598*y)
df <- data.frame(y = y, x = x)
plot(df$y, df$x)

如果要在范围[0,20]上绘制方程exp(-1.973+0.598*x)/(1+exp(-1.973+0.598*x)) ,最简单的方法是使用函数curve ,这样不必定义ay或x向量,因为它直接采用表达式:

curve(exp(-1.973+0.598*x)/(1+exp(-1.973+0.598*x)),from=0,to=20)

由于xy都是数据帧,因此必须在绘制前用[[提取第一列。

plot(x[[1]], y[[1]])

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