{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/141","repository_url":"https://api.github.com/repos/JuliaStats/GLM.jl","labels_url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/141/labels{/name}","comments_url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/141/comments","events_url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/141/events","html_url":"https://github.com/JuliaStats/GLM.jl/issues/141","id":157298675,"number":141,"title":"\"predict\" method does not keep NA values","user":{"login":"JessicaYK","id":8303445,"avatar_url":"https://avatars.githubusercontent.com/u/8303445?v=3","gravatar_id":"","url":"https://api.github.com/users/JessicaYK","html_url":"https://github.com/JessicaYK","followers_url":"https://api.github.com/users/JessicaYK/followers","following_url":"https://api.github.com/users/JessicaYK/following{/other_user}","gists_url":"https://api.github.com/users/JessicaYK/gists{/gist_id}","starred_url":"https://api.github.com/users/JessicaYK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JessicaYK/subscriptions","organizations_url":"https://api.github.com/users/JessicaYK/orgs","repos_url":"https://api.github.com/users/JessicaYK/repos","events_url":"https://api.github.com/users/JessicaYK/events{/privacy}","received_events_url":"https://api.github.com/users/JessicaYK/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-05-27T22:05:28Z","updated_at":"2016-05-30T18:36:03Z","closed_at":null,"body":"Hi all,\r\n\r\nThe data that I use contains variables with some \"NA\" values. I need to run regressions on them, and I want my prediction to show the positions of variables that have predictions as \"NA\". However, the \"predict\" method does not do this. It only shows the vector consisting of non-NA predictions. Is there a way I can show NA predictions? Any help will be appreciated!"},"comment":{"url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/comments/222538987","html_url":"https://github.com/JuliaStats/GLM.jl/issues/141#issuecomment-222538987","issue_url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/141","id":222538987,"user":{"login":"andreasnoack","id":505001,"avatar_url":"https://avatars.githubusercontent.com/u/505001?v=3","gravatar_id":"","url":"https://api.github.com/users/andreasnoack","html_url":"https://github.com/andreasnoack","followers_url":"https://api.github.com/users/andreasnoack/followers","following_url":"https://api.github.com/users/andreasnoack/following{/other_user}","gists_url":"https://api.github.com/users/andreasnoack/gists{/gist_id}","starred_url":"https://api.github.com/users/andreasnoack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreasnoack/subscriptions","organizations_url":"https://api.github.com/users/andreasnoack/orgs","repos_url":"https://api.github.com/users/andreasnoack/repos","events_url":"https://api.github.com/users/andreasnoack/events{/privacy}","received_events_url":"https://api.github.com/users/andreasnoack/received_events","type":"User","site_admin":false},"created_at":"2016-05-30T18:36:03Z","updated_at":"2016-05-30T18:36:03Z","body":"You are welcome and no problem that you are not sure about the format in here. We have all been new to it at some point. For a question like this one, it is actually more appropriate to post on https://groups.google.com/forum/#!forum/julia-stats whereas this place is mainly for bugs or design discussions related to `GLM.jl` more than questions about use. However, since we have started the conversation here, let's just finish it here.\r\n\r\nIn `lm` the `predict` function is fairly simple and is just computing `X*β̂`, i.e.\r\n```jl\r\njulia> prVals = [ones(10) df[:x]]\r\n10x2 Array{Float64,2}:\r\n 1.0  -0.208228 \r\n 1.0  -0.0711758\r\n 1.0   0.698314 \r\n 1.0  -0.0662767\r\n 1.0   0.834966 \r\n 1.0  -1.22193  \r\n 1.0   1.35638  \r\n 1.0   1.0735   \r\n 1.0   1.51421  \r\n 1.0  -0.45499  \r\n\r\njulia> predict(ft, prVals)\r\n10-element Array{Float64,1}:\r\n -0.0143628\r\n -0.0953182\r\n -0.549847 \r\n -0.0982121\r\n -0.630566 \r\n  0.584419 \r\n -0.93856  \r\n -0.771464 \r\n -1.03179  \r\n  0.131397 \r\n\r\njulia> prVals*coef(ft)\r\n10-element Array{Float64,1}:\r\n -0.0143628\r\n -0.0953182\r\n -0.549847 \r\n -0.0982121\r\n -0.630566 \r\n  0.584419 \r\n -0.93856  \r\n -0.771464 \r\n -1.03179  \r\n  0.131397 \r\n```\r\nso the only way the the `NA` in `y` could affect the predicted values would be through `coef(ft)`. When `NA` are removed, as we do now, then `coef(ft)` doesn't have any `NA`s. If `NA` observations were not removed from the model then all of `coef(ft)` would be `NA`s and all the predicted values would be `NA`s as well.\r\n\r\nAn `NA` in the values used for prediction would cause an `NA` in the predicted values, i.e.\r\n```jl\r\njulia> ft = glm(y~x, df, Normal(), IdentityLink())\r\nDataFrames.DataFrameRegressionModel{GLM.GeneralizedLinearModel{GLM.GlmResp{Array{Float64,1},Distributions.Normal{Float64},GLM.IdentityLink},GLM.DensePredChol{Float64,Base.LinAlg.Cholesky{Float64,Array{Float64,2}}}},Float64}\r\n\r\nFormula: y ~ 1 + x\r\n\r\nCoefficients:\r\n              Estimate Std.Error   z value Pr(>|z|)\r\n(Intercept)  -0.137361  0.394318 -0.348351   0.7276\r\nx            -0.590689  0.413625  -1.42808   0.1533\r\n\r\n\r\njulia> prVal = DataArray([ones(2) randn(2)]);\r\n\r\njulia> prVal[1,2] = NA;\r\n\r\njulia> predict(ft, prVal)\r\n2-element Array{Union{DataArrays.NAtype,Float64},1}:\r\n   NA    \r\n -0.17572\r\n```\r\nNotice that I used `glm` here. For some reason this doesn't work for `lm` which is a bug."}}
{"actor":{"display_login":"andreasnoack"}}