Announcement

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

  • Creating a PP plot from a linear regression model with sampling weights

    I have a dataset that has sampling weights. I have fitted a multivariable linear regression model and i would like to check if the residuals are normally distributed. the pnorm command in stata doesn't take either probability or frequency weights. How can I create a custom pp plot like the one produced by the 'pnorm' command that will accommodate either probability or frequent weights. How can I get the observed and expected probabilities so that I can try and plot them using the scatter command. I converted my sampling weights to frequency weights because some commands like "histogram" only take frequency weights. My weighted histogram looks pretty normal but the pp plot shows deviation which I suspect is because of not applying weights. Below is my code and sample dataset

    regress lgtcorscore corall rhino influenzall prevcase [pw=pweighting] if enrolled==1
    predict res, residuals // Predict the residuals
    histogram res [fw=fweighting3], normal title("A. Distribution of residuals") graphregion(color(white)) bgcolor(white) // Overall - Normality of errors (residuals)
    graph save Graph "C:\norm1.gph" , replace
    pnorm res, title("B. P-P plot") ytitle(Observed Probabilities) xtitle(Expected Probabilities) graphregion(color(white)) bgcolor(white)
    graph save Graph "C:\norm2.gph" , replace
    graph combine C:\norm1.gph C:\norm2.gph , ysize(1) xsize(2) iscale(*.8) row(1)
    graph save Graph "C:\normAll.gph", replace

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(lgtcorscore corall rhino influenzall) byte prevcase float(pweighting    fweighting3)
    2.995732 0 0 0 1 1.263 10
    2.456736 0 0 0 1 1.263 10
    4.0386543 0 0 0 1 1.263 10
    .5409555 0 0 0 1 1.263 10
    -.5223864 0 0 0 1  7.92 63
    .4643055 0 0 0 1 1.263 10
    1.7917595 0 0 0 1 1.263 10
    4.3307376 0 0 0 1 1.263 10
    3.6243405 0 0 0 1 1.263 10
    -2.154665 0 0 0 1  7.92 63
    -2.6936615 0 0 0 1  7.92 63
    1.0928487 0 0 0 0 1.263 10
    -2.904165 0 0 0 0  7.92 63
    -.9162908 0 0 0 0  7.92 63
    1.3638216 0 0 0 0 1.263 10
    5.438088 1 0 0 0 1.263 10
    .7323679 0 1 0 0 1.263 10
    3.811095 0 1 0 0 1.263 10
    -2.995732 0 0 0 0  7.92 63
    -.1997962 0 1 0 0  7.92 63
    -.11267325 0 1 0 0  7.92 63
    2.995732 0 0 0 0 1.263 10
    -2.904165 0 1 0 0  7.92 63
    4.3307376 0 1 0 0 1.263 10
    -1.1667502 0 1 0 0  7.92 63
    .26157087 1 0 0 0  7.92 63
    -1.261131 1 0 0 0  7.92 63
    1.9409716 1 0 0 0 1.263 10
    -1.2114916 0 0 0 0  7.92 63
    1.9661127 0 0 1 0 1.263 10
    2.904165 0 1 0 0 1.263 10
    -1.2697606 1 0 0 0  7.92 63
    1.1394342 0 1 0 0 1.263 10
    1.2361418 0 0 0 0 1.263 10
    2.904165 0 1 0 0 1.263 10
    2.995732 1 0 0 0 1.263 10
    1.475242 0 1 0 0 1.263 10
    -2.74084 0 1 0 0  7.92 63
    2.995732 0 1 0 0 1.263 10
    3.465735 1 0 0 0 1.263 10
    -.9591107 0 1 0 0  7.92 63
    -2.47092 0 1 0 0  7.92 63
    3.3277304 0 1 0 0 1.263 10
    2.3561258 0 1 0 0 1.263 10
    .9376007 1 0 0 0 1.263 10
    -1.446919 1 0 0 0  7.92 63
    2.3561258 0 1 0 0 1.263 10
    2.2637453 0 0 1 0 1.263 10
    -1.069957 0 1 0 0  7.92 63
    1.981001 0 1 0 0 1.263 10
    2.819545 1 0 0 0 1.263 10
    .991367 0 0 0 0 1.263 10
    -1.940972 0 0 0 0  7.92 63
    4.3307376 0 0 0 0 1.263 10
    -3.32773 0 0 0 0  7.92 63
    -3.1593616 0 0 0 0  7.92 63
    2.819545 0 0 0 0 1.263 10
    1.5040773 0 0 0 0 1.263 10
    -1.6894807 0 0 0 0  7.92 63
    -1.7227665 0 0 0 0  7.92 63
    .4685658 0 0 0 0 1.263 10
    -1.7917595 0 0 0 0  7.92 63
    2.3561258 0 0 0 0 1.263 10
    1.827569 0 0 0 0 1.263 10
    -2.1453996 0 0 0 0  7.92 63
    1.286474 0 0 0 0 1.263 10
    -2.667228 0 0 0 0  7.92 63
    -2.819546 0 0 0 0  7.92 63
    -2.9285235 0 0 0 0  7.92 63
    -1.3121864 0 0 0 0  7.92 63
    2.751535 0 0 0 0 1.263 10
    2.5980496 0 0 0 0 1.263 10
    3.160035 0 0 0 0 1.263 10
    -1.563394 0 0 0 0  7.92 63
    -1.375121 0 0 0 0  7.92 63
    -2.3561258 0 0 0 0  7.92 63
    -2.10515 0 0 0 0  7.92 63
    -3.465736 0 0 0 0  7.92 63
    3.095578 0 0 0 0 1.263 10
    -2.412147 0 0 0 0  7.92 63
    .7126917 0 0 0 0 1.263 10
    2.3025846 0 0 0 0 1.263 10
    -2.412147 0 0 0 0  7.92 63
    -1.625104 0 0 0 0  7.92 63
    -2.532763 0 0 0 0  7.92 63
    -2.819546 0 0 0 0  7.92 63
    -.3053816 0 0 0 0  7.92 63
    -2.397895 0 0 0 0  7.92 63
    4.7405767 0 0 0 0 1.263 10
    -.3766861 0 0 0 0  7.92 63
    -2.412147 0 0 0 0  7.92 63
    -2.758061 0 0 0 0  7.92 63
    -2.3025851 0 0 0 0  7.92 63
    -1.430746 0 0 0 0  7.92 63
    3.811095 0 0 0 0 1.263 10
    -2.434645 0 0 0 0  7.92 63
    -1.261131 0 0 0 0  7.92 63
    -.09962995 0 0 0 0  7.92 63
    1.267235 0 0 0 0 1.263 10
    -1.3121864 0 0 0 0  7.92 63
    end
    label values influenzall pstatus
    label values rhino pstatus
    label values corall pstatus
    label def pstatus 0 "negative", modify
    label def pstatus 1 "positive", modify
    label values prevcase casetype
    label def casetype 0 "No", modify
    label def casetype 1 "Yes", modify
    Click image for larger version

Name:	normAll.tif
Views:	2
Size:	16.8 KB
ID:	1613693
    Thanks
    Humphrey
Working...
X