Lucia Lucia
Lucia Lucia

Reputation: 1

Error in model.frame.default(formula = meansharelocal ~ meanshareglobal) : invalid type (list) for variable 'meansharelocal'

Trying to conduct a t.test of two sets of data. The code I am writing for this is:

t.test(meansharelocal ~ meanshareglobal)

Each data set has 4 pieces of data, in a column like this in a table:

mean(Share_1) mean(Share_2) mean(Share_3) mean(Share_4)
1.396552 1.034483 1.189655 1.396552

When I run t.test(meansharelocal ~ meanshareglobal) I receive this error.

Error in model.frame.default(formula = meansharelocal ~ meanshareglobal) : invalid type (list) for variable 'meansharelocal'

Can someone tell me what is going wrong? I am trying to see if the two piece of data are statistically different enough.

This is what I got from Reprex, again, I am new to this so don't know if I accessed this wrong as it is coming up with more errors? But the only error I actually have is the last line!

globalshare <- global %>% mutate_at(c("Share_1", "Share_2", "Share_3", "Share_4"), funs(recode(.,"Extremely likely" = 4, "Somewhat likely" = 3, "Neither likely nor unlikely" = 2, "Somewhat unlikely" = 1, "Extremely unlikely" = 0)))
#> Error in tbl_vars_dispatch(x): object 'global' not found
  
localshare <- local %>% mutate_at(c("Share_1", "Share_2", "Share_3", "Share_4"), funs(recode(.,"Extremely likely" = 4, "Somewhat likely" = 3, "Neither likely nor unlikely" = 2, "Somewhat unlikely" = 1, "Extremely unlikely" = 0)))
#> Error in UseMethod("tbl_vars"): no applicable method for 'tbl_vars' applied to an object of class "function"

boxplot(globalshare$Share_1, globalshare$Share_2, globalshare$Share_3, globalshare$Share_4, 
        localshare$Share_1, localshare$Share_2, localshare$Share_3, localshare$Share_4, names=c
        ("Global1", "Global2", "Global3", "Global4", "Local1", "Local2","Local3", "Local4"))
#> Error in boxplot(globalshare$Share_1, globalshare$Share_2, globalshare$Share_3, : object 'globalshare' not found

meanshareglobal <- globalshare %>% summarise(mean(Share_1), mean(Share_2), mean(Share_3), mean(Share_4))
#> Error in summarise(., mean(Share_1), mean(Share_2), mean(Share_3), mean(Share_4)): object 'globalshare' not found

meansharelocal <- localshare %>% summarise(mean(Share_1), mean(Share_2), mean(Share_3), mean(Share_4))
#> Error in summarise(., mean(Share_1), mean(Share_2), mean(Share_3), mean(Share_4)): object 'localshare' not found

t.test(meanshareglobal ~ meansharelocal)
#> Error in eval(predvars, data, env): object 'meanshareglobal' not found

Upvotes: 0

Views: 195

Answers (1)

Lamma
Lamma

Reputation: 1547

If I am understanding from your comments correctly you have wide dataframes of 1 row. Assuming they are the same dimensions you can just transpose and bind them then do your t test.

t.globalshare  = t(globalshare)
t.localshare  = t(localshare)

combined = cbind(t.globalshare, t.localshare)

t.test(combined, t.globalshare ~ t.localshare)

Upvotes: 0

Related Questions