【问题标题】:How do I do linear regression on count output with continuous predictor? (Sentiment Analysis如何使用连续预测器对计数输出进行线性回归? (情绪分析
【发布时间】:2022-12-12 08:35:11
【问题描述】:

所以我有一个情绪值(范围 -2<x<2)和附加的分类数据(0,1)。我想看看情感值是否可以预测分类数据的数量。我该怎么做?我要使用哪种型号?数据是这样的

element id | sentiment | Delta
1          | -1.038    | 0
2          |  1.263    | 0
3          | -1.900    | 0
4          |  0.038    | 1
5          |  0.000    | 0
6          |  0.458    | 0

此外,数据高度倾斜,90%+ 的增量值为 0

我试过拟合线性模型但它不起作用

【问题讨论】:

  • 您可以尝试使用具有二项分布的 glm。 glm(公式,族=二项式(链接=“logit”),数据,...)

标签: r statistics regression data-science sentiment-analysis


【解决方案1】:

如果我理解正确的话,你可以这样使用逻辑回归:model &lt;- glm(Delta ~ sentiment, data=df, family=binomial)

请参阅下面的整个分析,包括带有 report 包的报告。

# INPUT - Your data
df <- tibble::tribble(
  ~id, ~sentiment, ~Delta,
   1L,     -1.038,     0L,
   2L,      1.263,     0L,
   3L,       -1.9,     0L,
   4L,      0.038,     1L,
   5L,          0,     0L,
   6L,      0.458,     0L
  )

df
#> # A tibble: 6 × 3
#>      id sentiment Delta
#>   <int>     <dbl> <int>
#> 1     1    -1.04      0
#> 2     2     1.26      0
#> 3     3    -1.9       0
#> 4     4     0.038     1
#> 5     5     0         0
#> 6     6     0.458     0

# SOLUTION
model <- glm(Delta ~ sentiment, data=df, family=binomial)
summary(model) # get the summary
#> 
#> Call:
#> glm(formula = Delta ~ sentiment, family = binomial, data = df)
#> 
#> Deviance Residuals: 
#>       1        2        3        4        5        6  
#> -0.5344  -0.7177  -0.4767   1.8759  -0.6117  -0.6486  
#> 
#> Coefficients:
#>             Estimate Std. Error z value Pr(>|z|)
#> (Intercept)  -1.5813     1.1013  -1.436    0.151
#> sentiment     0.2822     1.1302   0.250    0.803
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 5.4067  on 5  degrees of freedom
#> Residual deviance: 5.3417  on 4  degrees of freedom
#> AIC: 9.3417
#> 
#> Number of Fisher Scoring iterations: 4

library(report)
report(model) # report the solution
#> We fitted a logistic model (estimated using ML) to predict Delta with sentiment
#> (formula: Delta ~ sentiment). The model's explanatory power is very weak
#> (Tjur's R2 = 6.57e-03). The model's intercept, corresponding to sentiment = 0,
#> is at -1.58 (95% CI [-4.55, 0.27], p = 0.151). Within this model:
#> 
#>   - The effect of sentiment is statistically non-significant and positive (beta =
#> 0.28, 95% CI [-1.93, 3.27], p = 0.803; Std. beta = 0.32, 95% CI [-2.17, 3.66])
#> 
#> Standardized parameters were obtained by fitting the model on a standardized
#> version of the dataset. 95% Confidence Intervals (CIs) and p-values were
#> computed using a Wald z-distribution approximation.

创建于 2022-12-11 reprex v2.0.2

【讨论】:

    猜你喜欢
    • 2012-12-07
    • 2020-11-09
    • 2017-11-30
    • 2017-11-06
    • 2018-12-26
    • 2015-06-19
    • 2019-09-11
    • 2013-11-15
    • 2015-09-23
    相关资源
    最近更新 更多