Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • stata neuling möchte fehlende werte ersetzten

    as part of a research project, we would like to determine predictors for the outcome of a particular form of therapy. To this end, we collected pre- and post-data using various PROM questionnaires. however, some of these questionnaires contain missing values because not all questions were answered. Now I would like to replace these missing values. I would like to use either FIML or MI, as I think these are the most useful methods. however, my experience with stata is very limited (I have only been working with it since the start of the project). Both are difficult for me. The theoretical background underlying both calculations is mostly clear to me. However, I don't understand why I still seem to have missing data after FIML - this shouldn't really be the case, should it?
    In the following code, I compare a sum score before the FIML with a score after the FIML at the end (Table at the end). The latter should actually take on a different value by replacing the missing values. what am I doing wrong here - or is my train of thought not correct? I hope you understand what I mean

    Code:
    * Apply FIML to handle missing values in fess_1_pre - fess_10_pre
    sem (fess_1_pre fess_2_pre fess_3_pre fess_4_pre fess_5_pre ///
    fess_6_pre fess_7_pre fess_8_pre fess_9_pre fess_10_pre), method(mlmv)

    * Generate new variable fess_score_pre_new as the sum of non-zero items
    egen fess_score_pre_new = rowtotal(fess_1_pre fess_2_pre fess_3_pre fess_4_pre ///
    fess_5_pre fess_6_pre fess_7_pre fess_8_pre ///
    fess_9_pre fess_10_pre) if fess_1_pre != 0 & ///
    fess_2_pre != 0 & fess_3_pre != 0 & fess_4_pre != 0 & ///
    fess_5_pre != 0 & fess_6_pre != 0 & fess_7_pre != 0 & ///
    fess_8_pre != 0 & fess_9_pre != 0 & fess_10_pre != 0

    * Documentation:
    * - The sem command applies FIML to handle missing values in the specified variables.
    * - The egen function with rowtotal calculates the sum of the non-zero items for each observation/id.
    * - The if condition excludes any observations where any of the fess_1_pre to fess_10_pre items are 0.
    * - The new variable fess_score_pre_new now contains the recalculated sum score, excluding 0 values.
    * - The existing fess_score_pre variable is preserved.


    * Create a table comparing the two variables
    tabstat fess_score_pre fess_score_pre_new, ///
    statistics(n mean sd min max) ///
    columns(statistics) ///
    longstub


    Output:
    * Using Full-Information Maximum Likelihood (FIML) in Stata to handle missing
    > values
    . * Ensure missing values are coded as "." for FIML to work correctly
    .
    . * Apply FIML to handle missing values in fess_1_pre - fess_10_pre
    . sem (fess_1_pre fess_2_pre fess_3_pre fess_4_pre fess_5_pre ///
    > fess_6_pre fess_7_pre fess_8_pre fess_9_pre fess_10_pre), method(mlmv)
    (1 all-missing observation excluded)

    Exogenous variables
    Observed: fess_1_pre fess_2_pre fess_3_pre fess_4_pre fess_5_pre fess_6_pre
    fess_7_pre fess_8_pre fess_9_pre fess_10_pre

    Fitting saturated model:
    Iteration 0: log likelihood = -1987.5859
    Iteration 1: log likelihood = -1986.2606
    Iteration 2: log likelihood = -1986.2261
    Iteration 3: log likelihood = -1986.2261

    Fitting baseline model:
    Iteration 0: log likelihood = -2341.374
    Iteration 1: log likelihood = -2341.3686
    Iteration 2: log likelihood = -2341.3686

    Fitting target model:
    Iteration 0: log likelihood = -1986.2261
    Iteration 1: log likelihood = -1986.2261

    Structural equation model Number of obs = 142
    Estimation method: mlmv

    Log likelihood = -1986.2261

    -------------------------------------------------------------------------------
    | OIM
    | Coefficient std. err. z P>|z| [95% conf. interval]
    --------------+----------------------------------------------------------------
    mean(fe~1_pre)| 3.753521 .1059557 35.43 0.000 3.545852 3.96119
    mean(fess_2~e)| 4.297576 .0997105 43.10 0.000 4.102147 4.493005
    mean(fess_3~e)| 3.59276 .116653 30.80 0.000 3.364125 3.821396
    mean(fess_4~e)| 3.818664 .1002849 38.08 0.000 3.62211 4.015219
    mean(fess_5~e)| 4.139852 .105352 39.30 0.000 3.933366 4.346338
    mean(fess_6~e)| 3.415493 .1026542 33.27 0.000 3.214294 3.616691
    mean(fess_7~e)| 3.570423 .1307653 27.30 0.000 3.314127 3.826718
    mean(fess_8~e)| 3.514085 .1009457 34.81 0.000 3.316235 3.711934
    mean(fess_9~e)| 3.626761 .1070836 33.87 0.000 3.416881 3.83664
    mean(fe~0_pre)| 3.690141 .1011652 36.48 0.000 3.491861 3.888421
    --------------+----------------------------------------------------------------
    var(fess_1_~e)| 1.594178 .1891941 1.263333 2.011666
    var(fess_2_~e)| 1.389289 .1664312 1.098556 1.756965
    var(fess_3_~e)| 1.925182 .2288001 1.525141 2.430153
    var(fess_4_~e)| 1.42291 .1690777 1.127283 1.796063
    var(fess_5_~e)| 1.563497 .1864577 1.237615 1.975189
    var(fess_6_~e)| 1.49638 .1775876 1.185831 1.888256
    var(fess_7_~e)| 2.428139 .2881671 1.924219 3.064027
    var(fess_8_~e)| 1.446985 .1717255 1.146687 1.825925
    var(fess_9_~e)| 1.628298 .1932434 1.290372 2.054721
    var(fess_10~e)| 1.453283 .172473 1.151678 1.833873
    --------------+----------------------------------------------------------------
    cov(fess_1_~e,|
    fess_2_pre)| .6959802 .1384627 5.03 0.000 .4245983 .9673621
    cov(fess_1_~e,|
    fess_3_pre)| 1.025174 .1704203 6.02 0.000 .6911559 1.359191
    cov(fess_1_~e,|
    fess_4_pre)| .6929782 .1392014 4.98 0.000 .4201485 .965808
    cov(fess_1_~e,|
    fess_5_pre)| .6199708 .1425125 4.35 0.000 .3406515 .8992901
    cov(fess_1_~e,|
    fess_6_pre)| .6587483 .1409086 4.68 0.000 .3825724 .9349241
    cov(fess_1_~e,|
    fess_7_pre)| .4082027 .1686215 2.42 0.015 .0777107 .7386948
    cov(fess_1_~e,|
    fess_8_pre)| .7464293 .1420154 5.26 0.000 .4680843 1.024774
    cov(fess_1_~e,|
    fess_9_pre)| .8657508 .1534881 5.64 0.000 .5649197 1.166582
    cov(fess_1_~e,|
    fess_10_pre)| .5151756 .1348499 3.82 0.000 .2508747 .7794765
    cov(fess_2_~e,|
    fess_3_pre)| .707832 .150346 4.71 0.000 .4131592 1.002505
    cov(fess_2_~e,|
    fess_4_pre)| .7702579 .1356952 5.68 0.000 .5043002 1.036216
    cov(fess_2_~e,|
    fess_5_pre)| .8982935 .1456122 6.17 0.000 .6128987 1.183688
    cov(fess_2_~e,|
    fess_6_pre)| .7120622 .1356932 5.25 0.000 .4461084 .9780161
    cov(fess_2_~e,|
    fess_7_pre)| .5947767 .1634216 3.64 0.000 .2744762 .9150772
    cov(fess_2_~e,|
    fess_8_pre)| .6619475 .1327698 4.99 0.000 .4017235 .9221715
    cov(fess_2_~e,|
    fess_9_pre)| .7167607 .1410359 5.08 0.000 .4403354 .9931859
    cov(fess_2_~e,|
    fess_10_pre)| .473951 .1267695 3.74 0.000 .2254874 .7224147
    cov(fess_3_~e,|
    fess_4_pre)| .8986428 .1588445 5.66 0.000 .5873133 1.209972
    cov(fess_3_~e,|
    fess_5_pre)| .7904607 .1602389 4.93 0.000 .4763982 1.104523
    cov(fess_3_~e,|
    fess_6_pre)| .9649799 .1638709 5.89 0.000 .6437988 1.286161
    cov(fess_3_~e,|
    fess_7_pre)| .5669175 .1883615 3.01 0.003 .1977358 .9360992
    cov(fess_3_~e,|
    fess_8_pre)| .9383406 .1616449 5.80 0.000 .6215223 1.255159
    cov(fess_3_~e,|
    fess_9_pre)| 1.103945 .1759019 6.28 0.000 .7591836 1.448707
    cov(fess_3_~e,|
    fess_10_pre)| .545249 .1485431 3.67 0.000 .2541098 .8363882
    cov(fess_4_~e,|
    fess_5_pre)| .7329144 .1404756 5.22 0.000 .4575872 1.008242
    cov(fess_4_~e,|
    fess_6_pre)| .7285103 .1371322 5.31 0.000 .4597362 .9972844
    cov(fess_4_~e,|
    fess_7_pre)| .7971047 .1699422 4.69 0.000 .4640242 1.130185
    cov(fess_4_~e,|
    fess_8_pre)| .8854802 .1417811 6.25 0.000 .6075943 1.163366
    cov(fess_4_~e,|
    fess_9_pre)| .9516822 .1506946 6.32 0.000 .6563261 1.247038
    cov(fess_4_~e,|
    fess_10_pre)| .6128256 .1311902 4.67 0.000 .3556975 .8699537
    cov(fess_5_~e,|
    fess_6_pre)| .8925968 .1486674 6.00 0.000 .601214 1.18398
    cov(fess_5_~e,|
    fess_7_pre)| .6602347 .1735039 3.81 0.000 .3201734 1.000296
    cov(fess_5_~e,|
    fess_8_pre)| .6551925 .138805 4.72 0.000 .3831397 .9272453
    cov(fess_5_~e,|
    fess_9_pre)| .828412 .1518199 5.46 0.000 .5308505 1.125974
    cov(fess_5_~e,|
    fess_10_pre)| .6294073 .1380864 4.56 0.000 .3587629 .9000518
    cov(fess_6_~e,|
    fess_7_pre)| .5517258 .1665266 3.31 0.001 .2253396 .8781121
    cov(fess_6_~e,|
    fess_8_pre)| .9131621 .1453288 6.28 0.000 .6283229 1.198001
    cov(fess_6_~e,|
    fess_9_pre)| .922684 .1521651 6.06 0.000 .6244459 1.220922
    cov(fess_6_~e,|
    fess_10_pre)| .6005753 .1336211 4.49 0.000 .3386827 .8624679
    cov(fess_7_~e,|
    fess_8_pre)| .8616842 .1731233 4.98 0.000 .5223687 1.201
    cov(fess_7_~e,|
    fess_9_pre)| .7269887 .1776657 4.09 0.000 .3787702 1.075207
    cov(fess_7_~e,|
    fess_10_pre)| .6415394 .1665801 3.85 0.000 .3150484 .9680303
    cov(fess_8_~e,|
    fess_9_pre)| 1.121454 .1595279 7.03 0.000 .808785 1.434123
    cov(fess_8_~e,|
    fess_10_pre)| .7578853 .1373099 5.52 0.000 .4887629 1.027008
    cov(fess_9_~e,|
    fess_10_pre)| .792799 .1452271 5.46 0.000 .5081592 1.077439
    -------------------------------------------------------------------------------
    LR test of model vs. saturated: chi2(0) = 0.00 Prob > chi2 = .

    .
    . * Generate new variable fess_score_pre_new as the sum of non-zero items
    . egen fess_score_pre_new = rowtotal(fess_1_pre fess_2_pre fess_3_pre fess_4_pre
    > ///
    > fess_5_pre fess_6_pre fess_7_pre fess_8_pre
    > ///
    > fess_9_pre fess_10_pre) if fess_1_pre != 0
    > & ///
    > fess_2_pre != 0 & fess_3_pre != 0 & fess_4_
    > pre != 0 & ///
    > fess_5_pre != 0 & fess_6_pre != 0 & fess_7_
    > pre != 0 & ///
    > fess_8_pre != 0 & fess_9_pre != 0 & fess_10
    > _pre != 0

    .
    . * Documentation:
    . * - The sem command applies FIML to handle missing values in the specified var
    > iables.
    . * - The egen function with rowtotal calculates the sum of the non-zero items f
    > or each observation/id.
    . * - The if condition excludes any observations where any of the fess_1_pre to
    > fess_10_pre items are 0.
    . * - The new variable fess_score_pre_new now contains the recalculated sum scor
    > e, excluding 0 values.
    . * - The existing fess_score_pre variable is preserved.
    .
    .
    . * Create a table comparing the two variables
    . tabstat fess_score_pre fess_score_pre_new, ///
    > statistics(n mean sd min max) ///
    > columns(statistics) ///
    > longstub

    Variable | N Mean SD Min Max
    -------------+--------------------------------------------------
    fess_score~e | 143 36.91608 9.619886 0 58
    fess_score~w | 143 36.91608 9.619886 0 58

    ----------------------------------------------------------------

    .
    end of do-file

    Last edited by Phillip Thies; 22 Mar 2024, 05:24. Reason: i had a mix uf languages in my post, title is still in german - sorry

  • #2
    FIML does not replace missing values. It just uses all the available information, including from observations with partially missing information, in the estimation. So this is something you do in the final model. This is also the logic behind MI: MI does not recover the missing values. They are assumed to be lost forever. The imputation is just a computational trick to average out those missing values, so the information in the observed values can be used.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      I appreciate your answer. I thought that (regardless of whether it is FIML or MI) missing values in the dataset are replaced by multiple sets of simulated values based on the observed data and a defined imputation model, or that FIML incorporates all available information from the observed data and the pattern of missing data directly into the estimation process. I could then use these values for further calculations, right?

      Comment


      • #4
        That depends (which is short for "in theory yes, in practice probably not")
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          But what could be an alternative approach then?

          Comment


          • #6
            That depends on what you exactly want to do and why.
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              We’d like to determine predictors for the outcome of a particular form of therapy using a regression model. Some of the potential predictor variables have missing data, that’s why i wanted to perform fiml or mi before the building the regression model.
              Last edited by Phillip Thies; 22 Mar 2024, 12:02.

              Comment


              • #8
                So, you can do that regression with sem and use fiml
                ---------------------------------
                Maarten L. Buis
                University of Konstanz
                Department of history and sociology
                box 40
                78457 Konstanz
                Germany
                http://www.maartenbuis.nl
                ---------------------------------

                Comment

                Working...
                X