这是一个简单的数据集。我想估算此最佳拟合逻辑增长曲线的R2值。有关如何执行此操作的任何想法?
ggplot2中的###### Logistic增长模型
library(tidyverse)
theme_set(theme_bw())
colors <- list(
data = "#41414550",
# data = "grey80",
fit = "#414145")
#build the dataset
points <- tibble(
age = c(38, 45, 52, 61, 80, 74),
prop = c(0.146, 0.241, 0.571, 0.745, 0.843, 0.738))
ggplot(points, aes(x = age, y = prop)) +
geom_point(size = 3.5, color = colors$data) +
scale_x_continuous(name = "Age in months", limits = c(0, 96),
# Because age is in months, I want breaks to land on multiples
# of 12. The `Q` in `extended_breaks()` are "nice" numbers to use
# for axis breaks.
breaks = scales::extended_breaks(Q = c(24, 12))) +
scale_y_continuous( name = "Intelligibility", limits = c(0, NA),labels = scales::percent_format(accuracy = 1))
生成最佳拟合方程:
xs <- seq(0, 96, length.out = 80) #80 observations ranging from 0-96
# Create the curve from the equation parameters
trend <- tibble( age = xs, asymptote = .8, scale = .2, midpoint = 48,
prop = asymptote / (1 + exp((midpoint - age) * scale)))
trend
绘制
colors$asym <- "#E7552C"
colors$mid <- "#3B7B9E"
colors$scale <- "#1FA35C"
logi.p <- ggplot(points, aes(x = age, y = prop)) +
annotate("segment",color = colors$mid,x = 48, xend = 48,y = 0, yend = .4,linetype = "dashed") +
annotate("segment",color = colors$asym, x = 20, xend = Inf, y = .8, yend = .8, linetype = "dashed") +
geom_line(data = trend, size = 1, color = colors$fit) +
geom_point(size = 3.5, color = colors$data) +
annotate("text",label = "growth plateaus at asymptote",x = 20, y = .84,
# horizontal justification = 0 sets x position to left edge of text
hjust = 0,
color = colors$asym) +
annotate("text",
label = "growth steepest at midpoint", x = 49, y = .05, hjust = 0, color = colors$mid) +
scale_x_continuous( name = "Age in months", limits = c(0, 96), breaks = scales::extended_breaks(Q = c(24, 12))) +
scale_y_continuous( name = "Intelligibility", limits = c(0, NA),labels = scales::percent_format(accuracy = 1))
logi.p