如何解决stan模型中的发电量块
我正在建立一个标准的线性回归模型,我想包含generated quantities
块,并且我想使用dot_self()
函数。问题是我无法获得仿真样本。错误是:Stan model 'LinearRegression' does not contain samples.
。我认为函数dot_self()
未被识别为一个函数。
我在这里显示stan
代码和R
代码。
预先感谢。
注意:由于没有generated quantities
块的模型可以正常工作,因此我确定输入的数据是正确的。
Stan代码:
data {
int<lower=1> N;
int<lower=1> K;
matrix[N,K] X;
vector[N] y;
}
parameters {
vector[K] beta;
real<lower=0> sigma;
}
model{
vector[N] mu;
mu = X * beta;
beta ~ normal(0,10);
sigma ~ cauchy(0,5);
y ~ normal(mu,sigma);
}
generated quantities {
real rss;
real totalss;
real<lower=0,upper=1> R2;
vector[N] mu;
mu=X * beta;
rss=dot_self(y-mu);
totalss=dot_self(y-mean(y));
R2=1 - rss/totalss;
}
运行Stan模型的R代码:
library(rstan)
library(coda)
library(ggplot2)
rstan_options(auto_write=T)
options(mc.cores=parallel::detectCores())
dat=list(N=N,K=ncol(X),y=y,X=X)
fit3 = stan(file = "C:.... LinearRegression.stan",data = dat,iter = 100,chains = 4)
print(fit3,digits=3,prob=c(.025,.5,.975))
解决方法
请务必添加您使用的数据(X 和 y)。
该错误是由于 R2 的边界造成的。我想没有必要对生成的数量施加限制。
去掉边界后的结果是:
X 和 y 模拟如下:
<UserJourney Id="SignUpOrSignIn">
<OrchestrationSteps>
<OrchestrationStep Order="1" Type="CombinedSignInAndSignUp" ContentDefinitionReferenceId="api.signuporsignin">
<ClaimsProviderSelections>
<ClaimsProviderSelection TargetClaimsExchangeId="GoogleExchange" />
<ClaimsProviderSelection TargetClaimsExchangeId="MyCustomExchange" />
<ClaimsProviderSelection ValidationClaimsExchangeId="LocalAccountSigninEmailExchange" />
</ClaimsProviderSelections>
<ClaimsExchanges>
<ClaimsExchange Id="LocalAccountSigninEmailExchange" TechnicalProfileReferenceId="SelfAsserted-LocalAccountSignin-Email" />
</ClaimsExchanges>
</OrchestrationStep>
<!-- Check if the user has selected to sign in using one of the social providers -->
<OrchestrationStep Order="2" Type="ClaimsExchange">
<Preconditions>
<Precondition Type="ClaimsExist" ExecuteActionsIf="true">
<Value>objectId</Value>
<Action>SkipThisOrchestrationStep</Action>
</Precondition>
</Preconditions>
<ClaimsExchanges>
<ClaimsExchange Id="GoogleExchange" TechnicalProfileReferenceId="Google-OAuth2" />
<ClaimsExchange Id="MyCustomExchange" TechnicalProfileReferenceId="Google-OAuth2" />
</ClaimsExchanges>
</OrchestrationStep>
...
</UserJourney>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。