r - R:lpSolve 崩溃 R
问题描述
我正在尝试使用 lpSolve 解决 R 中的线性优化问题。问题的详细信息在前面的问题中描述:https ://math.stackexchange.com/questions/2813747/need-some-help-implementing-a-linear-program-with-a-parameter-and -偏差-va
我编写了以下 R 脚本来读取我的数据集并构建 lpSolve 的输入(路径故意编辑)。最终,我将循环求解与每个观察对应的百分位数,但现在我只是尝试在一个特定的百分位数上进行尝试。
library(readr)
library(dplyr)
library(magrittr)
library(lpSolve)
# Define percentile rank function
perc.rank <- function(x) trunc(rank(x))/length(x)
# Read in domestic and nondomestic datasets
domestic <- read_csv("D:/ ... /QuantileRegression/MSOAs_Areas_Volumes_ExcludedRemoved_Domestic.csv")
nondomestic <- read_csv("D:/ ... /QuantileRegression/MSOAs_Areas_Volumes_ExcludedRemoved_NonDomestic.csv")
# Add percentile rank columns to domestic and nondomestic datasets
domestic$percentile <- perc.rank(domestic$DomesticConsumption)
nondomestic$percentile <- perc.rank(nondomestic$NonDomesticConsumption)
domestic.const.mat <- select(domestic, Area_C1:Area_Mixed)
domestic.const.mat %<>% mutate(underestimation=1) %<>% mutate(overestimation=-1)
domestic.const.dir <- rep("==", length.out=nrow(domestic.const.mat))
domestic.const.rhs <- domestic$DomesticConsumption
domestic.const.rhs <- as.numeric(domestic.const.rhs)
domestic.obj <- rep(c(0.9020071, 1-0.9020071), times=nrow(domestic))
domestic.const.mat <- as.matrix(domestic.const.mat)
lp ("min", domestic.obj, domestic.const.mat, domestic.const.dir, domestic.const.rhs)
“国内”数据集中有 862 个观察值和 9 个约束。
不幸的是,当我开始运行 lp 函数时,R 就死了,没有警告,没有错误,它就停止了。如果我使用 RStudio,它会启动一个新会话,如果我只使用 R 本身,整个程序就会消失。
如果有区别,我正在使用 R 3.5.1 64 位。
有任何想法吗?难道我做错了什么?还有什么我可以尝试的吗?
谢谢
解决方案
推荐阅读
- angular6 - 当我尝试对角度应用程序执行单元测试时..但是在运行测试时我遇到了错误
- jquery - JQuery Accordion,当你折叠一个手风琴时,它们都会折叠。我希望它只会折叠目标手风琴
- python - 当QtableView单元格失去对表单关闭的关注时如何保存正在编辑的数据
- java - JUnits ParametrizedTest 与 TestTemplate
- c# - “Sybase.Data.AseClient1.AseConnection”的类型初始化程序引发异常
- javascript - 选择项目时的任何预期条件?量角器测试
- laravel - 如何获得在特定日期完成的平均任务
- php - 防止多个用户同时执行查询并重定向到不同的会话 php/mysql
- teamcity - 如何在所有代理中运行一个 teamcity 构建实例
- sparql - Jena Fuseki 和 Blazegraph 在字符串文字的“类型严格性”方面表现不同