弥补 idPop3 缺少的 Subject 只是这部分的处理.

博客介绍了处理邮件subject编码的方法,给出了邮件subject常见的编码形式,如=?gb2312?B?Z290b21vYmlsZQ==?= ,并提供了一个名为ConvertCharSet的函数,用于将编码后的字符串转换为正常字符串,解决了indy部分功能缺失的问题。

在收到163.com等一些邮件的时候 subject 通常是下面的形式,

=?gb2312?B?Z290b21vYmlsZQ==?= 

这个翻译过来就是 pic test

只需要一个函数就可以处理好了!indy也就不再残缺了..

//idPop3缺少的只是这部分的处理. Subject

// this function by Chris G黱ther and Sergio Kessler
function ConvertCharSet( const Line : string ) : string;
var
  strToDecode, RestBefore, RestAfter, strActual, decoded: string;
  iLast, iFirst, eFirst, i: integer;
  Encoding, c: char;
  b64Decode: TBase64DecodingStream;
  Dest: TMemoryStream;
begin
  strActual := Line;

  iFirst := Pos( '=?', strActual );
  while (iFirst > 0) do
  begin
    RestBefore := copy( strActual, 1, iFirst-1 );
    strToDecode := copy( strActual, iFirst+2, length( strActual) );
    eFirst := pos( '?', strToDecode);
    if eFirst > 0 then
    begin
      Encoding := UpperCase( strToDecode[eFirst+1])[1];
      delete( strToDecode, 1, eFirst + 2);  // remove until ?Q? or ?B? inclusive
      iLast := Pos( '?=', strToDecode );
      if iLast > 0 then
      begin
        RestAfter := copy( strToDecode, iLast+2, length( strToDecode) );
        delete( strToDecode, iLast, length( strToDecode));  // remove the ?= and the rest

        strActual := RestBefore + RestAfter;
        if Encoding = 'Q' then
        begin
           strActual := RestBefore +
                        sak_QuotedPrintableDecode( PChar( strToDecode) ) +
                        RestAfter;
        end else
        if Encoding = 'B' then
        begin
          Dest := TMemoryStream.Create;

          b64Decode := TBase64DecodingStream.Create( Dest);
          b64Decode.Write( pointer(strToDecode)^, length( strToDecode));
          b64Decode.Free;

          decoded := '';
          Dest.Position := 0;
          for i:= 1 to Dest.Size do
          begin
            Dest.Read( c, 1);
            decoded := decoded + c;
          end;
          Dest.Free;
          strActual := RestBefore + decoded + RestAfter;
        end;

        iFirst := Pos( '=?', strActual );
      end
      else iFirst := 0;
    end
    else iFirst := 0;
  end;
  Result := strActual;
end;

固定效应参数: Intercept 0.068466 gestational_age 0.003049 BMI -0.001303 subject_id Var 2.829078 dtype: float64 随机效应参数: {'A001': subject_id -0.035055 dtype: float64, 'A002': subject_id -0.033353 dtype: float64, 'A003': subject_id -0.017354 dtype: float64, 'A004': subject_id -0.019832 dtype: float64, 'A005': subject_id 0.016035 dtype: float64, 'A006': subject_id 0.001921 dtype: float64, 'A007': subject_id -0.048269 dtype: float64, 'A008': subject_id -0.036862 dtype: float64, 'A009': subject_id -0.003584 dtype: float64, 'A010': subject_id -0.055105 dtype: float64, 'A011': subject_id -0.024666 dtype: float64, 'A012': subject_id -0.028721 dtype: float64, 'A013': subject_id 0.032073 dtype: float64, 'A014': subject_id -0.023335 dtype: float64, 'A015': subject_id -0.024835 dtype: float64, 'A016': subject_id 0.002777 dtype: float64, 'A017': subject_id -0.009749 dtype: float64, 'A018': subject_id -0.029843 dtype: float64, 'A019': subject_id -0.01749 dtype: float64, 'A020': subject_id -0.007834 dtype: float64, 'A021': subject_id 0.011509 dtype: float64, 'A022': subject_id -0.011392 dtype: float64, 'A023': subject_id -0.037848 dtype: float64, 'A024': subject_id -0.016556 dtype: float64, 'A025': subject_id -0.015689 dtype: float64, 'A026': subject_id -0.038976 dtype: float64, 'A027': subject_id 0.032786 dtype: float64, 'A028': subject_id 0.007696 dtype: float64, 'A029': subject_id -0.022293 dtype: float64, 'A030': subject_id -0.005793 dtype: float64, 'A031': subject_id -0.03404 dtype: float64, 'A032': subject_id -0.024406 dtype: float64, 'A033': subject_id -0.015139 dtype: float64, 'A034': subject_id -0.009339 dtype: float64, 'A035': subject_id -0.031526 dtype: float64, 'A036': subject_id -0.004511 dtype: float64, 'A037': subject_id -0.024504 dtype: float64, 'A038': subject_id -0.004405 dtype: float64, 'A039': subject_id -0.0016 dtype: float64, 'A040': subject_id 0.011932 dtype: float64, 'A041': subject_id -0.046103 dtype: float64, 'A042': subject_id -0.039831 dtype: float64, 'A043': subject_id -0.001966 dtype: float64, 'A044': subject_id -0.0304 dtype: float64, 'A045': subject_id -0.023667 dtype: float64, 'A046': subject_id 0.0805 dtype: float64, 'A047': subject_id 0.005504 dtype: float64, 'A048': subject_id -0.023314 dtype: float64, 'A049': subject_id 0.009368 dtype: float64, 'A050': subject_id -0.00174 dtype: float64, 'A051': subject_id -0.011905 dtype: float64, 'A052': subject_id 0.054051 dtype: float64, 'A053': subject_id -0.037906 dtype: float64, 'A054': subject_id -0.017991 dtype: float64, 'A055': subject_id -0.016502 dtype: float64, 'A056': subject_id -0.001291 dtype: float64, 'A057': subject_id 0.023071 dtype: float64, 'A058': subject_id 0.056519 dtype: float64, 'A059': subject_id 0.001228 dtype: float64, 'A060': subject_id -0.021285 dtype: float64, 'A061': subject_id 0.011803 dtype: float64, 'A062': subject_id 0.052794 dtype: float64, 'A063': subject_id -0.011451 dtype: float64, 'A064': subject_id 0.033195 dtype: float64, 'A065': subject_id 0.001137 dtype: float64, 'A066': subject_id -0.011142 dtype: float64, 'A067': subject_id -0.023079 dtype: float64, 'A068': subject_id 0.099633 dtype: float64, 'A069': subject_id 0.002017 dtype: float64, 'A070': subject_id -0.007817 dtype: float64, 'A071': subject_id -0.0119 dtype: float64, 'A072': subject_id 0.007295 dtype: float64, 'A073': subject_id -0.018945 dtype: float64, 'A074': subject_id -0.028083 dtype: float64, 'A075': subject_id -0.01609 dtype: float64, 'A076': subject_id 0.046675 dtype: float64, 'A077': subject_id -0.03244 dtype: float64, 'A078': subject_id -0.043326 dtype: float64, 'A079': subject_id -0.036979 dtype: float64, 'A080': subject_id -0.023735 dtype: float64, 'A081': subject_id -0.009078 dtype: float64, 'A082': subject_id 0.015105 dtype: float64, 'A083': subject_id -0.054908 dtype: float64, 'A084': subject_id -0.008697 dtype: float64, 'A085': subject_id -0.009489 dtype: float64, 'A086': subject_id -0.022621 dtype: float64, 'A087': subject_id -0.017947 dtype: float64, 'A088': subject_id -0.010954 dtype: float64, 'A089': subject_id 0.013006 dtype: float64, 'A090': subject_id -0.000138 dtype: float64, 'A091': subject_id 0.027743 dtype: float64, 'A092': subject_id -0.030805 dtype: float64, 'A093': subject_id -0.021612 dtype: float64, 'A094': subject_id 0.010988 dtype: float64, 'A095': subject_id -0.029956 dtype: float64, 'A096': subject_id -0.029488 dtype: float64, 'A097': subject_id -0.026822 dtype: float64, 'A098': subject_id -0.03862 dtype: float64, 'A099': subject_id -0.023127 dtype: float64, 'A100': subject_id -0.038638 dtype: float64, 'A101': subject_id -0.026807 dtype: float64, 'A102': subject_id -0.008197 dtype: float64, 'A103': subject_id -0.008228 dtype: float64, 'A104': subject_id -0.02187 dtype: float64, 'A105': subject_id -0.007831 dtype: float64, 'A106': subject_id -0.02725 dtype: float64, 'A107': subject_id -0.021428 dtype: float64, 'A108': subject_id -0.007573 dtype: float64, 'A109': subject_id -0.041972 dtype: float64, 'A110': subject_id -0.022468 dtype: float64, 'A111': subject_id -0.017535 dtype: float64, 'A112': subject_id -0.006406 dtype: float64, 'A113': subject_id -0.053638 dtype: float64, 'A114': subject_id -0.040818 dtype: float64, 'A115': subject_id -0.010508 dtype: float64, 'A116': subject_id 0.017527 dtype: float64, 'A117': subject_id -0.007331 dtype: float64, 'A118': subject_id -0.018274 dtype: float64, 'A119': subject_id -0.026648 dtype: float64, 'A120': subject_id 0.001926 dtype: float64, 'A121': subject_id -0.035963 dtype: float64, 'A122': subject_id -0.00637 dtype: float64, 'A123': subject_id -0.02079 dtype: float64, 'A124': subject_id -0.009699 dtype: float64, 'A125': subject_id -0.018569 dtype: float64, 'A126': subject_id -0.030934 dtype: float64, 'A127': subject_id -0.011327 dtype: float64, 'A128': subject_id -0.018097 dtype: float64, 'A129': subject_id -0.01029 dtype: float64, 'A130': subject_id -0.009409 dtype: float64, 'A131': subject_id -0.036589 dtype: float64, 'A132': subject_id -0.033433 dtype: float64, 'A133': subject_id 0.000696 dtype: float64, 'A134': subject_id -0.018836 dtype: float64, 'A135': subject_id -0.011257 dtype: float64, 'A136': subject_id -0.031509 dtype: float64, 'A137': subject_id -0.039988 dtype: float64, 'A138': subject_id -0.023922 dtype: float64, 'A139': subject_id 0.033501 dtype: float64, 'A140': subject_id -0.031922 dtype: float64, 'A141': subject_id 0.004147 dtype: float64, 'A142': subject_id -0.006817 dtype: float64, 'A143': subject_id 0.016955 dtype: float64, 'A144': subject_id -0.011032 dtype: float64, 'A145': subject_id -0.003219 dtype: float64, 'A146': subject_id -0.010208 dtype: float64, 'A147': subject_id -0.034973 dtype: float64, 'A148': subject_id -0.021192 dtype: float64, 'A149': subject_id -0.03637 dtype: float64, 'A150': subject_id -0.016161 dtype: float64, 'A151': subject_id 0.053686 dtype: float64, 'A152': subject_id 0.006725 dtype: float64, 'A153': subject_id -0.026578 dtype: float64, 'A154': subject_id 0.010697 dtype: float64, 'A155': subject_id -0.028225 dtype: float64, 'A156': subject_id 0.010207 dtype: float64, 'A157': subject_id -0.005155 dtype: float64, 'A158': subject_id -0.034062 dtype: float64, 'A159': subject_id -0.035848 dtype: float64, 'A160': subject_id -0.049362 dtype: float64, 'A161': subject_id -0.010667 dtype: float64, 'A162': subject_id 0.031484 dtype: float64, 'A163': subject_id -0.047818 dtype: float64, 'A164': subject_id -0.019143 dtype: float64, 'A165': subject_id -0.034536 dtype: float64, 'A166': subject_id -0.017263 dtype: float64, 'A167': subject_id 0.010783 dtype: float64, 'A168': subject_id -0.016895 dtype: float64, 'A169': subject_id 0.007298 dtype: float64, 'A170': subject_id 0.020844 dtype: float64, 'A171': subject_id 0.035059 dtype: float64, 'A172': subject_id 0.051864 dtype: float64, 'A173': subject_id 0.024722 dtype: float64, 'A174': subject_id 0.031727 dtype: float64, 'A175': subject_id 0.008488 dtype: float64, 'A176': subject_id 0.017845 dtype: float64, 'A177': subject_id -0.002793 dtype: float64, 'A178': subject_id 0.019094 dtype: float64, 'A179': subject_id 0.003643 dtype: float64, 'A180': subject_id 0.028681 dtype: float64, 'A181': subject_id 0.013705 dtype: float64, 'A182': subject_id 0.008126 dtype: float64, 'A183': subject_id 0.012754 dtype: float64, 'A184': subject_id 0.014773 dtype: float64, 'A185': subject_id 0.044755 dtype: float64, 'A186': subject_id 0.015975 dtype: float64, 'A187': subject_id 0.021939 dtype: float64, 'A188': subject_id -0.001218 dtype: float64, 'A189': subject_id 0.049337 dtype: float64, 'A190': subject_id 0.018324 dtype: float64, 'A191': subject_id 0.002759 dtype: float64, 'A192': subject_id 0.031426 dtype: float64, 'A193': subject_id 0.038672 dtype: float64, 'A194': subject_id -0.013302 dtype: float64, 'A195': subject_id 0.044341 dtype: float64, 'A196': subject_id 0.017216 dtype: float64, 'A197': subject_id 0.039507 dtype: float64, 'A198': subject_id 0.020454 dtype: float64, 'A199': subject_id 0.012259 dtype: float64, 'A200': subject_id -0.015608 dtype: float64, 'A201': subject_id 0.006145 dtype: float64, 'A202': subject_id 0.01747 dtype: float64, 'A203': subject_id 0.04035 dtype: float64, 'A204': subject_id -0.012706 dtype: float64, 'A205': subject_id 0.044003 dtype: float64, 'A206': subject_id 0.050602 dtype: float64, 'A207': subject_id -0.00632 dtype: float64, 'A208': subject_id 0.027058 dtype: float64, 'A209': subject_id -0.003056 dtype: float64, 'A210': subject_id 0.015636 dtype: float64, 'A211': subject_id 0.037614 dtype: float64, 'A212': subject_id 0.034854 dtype: float64, 'A213': subject_id 0.010366 dtype: float64, 'A214': subject_id 0.019028 dtype: float64, 'A215': subject_id -0.002413 dtype: float64, 'A216': subject_id 0.021927 dtype: float64, 'A217': subject_id -0.008786 dtype: float64, 'A218': subject_id -0.025894 dtype: float64, 'A219': subject_id 0.047479 dtype: float64, 'A220': subject_id 0.056642 dtype: float64, 'A221': subject_id 0.014175 dtype: float64, 'A222': subject_id 0.029246 dtype: float64, 'A223': subject_id 0.013788 dtype: float64, 'A224': subject_id 0.047536 dtype: float64, 'A225': subject_id 0.025669 dtype: float64, 'A226': subject_id 0.009542 dtype: float64, 'A227': subject_id -0.015876 dtype: float64, 'A228': subject_id 0.034077 dtype: float64, 'A229': subject_id 0.010697 dtype: float64, 'A230': subject_id -0.008141 dtype: float64, 'A231': subject_id 0.007941 dtype: float64, 'A232': subject_id 0.017171 dtype: float64, 'A233': subject_id 0.042276 dtype: float64, 'A234': subject_id 0.000055 dtype: float64, 'A235': subject_id 0.006856 dtype: float64, 'A236': subject_id 0.047018 dtype: float64, 'A237': subject_id 0.03415 dtype: float64, 'A238': subject_id 0.037387 dtype: float64, 'A239': subject_id 0.047311 dtype: float64, 'A240': subject_id 0.021462 dtype: float64, 'A241': subject_id 0.014295 dtype: float64, 'A242': subject_id 0.026146 dtype: float64, 'A243': subject_id 0.03765 dtype: float64, 'A244': subject_id 0.062082 dtype: float64, 'A245': subject_id -0.013744 dtype: float64, 'A246': subject_id 0.022484 dtype: float64, 'A247': subject_id 0.032606 dtype: float64, 'A248': subject_id 0.010429 dtype: float64, 'A249': subject_id -0.010792 dtype: float64, 'A250': subject_id 0.033156 dtype: float64, 'A251': subject_id 0.011312 dtype: float64, 'A252': subject_id 0.026192 dtype: float64, 'A253': subject_id 0.039934 dtype: float64, 'A254': subject_id 0.043422 dtype: float64, 'A255': subject_id -0.008678 dtype: float64, 'A256': subject_id 0.038307 dtype: float64, 'A257': subject_id 0.012337 dtype: float64, 'A258': subject_id -0.007633 dtype: float64, 'A259': subject_id 0.047141 dtype: float64, 'A260': subject_id 0.039699 dtype: float64, 'A261': subject_id 0.012697 dtype: float64, 'A262': subject_id 0.034507 dtype: float64, 'A263': subject_id 0.002251 dtype: float64, 'A264': subject_id 0.015835 dtype: float64, 'A265': subject_id 0.015058 dtype: float64, 'A266': subject_id 0.00932 dtype: float64, 'A267': subject_id 0.037195 dtype: float64} Click to add a cell.根据所给参数把这个表达式写出来
最新发布
09-06
根据你提供的模型参数输出,可以写出最终的线性混合模型表达式如下: ### 模型表达式 #### 总体模型(Population-level,固定效应 + 随机效应): $$ Y_{ij} = (\beta_0 + u_i) + \beta_1 \cdot \text{gestational\_age}_{ij} + \beta_2 \cdot \text{BMI}_{ij} + \varepsilon_{ij} $$ 其中: - $ Y_{ij} $:第 $ i $ 个孕妇第 $ j $ 次观测的 `Y_concentration` 值。 - $ \beta_0 = 0.068466 $:固定截距项。 - $ \beta_1 = 0.003049 $:`gestational_age` 的固定效应系数。 - $ \beta_2 = -0.001303 $:`BMI` 的固定效应系数。 - $ u_i $:第 $ i $ 个孕妇的随机截距,服从 $ N(0, \sigma_u^2) $,估计值见 `random_effects`。 - $ \varepsilon_{ij} $:残差项,服从 $ N(0, \sigma^2) $,模型默认估计。 #### 固定效应部分(Fixed Effects): $$ Y_{ij} = 0.068466 + 0.003049 \cdot \text{gestational\_age}_{ij} - 0.001303 \cdot \text{BMI}_{ij} $$ #### 随机截距(Random Intercept): 对于第 $ i $ 个孕妇,其最终的个体特异性模型为: $$ Y_{ij} = (0.068466 + u_i) + 0.003049 \cdot \text{gestational\_age}_{ij} - 0.001303 \cdot \text{BMI}_{ij} $$ 例如,对于 `subject_id = A001`,其随机截距 $ u_i = -0.035055 $,则其个体模型为: $$ Y_{ij} = (0.068466 - 0.035055) + 0.003049 \cdot \text{gestational\_age}_{ij} - 0.001303 \cdot \text{BMI}_{ij} $$ $$ Y_{ij} = 0.033411 + 0.003049 \cdot \text{gestational\_age}_{ij} - 0.001303 \cdot \text{BMI}_{ij} $$ --- ### 模型方差成分(Variance Components): - 随机截距的方差(subject_id Var):2.829078 - 残差方差(Residual Var):未直接给出,可以通过 `result.scale` 提取。 --- ### Python 代码提取残差方差: ```python # 提取残差方差 residual_var = result.scale print("残差方差:", residual_var) ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值