{"id":14947,"date":"2022-10-09T18:47:38","date_gmt":"2022-10-09T13:17:38","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/"},"modified":"2022-10-09T18:47:38","modified_gmt":"2022-10-09T13:17:38","slug":"solved-object-not-found-in-for-loop","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/","title":{"rendered":"[Solved] Object not found in for loop"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-53858074\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"53858074\" data-parentid=\"53622687\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>The problem in the peace of code below after your definition of <code>crra<\/code> function:<\/p>\n<pre><code>eua = c(pa1*crra(a1,r)+pa2*crra(a2,r))\neub = c(pb1*crra(b1,r)+pb2*crra(b2,r))\n<\/code><\/pre>\n<p>Basically you are trying to use <code>r<\/code> variable before it&#8217;s defined moreover it is a duplicate of the code inside the <code>for<\/code>-loop. If you comment out these two lines everything goes OK. Please see the code below:<\/p>\n<pre><code>data=read.table(text = \" task  pa1 a1  pa2 a2  pb1  b1  pb2 b2 choice\n   1      0.34 24 0.66 59 0.42  47 0.58 64      0\n                2      0.88 79 0.12 82 0.20  57 0.80 94      0\n                3      0.74 62 0.26  0 0.44  23 0.56 31      1\n                4      0.05 56 0.95 72 0.95  68 0.05 95      1\n                5      0.25 84 0.75 43 0.43   7 0.57 97      0\n                6      0.28  7 0.72 74 0.71  55 0.29 63      0\n                7      0.09 56 0.91 19 0.76  13 0.24 90      0\n                8      0.63 41 0.37 18 0.98  56 0.02  8      0\n                9      0.88 72 0.12 29 0.39  67 0.61 63      1\n                10    0.61 37 0.39 50 0.60   6 0.40 45      1\n                11    0.08 54 0.92 31 0.15  44 0.85 29      1\n                12    0.92 63 0.08  5 0.63  43 0.37 53      1\n                13    0.78 32 0.22 99 0.32  39 0.68 56      0\n                14    0.16 66 0.84 23 0.79  15 0.21 29      1\n                15    0.12 52 0.88 73 0.98  92 0.02 19      0\n                16    0.29 88 0.71 78 0.29  53 0.71 91      1\n                17    0.31 39 0.69 51 0.84  16 0.16 91      1\n                18    0.17 70 0.83 65 0.35 100 0.65 50      0\n                19    0.91 80 0.09 19 0.64  37 0.36 65      1\n                20    0.09 83 0.91 67 0.48  77 0.52  6      1\n                21    0.44 14 0.56 72 0.21   9 0.79 31      1\n                22    0.68 41 0.32 65 0.85 100 0.15  2      0\n                23    0.38 40 0.62 55 0.14  26 0.86 96      0\n                24    0.62  1 0.38 83 0.41  37 0.59 24      1\n                25    0.49 15 0.51 50 0.94  64 0.06 14      0\n                26    0.10 40 0.90 32 0.10  77 0.90  2      1\n                27    0.20 40 0.80 32 0.20  77 0.80  2      1\n                28    0.30 40 0.70 32 0.30  77 0.70  2      1\n                29    0.40 40 0.60 32 0.40  77 0.60  2      1\n                30    0.50 40 0.50 32 0.50  77 0.50  2      0\n                31    0.60 40 0.40 32 0.60  77 0.40  2      0\n                32    0.70 40 0.30 32 0.70  77 0.30  2      0\n                33    0.80 40 0.20 32 0.80  77 0.20  2      0\n                34    0.90 40 0.10 32 0.90  77 0.10  2      0\n                35    1.00 40 0.00 32 1.00  77 0.00  2      0\", header = TRUE)\n\npa1 = c(data$pa1)\npa2 = c(data$pa2)\npb1 = c(data$pb1)\npb2 = c(data$pb2)\na1 = c(data$a1)\na2= c(data$a2)\nb1 = c(data$b1)\nb2 = c(data$b2)\nyy=c(data$choice)\n\ncrra=function(x,r){\n  u=x^(1-r)\/(1-r)\n  return(u)\n}\n\n# eua = c(pa1*crra(a1,r)+pa2*crra(a2,r))\n# eub = c(pb1*crra(b1,r)+pb2*crra(b2,r))\n\nLL_all = c()\n\nR&lt;-seq(0,1,0.01)\nfor (r in R){\n  eua = c(pa1*crra(a1,r)+pa2*crra(a2,r))\n  eub = c(pb1*crra(b1,r)+pb2*crra(b2,r))\n  probA = eua\/(eua+eub)\n  total = ifelse(yy==1, probA, 1-probA)\n  LL=log(prod(total))\n  LL_all=c(LL_all,LL)\n}\nhead(LL_all)\n<\/code><\/pre>\n<p>Output:<\/p>\n<pre><code>[1] -18.93759 -18.97863 -19.02000 -19.06170 -19.10374 -19.14611\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Object not found in for loop <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] The problem in the peace of code below after your definition of crra function: eua = c(pa1*crra(a1,r)+pa2*crra(a2,r)) eub = c(pb1*crra(b1,r)+pb2*crra(b2,r)) Basically you are trying to use r variable before it&#8217;s defined moreover it is a duplicate of the code inside the for-loop. If you comment out these two lines everything goes OK. Please see &#8230; <a title=\"[Solved] Object not found in for loop\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/\" aria-label=\"More on [Solved] Object not found in for loop\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[321],"class_list":["post-14947","post","type-post","status-publish","format-standard","hentry","category-solved","tag-r"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] Object not found in for loop - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Object not found in for loop - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] The problem in the peace of code below after your definition of crra function: eua = c(pa1*crra(a1,r)+pa2*crra(a2,r)) eub = c(pb1*crra(b1,r)+pb2*crra(b2,r)) Basically you are trying to use r variable before it&#8217;s defined moreover it is a duplicate of the code inside the for-loop. If you comment out these two lines everything goes OK. Please see ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-09T13:17:38+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-object-not-found-in-for-loop\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-object-not-found-in-for-loop\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Object not found in for loop\",\"datePublished\":\"2022-10-09T13:17:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-object-not-found-in-for-loop\\\/\"},\"wordCount\":67,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"r\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-object-not-found-in-for-loop\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-object-not-found-in-for-loop\\\/\",\"name\":\"[Solved] Object not found in for loop - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-10-09T13:17:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-object-not-found-in-for-loop\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-object-not-found-in-for-loop\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-object-not-found-in-for-loop\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Object not found in for loop\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Object not found in for loop - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Object not found in for loop - JassWeb","og_description":"[ad_1] The problem in the peace of code below after your definition of crra function: eua = c(pa1*crra(a1,r)+pa2*crra(a2,r)) eub = c(pb1*crra(b1,r)+pb2*crra(b2,r)) Basically you are trying to use r variable before it&#8217;s defined moreover it is a duplicate of the code inside the for-loop. If you comment out these two lines everything goes OK. Please see ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/","og_site_name":"JassWeb","article_published_time":"2022-10-09T13:17:38+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Object not found in for loop","datePublished":"2022-10-09T13:17:38+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/"},"wordCount":67,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["r"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/","url":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/","name":"[Solved] Object not found in for loop - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-09T13:17:38+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-object-not-found-in-for-loop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Object not found in for loop"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/14947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=14947"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/14947\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=14947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=14947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=14947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}