裏 RjpWiki

Julia ときどき R, Python によるコンピュータプログラム,コンピュータ・サイエンス,統計学

結果が合わない(その3)

2013年07月17日 | ブログラミング

世代別投票率と新規国債発行額

図3では,曲線を当てはめているが,その曲線は漸近指数曲線かな?
いずれの世代の投票率も新規国債発行額とは負の相関。
投票率はまあ,曲線にあてはまっているといっても良いが,国債発行額は,単純な曲線にあてはまっているとはいいがたい。

上の図を描くための R プログラム。
このブログの特性への対策のため,以下のプログラムでは,付値は = に変えた。

par(mar=c(3, 3, 1, 4), mgp=c(1.8, 0.8, 0))
plot(若年世代投票率 ~ 年, data=d, pch=15, col="red", ylim=c(35, 85), ylab="投票率")
points(高齢世代投票率 ~ 年, data=d, pch=17, col="darkgreen")

年 = seq(1967, 2012, length=500)
(ans.red = nls(若年世代投票率 ~ a*b^(年-1967)+c, data=d, start=list(a=57, b=0.98, c=19)))
p = ans.red$m$getPars()
lines(predict(ans.red, newdata=list(年=年)) ~ 年, col="red")
text(1990, 58, sprintf("y = %.3f * %.3f^(年-1967) %s %.3f", p[1], p[2], ifelse(p[3] > 0, "+", "-"), abs(p[3])), pos=2, col="red")

(ans.green = nls(高齢世代投票率 ~ a*b^(年-1967)+c, data=d, start=list(a=-7, b=1.01, c=85)))
p = ans.green$m$getPars()
lines(predict(ans.green, newdata=list(年=年)) ~ 年, col="darkgreen")
text(1994, 77, sprintf("y = %.3f * %.3f^(年-1967) %s %.3f", p[1], p[2], ifelse(p[3] > 0, "+", "-"), abs(p[3])), pos=1, col="darkgreen")

par(new=TRUE)
plot(新規国債発行額 ~ 年, data=d, pch=16, col="blue", axes=FALSE, ylab="")
mtext("新規国債発行額", 4, line=1.8)
axis(4, at=0:5*10, lab=0:5*10)
(ans.blue = nls(新規国債発行額 ~ a*b^(年-1967)+c, data=d, start=list(a=100, b=1.1, c=0)))
p = ans.blue$m$getPars()
lines(predict(ans.blue, newdata=list(年=年)) ~ 年, col="blue")
text(1975, 2, sprintf("y = %.3f * %.3f^(年-1967) %s %.3f", p[1], p[2], ifelse(p[3] > 0, "+", "-"), abs(p[3])), pos=4, col="blue")

コメント    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« 結果が合わない(その2) | トップ | 結果が合わない(その4) »
最新の画像もっと見る

コメントを投稿

ブログラミング」カテゴリの最新記事