从lm函数获取分组数据的p值(Get the p-values from the lm function for grouped data)
我正在尝试使用
lm()
函数和plyr
包为我的数据中的每个段拟合一个模型,因为我的数据是按键分组的。我已经设法运行模型并获得系数以及R ^ 2和adj平方但我正在努力与p值。
library("plyr") #Sample data test_data <- data.frame(key = c("a","a","a","a","a","b","b","b","b","b"), y = c(100,180,120,60,140,200,220,240,260,280), x1 = c(50,60,79,85,90,133,140,120,160,170), x2 = c(20,18,47,16,15,25,30,25,20,15)) #model model_1 <- dlply(test_data, .(key), function(test_data) lm(y ~ x1 + x2,data = test_data)) #coefficients ldply(model_1, coef) #adj r-squared ldply(model_1, function(x) summary(x)$r.squared)
我试过这个让我获得密钥和p值但它没有变量的名称,我需要能够将输出与模型中的系数合并。
#p-values but missing the variable names ldply(model_1, function(x) summary(x)$coefficients)[,c(1,5)]
我试图使用
Do
来适应模型,然后从dplyr
包中tidy
,这可以很好地处理一个小数据集,因为它实际上返回了我需要的所有东西,但我的实际数据包含超过1,000个不同的段,并且RStudio最终崩溃。I am trying to fit a model for each segment in my data using the
lm()
function in conjunction with theplyr
package because my data is grouped by a key.I've managed to run the model and get the coefficients along with the R^2 & adj r-squared but I am struggling with the p-values.
library("plyr") #Sample data test_data <- data.frame(key = c("a","a","a","a","a","b","b","b","b","b"), y = c(100,180,120,60,140,200,220,240,260,280), x1 = c(50,60,79,85,90,133,140,120,160,170), x2 = c(20,18,47,16,15,25,30,25,20,15)) #model model_1 <- dlply(test_data, .(key), function(test_data) lm(y ~ x1 + x2,data = test_data)) #coefficients ldply(model_1, coef) #adj r-squared ldply(model_1, function(x) summary(x)$r.squared)
I've tried this which gets me the key and the p-value but it doesn't have the names of the variables which I need to be able to merge the output with the coefficients from the model later.
#p-values but missing the variable names ldply(model_1, function(x) summary(x)$coefficients)[,c(1,5)]
I've tried to fit the models using
Do
and thentidy
from thedplyr
package and this works fine with a small data set because it actually returns everything I need but my actual data contains over 1,000 different segments and RStudio end up crashing.
原文:https://stackoverflow.com/questions/36065447
最满意答案
我知道如何解决这个问题,我只是不知道为什么会这样。 如果有人能回答,我会很感激。
修复是,而不是在karma.conf.js中具有以下配置
preprocessors: { "**/*.js": ["webpack"] },
我现在有:
preprocessors: { "test/**/*.js": ["webpack"] },
I know how to fix this, I just don't know why it works. If anyone can answer that, I'd appreciate.
The fix is, instead of having the following config in karma.conf.js
preprocessors: { "**/*.js": ["webpack"] },
I now have:
preprocessors: { "test/**/*.js": ["webpack"] },
相关问答
更多-
其实它是重写模块(angular.mock.module)到(module.exports)的webpack,那么解决方案不使用别名。 直接使用这个angular.mock函数: angular.mock.module() Actually it was webpack whitch rewrites module (angular.mock.module) to (module.exports), then the solution is not using the alias. Use directl ...
-
我为后人回答自己的问题: 这与我的另一个问题有关: Aurelia,运行webpack-dev-server --hot在应用程序热更新上抛出错误 - '无法读取属性状态'undefined' 总之,Aurelia不支持HMR ......但(只有CSS)。 https://github.com/aurelia/skeleton-navigation/issues/629 http://blog.aurelia.io/2016/12/08/big-aurelia-release-update/ I'm an ...
-
事实证明,我已经在全局安装了业力npm install -g karma和karma-jasmine本地npm install karma-jasmine 。 我在全球范围内重新安装了karma-jasmine,现在正在运作。 It turned out that I have installed karma globally npm install -g karma and karma-jasmine locally npm install karma-jasmine. I reinstalled kar ...
-
angular-mocks.js缺失请参阅http://devnet.jetbrains.com/thread/452824?tstart=0 angular-mocks.js is missing See http://devnet.jetbrains.com/thread/452824?tstart=0
-
Karma-jasmine UncaughtReference错误状态栏未定义(Karma-jasmine UncaughtReference Error Statusbar not defined)[2023-05-03]
问题是,我没有模仿我的角度应用程序模块。 在我模块的run函数中,我得到了$ ionicPlatform来监听“deviceReady”事件。 在这种情况下,我访问状态栏和其他人的cordova插件。 但由于我没有使用其插件模拟应用程序模块,因此一旦触发了deviceready事件,测试就会失败。 为了解决这个问题,我刚刚定义了一个全局变量“testEnvironment”,因为我不想在模块中测试我的run方法,所以我只检查testEnvironment是否为true并退出run方法。 我全局定义了变量,并 ... -
使用karma + babel + webpack和bundle一起追踪错误(Tracing errors using karma + babel + webpack with bundles)[2021-11-22]
将devtool设置为在webpack中评估。 这个对我有用。 会给你正确的文件名与行号。 在这里阅读更多http://webpack.github.io/docs/configuration.html#devtool webpack: { devtool: 'eval', module: { loaders: [{ test: /\.js/, exclude: /node_modules/, ... -
问题是我从Barrel导入MyObject和HairColor! 如下: import { HairColor } from '../index'; 我将其更改为从自己的文件导入,问题现在解决了! import { HairColor } from '../enums/hair-color.enum'; The issue was that I was importing MyObject and HairColor from the Barrel! Like the following: import ...
-
我知道如何解决这个问题,我只是不知道为什么会这样。 如果有人能回答,我会很感激。 修复是,而不是在karma.conf.js中具有以下配置 preprocessors: { "**/*.js": ["webpack"] }, 我现在有: preprocessors: { "test/**/*.js": ["webpack"] }, I know how to fix this, I just don't know why it works. If anyone can answer that, ...
-
基于错误消息,您似乎没有安装babel-preset-airbnb并且您正在babel loader配置中使用它。 确保安装它: $ npm install --save-dev babel-preset-airbnb Based on the error message it seems you don't have babel-preset-airbnb installed and you are using it in the babel loader config. Make sure you ha ...
-
依赖关系路径与当前脚本相关。 所以只需重写你的require语句: var utilities = require('./utilities.js'); Dependencies paths are relative to current script. So just rewrite your require statement: var utilities = require('./utilities.js');