2017-10-04 10 views

答えて

1

はここで車

m <- lm(dist ~ speed, data = cars) 

plot(dist ~ speed,data = cars) 

abline(m, col = "red") 

を設定し、我々はR二乗およびP-値を抽出するために)(要約を使用します。

m1 <- summary(m) 

mtext(paste0("R squared: ",round(m1$r.squared,2)),adj = 0) 

mtext(paste0("P-value: ", format.pval(pf(m1$fstatistic[1], # F-statistic 
            m1$fstatistic[2], # df 
            m1$fstatistic[3], # df 
            lower.tail = FALSE)))) 

mtext(paste0("dist ~ ",round(m1$coefficients[1],2)," + ", 
        round(m1$coefficients[2],2),"x"), 
     adj = 1) 
+0

ありがとう、どのようにP値の桁数を調整し、回帰式を追加しますか? – soroush

+0

私のアンカーを編集しました。 –

+0

ggplot2ユーザーの場合:https://stackoverflow.com/questions/7549694/adding-regression-line-equation-and-r2-on-graph – lawyeR

関連する問題