Ich komme irgendwie nicht weiter. Der Y-intercepter müsste in diesem Beispiel irgendwo bei y ≈ 40 liegen. Laut linearer Regressions-Funktion liegt er aber bei ≈ 23. Die Steigung passt mit 3.32
Irgendwie muss es damit zusammenhängen das ein logarithmus von kleiner 1 eine negative Zahl ausgibt, aber irgendwie ist bei mir ein Knoten im Hirn.
Code: Alles auswählen
#---genutzte Libraries----
library(ggplot2)
library(hrbrthemes)
library(reshape)
#---Dateneingabe für jede 10er Faktor in x wird y um 3.32 größer----
x<-c(0.1, 0.1, 0.1, 0.01, 0.01, 0.01, 0.001, 0.001, 0.001, 0.0001, 0.0001, 0.0001)
y<-c(26.32, 26.32, 26.32, 29.64, 29.64, 29.64, 32.96, 32.96, 32.96, 36.28, 36.28, 36.28)
#x<-c(10000, 10000, 10000, 1000, 1000, 1000, 100, 100, 100, 10, 10, 10)
#y<-c(26.32, 26.32, 26.32, 29.64, 29.64, 29.64, 32.96, 32.96, 32.96, 36.28, 36.28, 36.28)
sample1 <- data.frame(x, y)
#---Berechnung Regressionsmodelle (linear, quadratisch "2" und kubisch "3") für Formel-Erstellung----
fit.1 <- lm(y ~ (log10(x)), data=sample1)
fit.2 <- lm(y ~ poly(log10(x), 2, raw=TRUE), data=sample1)
fit.3 <- lm(y ~ poly(log10(x), 3, raw=TRUE), data=sample1)
#---Formelerstellung lineare Regression für ggplot----
eqn.1 <- as.character(as.expression(substitute(italic(y)==a+b*italic(x)*"," ~~ italic(r)^2~ "=" ~ r2,
list(a = format(summary(fit.1)$coefficients[1,1], digits = 4),
b = format(summary(fit.1)$coefficients[2,1], digits = 4),
r2 = format(summary(fit.1)$r.squared, digits = 4)
))))
eqn.2 <- as.character(as.expression(substitute(italic(y)==a+b*italic(x)+c*italic(x)^2*"," ~~ italic(r)^2~ "=" ~ r2,
list(a = format(summary(fit.2)$coefficients[1,1], digits = 4),
b = format(summary(fit.2)$coefficients[2,1], digits = 4),
c = format(summary(fit.2)$coefficients[3,1], digits = 4),
r2 = format(summary(fit.2)$r.squared, digits = 4)
))))
eqn.3 <- as.character(as.expression(substitute(italic(y)==a+b*italic(x)+c*italic(x)^2+d*italic(x)^3*"," ~~ italic(r)^2~ "=" ~ r2,
list(a = format(summary(fit.3)$coefficients[1,1], digits = 4),
b = format(summary(fit.3)$coefficients[2,1], digits = 4),
c = format(summary(fit.3)$coefficients[3,1], digits = 4),
d = format(summary(fit.3)$coefficients[4,1], digits = 4),
r2 = format(summary(fit.3)$r.squared, digits = 4)
))))
Texte <- data.frame(lnr = 1:3, Reihe=c("linearPred","quadraticPred","cubicPred"), Equation = c(eqn.1, eqn.2, eqn.3))
#---Plot-Erstellung----
plot<- ggplot(sample1, aes(x = x, y = y)) +
annotation_logticks(sides = "b") + scale_x_log10() +
labs(title = 'Regressions Plot PCR Results',
subtitle = 'Polynomial regression Plot to test Linearity',
x = 'Concentration IU/ml',
y = 'Cq-value',
caption = 'Andreas / andreas@random.com')+
geom_point(aes(x=x, y=y)) +
geom_smooth(method="lm", color = 3, fullrange = TRUE) +
geom_smooth(method="lm", formula=y ~ I(x^2) + x, color = 4, fullrange = TRUE) +
geom_smooth(method="lm", formula=y ~ I(x^3) + I(x^2) + x, color = 2, fullrange = TRUE) +
geom_text(data=Texte, aes(x=0.0001, y=28 - 0.75*lnr, label=(Equation), colour=Reihe), parse=TRUE, hjust="left",
show.legend=FALSE) +
theme_bw()
plot
Es wäre wirklich toll wenn Ihr mir helfen könntet.