全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
2552 6
2010-08-06
#linear regression for storks
#number of chicks per pair as a fluncion of both rainfall and temperature in May
model
    {
         for(i in 1:N)
            {
                nbchicksperpair[i] ~dnorm(mu[i],tau)
                 mu[i]<-intercept+slope.temperature*temperature[i]+slope.rainfall*rainfall[i]
             }
            #priors for regression parameters
           intercept ~dnorm(0,0.001)
           slope.temperature ~ dnorm(0,0.001)
           slope.rainfall ~ dnorm(0,0.001)
           #piors for precision parameter
            tau ~ dgamma(0.001,0.001)
            #monitor the standard deviation
            sigma<-1/sqrt(tau)
}
#data
list(N=23,nbchicksperpair=
c(2.55,1.85,2.05,2.88,3.13,2.21,2.43,2.69,2.55,2.84,2.47,2.69,2
.52,2.31,2.07,2.35,2.98,1.98,2.53,2.21,2.62,1.78,2.30),temperature=
c(15.1,13.3,15.3,13.3,14.6,15.6,13.1,13.1,15.0,11.7,15.3,14.4,14.4,12.7,
11.7,11.9,15.9,13.4,14.0,13.9,12.9,15.1,13.0),rainfall=
c(67,52,88,61,32,36,72,43,92,32,86,28,57,55,66,26,28,96,48,90,86,78,87))
#initial values
list(intercept=0,slope.temperature=0,slope.rainfall=0,tau=0.01)


运行到load data的时候,出现expected variable name,检查了多次感觉没有出错啊。
麻烦各位大虾看看
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2011-3-1 16:10:11
# linear regression for storks
model
  {
  for (i in 1:N)
          {
            nbchicksperpair[i] ~ dnorm (mu[i],tau)
            mu[i] <- intercept + slope.temperature*temperature[i]+slope.rainfall*rainfall[i]
          }
    # priors for regression parameters
    intercept ~ dnorm (0,0.001)
    slope.temperature ~ dnorm (0,0.001)
    slope.rainfall~ dnorm (0,0.001)
   
    # priors for precision parameter
    tau~ dgamma (0.001,0.001)
   
    #monitor the standard deviation
    sigma <- 1/sqrt(tau)
  }

#data
list(N=23,nbchicksperpair=
c(2.55,1.85,2.05,2.88,3.13,2.21,2.43,2.69,2.55,2.84,2.47,2.69,2.52,2.31,2.07,2.35,2.98,1.98,2.53,2.21,2.62,1.78,2.30),temperature=
c(15.1,13.3,15.3,13.3,14.6,15.6,13.1,13.1,15.0,11.7,15.3,14.4,14.4,12.7,
11.7,11.9,15.9,13.4,14.0,13.9,12.9,15.1,13.0),rainfall=
c(67,52,88,61,32,36,72,43,92,32,86,28,57,55,66,26,28,96,48,90,86,78,87))
#initial values
list(intercept=0,slope.temperature=0,slope.rainfall=0,tau=0.01)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-3-1 16:29:08
我的运行结果是可以的。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-3-1 16:34:01
1. Check model: open the Model Specification Tool
Watch out for the confirmation at the foot of the screen
2. Load data: Now highlight the 'list' in the data window
then click 'load data'
watch out for the confirmation at the foot of the screen
3. Compile model: Next, click 'compile'
watch out for the confirmation at the foot of the screen
4. Load initial values: highlight the 'list' in the data window
click 'load inits'
watch out for the confirmation at the foot of the screen
5. Generate Burn-in values: Open the Model Update Tool
Give the number of burn-in iterations (1000)
click 'update' to do the sampling
6. Monitor parameters: open the Inference Samples Tool
Enter 'intercept' in the node box and click 'set'
Enter 'slope_temperature' in the node box and click 'set'
Enter 'slope_rainfall' in the node box and click 'set'
7. Generate posterior values: enter the number of samples you want to take (10000)
click 'update' to do the sampling
8. Summarize posteriors: Enter '*' in the node box and click 'stats'
mean, median and credible intervals
95% Credible intervals
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-9-1 02:31:07
#linear regression for storks
#number of chicks per pair as a function of both rainfall and temperature in May
model
    {
         for(i in 1:N)
            {
                nbchicksperpair[i] ~dnorm(mu[i],tau)
                 mu[i]<-intercept+slope.temperature*temperature[i]+slope.rainfall*rainfall[i]
             }
            #priors for regression parameters
           intercept ~dnorm(0,0.001)
           slope.temperature ~ dnorm(0,0.001)
           slope.rainfall ~ dnorm(0,0.001)
           #piors for precision parameter
            tau ~ dgamma(0.001,0.001)
            #monitor the standard deviation
            sigma<-1/sqrt(tau)
}
#data
list(N=23,nbchicksperpair=c(2.55,1.85,2.05,2.88,3.13,2.21,2.43,2.69,2.55,2.84,2.47,2.69,2.52,2.31,2.07,2.35,2.98,1.98,2.53,2.21,2.62,1.78,2.30),
temperature=c(15.1,13.3,15.3,13.3,14.6,15.6,13.1,13.1,15.0,11.7,15.3,14.4,14.4,12.7,11.7,11.9,15.9,13.4,14.0,13.9,12.9,15.1,13.0),
rainfall=c(67,52,88,61,32,36,72,43,92,32,86,28,57,55,66,26,28,96,48,90,86,78,87))
#initial values
list(intercept=0,slope.temperature=0,slope.rainfall=0,tau=0.01)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-9-1 02:39:34
#linear regression for storks
#number of chicks per pair as a fluncion of both rainfall and temperature in May
model
    {
         for(i in 1:N)
            {
                nbchicksperpair ~dnorm(mu,tau)
                 mu<-intercept+slope.temperature*temperature+slope.rainfall*rainfall
             }
            #priors for regression parameters
           intercept ~dnorm(0,0.001)
           slope.temperature ~ dnorm(0,0.001)
           slope.rainfall ~ dnorm(0,0.001)
           #piors for precision parameter
            tau ~ dgamma(0.001,0.001)
            #monitor the standard deviation
            sigma<-1/sqrt(tau)
}
#data
list(N=23,nbchicksperpair=
c(2.55,1.85,2.05,2.88,3.13,2.21,2.43,2.69,2.55,2.84,2.47,2.69,
2.52,2.31,2.07,2.35,2.98,1.98,2.53,2.21,2.62,1.78,2.30),temperature=
c(15.1,13.3,15.3,13.3,14.6,15.6,13.1,13.1,15.0,11.7,15.3,14.4,14.4,12.7,
11.7,11.9,15.9,13.4,14.0,13.9,12.9,15.1,13.0),rainfall=
c(67,52,88,61,32,36,72,43,92,32,86,28,57,55,66,26,28,96,48,90,86,78,87))
#initial values
list(intercept=0,slope.temperature=0,slope.rainfall=0,tau=0.01)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群