How do I write my code to include nlnp for a geometric distribution MLE? I do not think I get the right answer when I omit it from my code. Any help is greatly appreciated.
#> Rows: 100 Columns: 1
#> -- Column specification --------------------------------------------------------
#> Delimiter: ","
#> dbl (1): x
dput(data1[1:20, ])
#> structure(list(x = c(1.68107225364986, 0.519416796974838, 0.602025382220745,
#> 1.78941182495554, 0.703454908914864, 0.047538445852141, 0.330512334048969,
#> 3.90299055336003, 0.542592828501484, 0.812491587363183, 1.25761178322136,
#> 0.998352142050862, 1.90369714843433, 3.15919243443239, 1.14768674504012,
#> 0.373104335740209, 4.63665483494229, 0.612445597536862, 1.18418552726507,
#> 1.2424010457471)), row.names = c(NA, -20L), class = c("tbl_df",
#> "tbl", "data.frame"))
x = data1$x
p = 1/data$x
#> Error in data$x: object of type 'closure' is not subsettable
n = length(data1$x)
y = sum(data1$x)
geom.lik = function(p,x){
logl<-nlnp+sum(y)-n *log(1-p)
return(-logl)
}
geom.lik(data1)
#> Error in geom.lik(data1): object 'nlnp' not found
geom.lik = function(p,x){
logl<-sum(p)-n *log(1-p)
return(-logl)
}
geom.lik(data1)
#> Warning in FUN(X[[i]], ...): NaNs produced
#> x
#> 1 NaN
#> 2 -238.8002
#> 3 -257.6614
#> 4 NaN
#> 5 -287.0803
#> 6 -170.3953
#> 7 -205.6490
#> 8 NaN
#> 9 -243.7429
#> 10 -332.9179
#> 11 NaN
#> 12 -806.3526
#> 13 NaN
#> 14 NaN
#> 15 NaN
#> 16 -212.2223
#> 17 NaN
#> 18 -260.3146