Iris example model error

Hi I’ve installed “greta” successfully and also configured “reticulate” to recognize the conda environment I created using the different instructions provided on the forum. Installing greta on Windows 10

I was testing the Iris example, shown on the “greta” website and I run into the following error:


# “iris” is a dataset that comes with every installation of Base R
data(iris)

# data – in this step we are identifying the Independent (x) and the Dependent (y) variables
# the as_data() function converts variable(s) into “greta” arrays that can be read in by functions within #“greta” library
x <- as_data(iris$Petal.Length)
y <- as_data(iris$Sepal.Length)

# setting the model variables and the priors for each model component
# int = intercept; coef = beta coefficient; sd = standard deviation (note “sd” declaration has a truncation # = c(0, Inf) – recognizing the fact that standard deviation & variance CANNOT be NEGATIVE
int <- normal(0, 1)
coef <- normal(0, 3)
sd <- student(3, 0, 1, truncation = c(0, Inf))

# operations to calculate the “predicted mean” of the Dependent variable (y = Sepal.Length)
mean <- int + coef*x

The last command mean <- int +coef*x errors out with the following message:

Error: Object cannot be coerced to <greta_array>
Objects of class <character> cannot be coerced to a <greta_array>

Can anyone help?

Sree

Hi there Sree, I was able to run your example without any issue. Did you accidentally replaced x with a character vector?

1 Like