全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
786 2
2019-07-24
老师要求的图


代码
memory<- 5
nFarm <- 20    # Number of farms in the system
nAct  <- 72     # Number of activities in the system
nYear <- 11    # Number of year in total (1999 - 2009)
region_names<- read.csv('region_names.csv', header = FALSE)
farm_names  <- as.character(region_names[1:nFarm,])
act_names   <- paste('activity', formatC(1:nAct, width=nchar(nAct), flag='0'), sep='')

####---------- I. Set up ranges of means for generating input parameters ----------####

input_values <- list(
  ref_income_mu  = list(min=100, max=400, randomFunc="qunif"),
  #ref_income_ratio_mu= list(min=0.4,  max=0.9),   # Mean of aspiration levels
  tolincome_mu =       list(min=0.01, max=0.3,randomFunc="qunif"),  # Mean of tolerance of dissimilarity in income change
  tolactivi_mu =       list(min=0.1,  max=0.75,randomFunc="qunif"),  # Mean of tolerance of dissimilarity in activity
  lambda_mu    =       list(min=1.50, max=4.00,randomFunc="qunif"),  # Mean of lambda in satisfaction calculation using CPT
  alpha_plus_mu=       list(min=0.50, max=1,randomFunc="qunif"),  # Mean of alpha_plus in satisfaction calculation using CPT
  alpha_minus_mu=      list(min=0.50, max=1,randomFunc="qunif"),  # Mean of alpha_plus in satisfaction calculation using CPT
  phi_plus_mu  =       list(min=0.50, max=1,randomFunc="qunif"),  # Mean of alpha_minus in satisfaction calculation using CPT
  phi_minus_mu =       list(min=0.50, max=1,randomFunc="qunif"),   # Mean of alpha_minus in satisfaction calculation using CPT
  price_mu           = list(min=300, max=400, randomFunc="qunif")         # Mean of price
)


# TODO: number of parameter sets (for LHS)
sample_count <- 200

# TODO: give number of bootstraps in SRC/SRRC
src_nboot <- 100

# TODO: SRC or SRRC (on ranks)
on_rank <- FALSE

# TODO: names of output values
output_names  <- c("opt-out","imitation","optimization","repetition") # Corresponding to c(1,2,3,4)
input_names   <- names(input_values)

# how many repetitions for each input factor set should be run (to control stochasticity)?
# TODO: adapt the number of repititions, set to 1 if deterministic model
#no.repeated.sim <- 10
num_repeated_simu <- 3  

# TODO: should R report the progress
trace_progress = FALSE
output_names  <- c("opt-out","imitation","optimization","repetition") # Corresponding to c(1,2,3,4)
input_names   <- names(input_values)


#### Load "sim_results_lhs_orig" and "lhs_design"

# transform the data
sim_results_lhs <- t(sim_results_lhs_orig)
output_names  <- c("opt-out","imitation","optimization","repetition") # Corresponding to c(1,2,3,4)
colnames(sim_results_lhs) <- output_names
sim_results_lhs <- cbind(as.data.frame(lhs_design), sim_results_lhs)

#-------------------------------------------------------------------------------------
# V. Run of SRC/SRRC
#-------------------------------------------------------------------------------------
require(sensitivity)

# iterate over different evaluation criteria in simulation results
# calculate SRC
src_list <- list()
for (o in output_names) {
  src_list[[o]] <- src(X=sim_results_lhs[,1:length(input_values)], y=sim_results_lhs[o], nboot = src_nboot, rank = FALSE)
}

# calculate SRRC
srrc_list <- list()
for (o in output_names) {
  srrc_list[[o]] <- src(X=sim_results_lhs[,1:length(input_values)], y=sim_results_lhs[o], nboot = src_nboot, rank = TRUE)
}


#-------------------------------------------------------------------------------------
# VI. Calculation of R? for the original data
#-------------------------------------------------------------------------------------
## Function calculating R squared
get.rsquare <- function(x, y, rank) {
  data <- data.frame(Y = y, x)
  if (rank) {
    for (i in 1:ncol(data)) {
      data[,i] <- rank(data[,i])
    }
  }
  i = 1:nrow(data)
  d <- data[i, ]
  lm.Y <- lm(formula(paste(colnames(d)[1], "~", paste(colnames(d)[-1], collapse = "+"))), data = d)
  return(summary(lm.Y)$r.squared)
}

## Calculate R squared for SRC
r_square_src <- list()
for (o in output_names) {
  r_square_src[[o]] <- get.rsquare(x=sim_results_lhs[,1:length(input_values)], y=sim_results_lhs[o], rank=FALSE)
}

print(r_square_src)

## Calculate R squared for SRRC
r_square_srrc <- list()
for (o in output_names) {
  r_square_srrc[[o]] <- get.rsquare(x=sim_results_lhs[,1:length(input_values)], y=sim_results_lhs[o], rank=TRUE)
}

print(r_square_srrc)

#-------------------------------------------------------------------------------------
# IV. Analysis of the results (postprocessing)
#-------------------------------------------------------------------------------------

# plot of package sensitivitiy (not shown in the paper)
# (package sesnitivity must be loaded)
for (o in output_names)
{   
  plot(src_list[[o]])
  title(sub=o)

  plot(srrc_list[[o]])
  title(sub=o)
}
library(sensitivity)

老师给的数据

微信截图_20190724082755.png

附件列表
微信截图_20190724083036.png

原图尺寸 32.08 KB

微信截图_20190724083036.png

微信图片_20190724082418.jpg

原图尺寸 89.86 KB

微信图片_20190724082418.jpg

二维码

扫码加我 拉你入群

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

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

全部回复
2019-7-24 08:33:42
最后一张图是老师要求的
二维码

扫码加我 拉你入群

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

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

2019-7-31 14:12:34
HHLDPPH 发表于 2019-7-24 08:33
最后一张图是老师要求的
这么长的代码而且没有原始数据,去淘宝上花点钱找人给你做下吧。

能解决你问题的人不太可能有耐心和时间免费给你一行一行读你的代码的。。
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群