Open jmacost5 opened 2 years ago
I have been trying to find a solution and not been able to find one all week
Hi Jestri,
Sorry for the delay. I wanted to wait until we got to this week. My responses are in blue below.
margins(log, at = list(Media = quantile(data$Media, 0.95)), variable = "Media") Error in check_at_names(names(data), at) : Unrecognized variable name in 'at': (1) Media
I ran that code that you provided. And it works. There might be an error before the line you posted. But this works if the model is properly specified and data is stored as data.
data2 <- with( data, data.frame( Adpotion = mean(Adoption),
Evangelics = c(0, 10 , 20 , 30 , 40 ,50, 60, 70, 80, 90, 100 ) ) )
data2$Evangelic_Prop <- predict(log, newdata = data2, type = "response")
data2$Evangelic_Prop plot(data2$GPA, data2$Evangelic_Prop, xlab = "Evangelic", ylab = "Adoption", main = "Evangelic Vs Adoption", lwd = 6) Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : variable lengths differ (found for 'Evangelics')
A few things.
1) the error is occurring because you have Adoption in the new dataframe you are using for your predicted values. Remove Adoption.
2) Evangelic should be 0 - 1 so c(0, 0.1, 0.2, ... 0.9, 1.0)
3) You have to include the mean values of the other variables to do this analysis. In the case of the binary variables like Democrats decided if you want it to be 0 or a 1.
4) You still have data2$GPA. Change that to Evangelics.
This should now work
margins(log, at = list(Evangelics = quantile(Evangelics, 20)), variable = "Evangelics") margins(log, at = list(Evangelics = quantile(Evangelics, 40)), variable = "Evanglics") Error in quantile.default(Evangelics, 20) : 'probs' outside [0,1] These are my code lines and the errors that I am getting.
The range of the Evangelics variable is between 0 and 1, so instead of 20 and 40 it should be 0.20 and 0.40, Also in the second line make sure you have the correct variable name. it should be " Evangelics"
Hope this Helps
On Mon, Apr 18, 2022 at 12:31 PM Jestrii Acosta @.***> wrote:
margins(log, at = list(Media = quantile(data$Media, 0.95)), variable = "Media") Error in check_at_names(names(data), at) : Unrecognized variable name in 'at': (1) Media
data2 <- with( data, data.frame( Adpotion = mean(Adoption),
Evangelics = c(0, 10 , 20 , 30 , 40 ,50, 60, 70, 80, 90, 100 ) ) )
data2$Evangelic_Prop <- predict(log, newdata = data2, type = "response")
data2$Evangelic_Prop plot(data2$GPA, data2$Evangelic_Prop, xlab = "Evangelic", ylab = "Adoption", main = "Evangelic Vs Adoption", lwd = 6) Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : variable lengths differ (found for 'Evangelics')
margins(log, at = list(Evangelics = quantile(Evangelics, 20)), variable = "Evangelics") margins(log, at = list(Evangelics = quantile(Evangelics, 40)), variable = "Evanglics") Error in quantile.default(Evangelics, 20) : 'probs' outside [0,1] These are my code lines and the errors that I am getting.
— Reply to this email directly, view it on GitHub https://github.com/Watts-College/cpp-525-spr-2022/issues/10, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHB4YDGRXRJDOQ7GCX2LVFW2CJANCNFSM5TWVBSNA . You are receiving this because you are subscribed to this thread.Message ID: @.***>
margins(log, at = list(Media = mean(Media)), variable = "Media") margins(log, at = list(Evangelics = mean(Evangelics)), variable = "Evangelics")
Error in check_at_names(names(data), at) :
Unrecognized variable name in 'at': (1)
Hi Jestrii,
Send me your markdown file. I was unable to replicate the error with code you provided.
On Thu, Apr 28, 2022, 3:29 PM Jestrii Acosta @.***> wrote:
margins(log, at = list(Media = mean(Media)), variable = "Media") margins(log, at = list(Evangelics = mean(Evangelics)), variable = "Evangelics")
Error in check_at_names(names(data), at) : Unrecognized variable name in 'at': (1) Media
— Reply to this email directly, view it on GitHub https://github.com/Watts-College/cpp-525-spr-2022/issues/10#issuecomment-1112712700, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHBY4I5P2GSI73QBMCX3VHMGODANCNFSM5TWVBSNA . You are receiving this because you commented.Message ID: @.***>
margins(log, at = list(Media = quantile(data$Media, 0.95)), variable = "Media") Error in check_at_names(names(data), at) : Unrecognized variable name in 'at': (1)Media
data2 <- with( data, data.frame( Adpotion = mean(Adoption),
Evangelics = c(0, 10 , 20 , 30 , 40 ,50, 60, 70, 80, 90, 100 ) ) )
data2$Evangelic_Prop <- predict(log, newdata = data2, type = "response")
data2$Evangelic_Prop plot(data2$GPA, data2$Evangelic_Prop, xlab = "Evangelic", ylab = "Adoption", main = "Evangelic Vs Adoption", lwd = 6) Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : variable lengths differ (found for 'Evangelics')
margins(log, at = list(Evangelics = quantile(Evangelics, 20)), variable = "Evangelics") margins(log, at = list(Evangelics = quantile(Evangelics, 40)), variable = "Evanglics") Error in quantile.default(Evangelics, 20) : 'probs' outside [0,1] These are my code lines and the errors that I am getting.